环境简述:
服务器A具备双网卡,安装操作系统RHEL6.3
----------------------------------------------------------
网卡显示名称 IP地址 网关
----------------------------------------------------------
eth0 192.168.153.4 192.168.153.1
eth1 192.168.152.4 192.168.152.1
-----------------------------------------------------------
网卡配置文件:
[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.168.153.4
NETMASK=255.255.255.0
GATEWAY=192.168.153.1
[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.168.152.4
NETMASK=255.255.255.0
GATEWAY=192.168.152.1
重启网络服务
[root@clovem ~]# service network restart
查看其路由信息:
[root@clovem ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.153.0 * 255.255.255.0 U 0 0 0 eth0
192.168.152.0 * 255.255.255.0 U 0 0 0 eth1
link-local * 255.255.0.0 U 1015 0 0 eth0
link-local * 255.255.0.0 U 1016 0 0 eth1
default 192.168.152.1 255.255.255.0 UG 1017 0 0 eth1
可以发现双网卡的默认网关为192.168.152.1
从其他网段192.168.151.0/24的某台测试机:192.168.150.252
访问192.168.153.4以及192.168.152.4 ,只能通过192.168.152.4进行网络连接,而192.168.153.4却不可以,从上面的路由表中可以看出两个网卡配置文件中的网关参数只有192.168.152.1生效,并被设置为默认网关。
解决方法:
1.将两个网卡配置文件中的GATEWAY参数全部删除,即
[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.168.153.4
NETMASK=255.255.255.0
[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=static
TYPE=Ethernet
IPADDR=192.168.152.4
NETMASK=255.255.255.0
2. 重启网络
[root@clovem ~]# service network restart
3.查看路由表
[root@clovem ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.153.0 * 255.255.255.0 U 0 0 0 eth0
192.168.152.0 * 255.255.255.0 U 0 0 0 eth1
link-local * 255.255.0.0 U 1015 0 0 eth0
link-local * 255.255.0.0 U 1016 0 0 eth1
发现默认网关没有被设置
4. 添加静态路由表
[root@clovem ~]# echo "153 net_153" >> /etc/iproute2/rt_tables
[root@clovem ~]# echo "152 net_152" >> /etc/iproute2/rt_tables
[root@clovem ~]# ip route flush table net_153
[root@clovem ~]# ip route add default via 192.168.153.1 dev eth0 src 192.168.153.4 table net_153
[root@clovem ~]# ip rule add from 192.168.153.4 table net_153 //可忽略
[root@clovem ~]# ip route flush table net_152
[root@clovem ~]# ip route add default via 192.168.152.1 dev eth0 src 192.168.153.4 table net_152
[root@clovem ~]# ip rule add from 192.168.152.4 table net_152//可忽略
5. 此时再次通过外部测试机访问均可
[root@storage252 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:50:56:82:56:55
inet addr:192.168.150.252 Bcast:192.168.150.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fe82:5655/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25910143 errors:0 dropped:0 overruns:0 frame:0
TX packets:19888495 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:26258149440 (24.4 GiB) TX bytes:16323278977 (15.2 GiB)