Virtual Box中 CentOS双网卡设置:
在Virtual Box中安装CentOS x86-64 6.4(final),配置了双网卡,eth0 为桥接模式 , eth1为内网模式
配置对应文件:[root@compute1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:6A:0A:50
TYPE=Ethernet
UUID=daed07c6-42df-4d1a-a6dc-15be73161da3
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.137.182
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
DNS1=192.168.137.1
DEFROUTE=yes
HWADDR=08:00:27:6A:0A:50
TYPE=Ethernet
UUID=daed07c6-42df-4d1a-a6dc-15be73161da3
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.137.182
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
DNS1=192.168.137.1
DEFROUTE=yes
配置对应文件:[root@compute1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
HWADDR=08:00:27:EF:C0:28
TYPE=Ethernet
UUID=23f6bf7a-6eaf-48e9-8d73-1df8e23d843e
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.182
NETMASK=255.255.255.0
DEFROUTE=yes
HWADDR=08:00:27:EF:C0:28
TYPE=Ethernet
UUID=23f6bf7a-6eaf-48e9-8d73-1df8e23d843e
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.182
NETMASK=255.255.255.0
DEFROUTE=yes
在eth1中不能设置GATEWAY,因为linux GATEWAY的加载是先加载eth0 在加载eth1 这样会覆盖eht0中的GATEWAY。
配置文件:[root@compute1 ~]# vi /etc/resolv.conf
nameserver 192.168.137.1
修改hostname 为: compute1
配置文件:[root@compute1 ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=compute1
HOSTNAME=compute1
配置文件:[root@compute1 ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.137.1 compute1
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.137.1 compute1
如果不小心在eth1中添加了GATEWAY,则除了编辑文件ifcfg-eth1去掉GATWAY之外,还要添加默认路由:
[root@controller1 etc]# route add default gw 192.168.137.1
此时路由信息由:
[root@controller1 etc]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.137.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.137.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
变成了:
[root@controller1 etc]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.137.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 192.168.137.1 0.0.0.0 UG 0 0 0 eth0
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.137.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 192.168.137.1 0.0.0.0 UG 0 0 0 eth0