一、前言
需求:由於LVS演練需要,需要配置兩張linux OS網卡,而且是不同網段。
准備:
物理機:單網卡
VMware:centos 6.8
二、配置
第一步:新建虛擬機VMware,centos 6.8,默認有一張網卡eth0。配置的NAT模式,如圖:
我這里NAT模式設置的網段是192.168.229.0/24網段。
第二步:添加一塊網卡。模式為橋接,和物理機網段一樣是192.168.1.0/24 網段。如圖。
到這里,添加完了。
第三步、配置
Centos開機后,只有一張網卡eth0的信息,拷貝一張eth0的配置文件:
[root@ShiYanLou network-scripts]#cd /etc/sysconfig/network-scripts
[root@ShiYanLou network-scripts]#cp ifcfg-eth0 ifcfg-eth1
修改配置文件ifcfg-eth1:
[root@ShiYanLou network-scripts]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules # program, run by the persistent-net-generator.rules rules file. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. # PCI device 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:df:72:dd", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" # PCI device 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:df:72:e7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
可以看到,eth1的mac地址是:00:0c:29:df:72:e7,修改/etc/sysconfig/network-scripts/ifcfg-eth1 成如下:
[root@ShiYanLou network-scripts]# cat ifcfg-eth1
DEVICE=eth1 HWADDR=00:0C:29:DF:72:E7 TYPE=Ethernet UUID=a5370cfe-c84a-4b11-97ee-a96f34db9bba ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.1.111 NETMASK=255.255.255.0 GATEWAY=192.168.1.1
重啟網卡:service Network restart。
[root@ShiYanLou network-scripts]# service network restart
正在關閉接口 eth0: [確定]
正在關閉接口 eth1: [確定]
關閉環回接口: [確定]
彈出環回接口: [確定]
彈出界面 eth0:
正在決定 eth0 的 IP 信息...完成。
[確定]
彈出界面 eth1: Determining if ip address 192.168.1.111 is already in use for device eth1... [確定] [root@ShiYanLou network-scripts]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:df:72:dd brd ff:ff:ff:ff:ff:ff inet 192.168.229.133/24 brd 192.168.229.255 scope global eth0 inet6 fe80::20c:29ff:fedf:72dd/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:df:72:e7 brd ff:ff:ff:ff:ff:ff inet 192.168.1.111/24 brd 192.168.1.255 scope global eth1 inet6 fe80::20c:29ff:fedf:72e7/64 scope link valid_lft forever preferred_lft forever
可以看到,兩塊網卡配置成功。