一、前言
需求:由于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
可以看到,两块网卡配置成功。