環境簡述:
伺服器A具備雙網卡,安裝作業系統RHEL6.3
----------------------------------------------------------
網卡顯示名稱 IP地址 網關
----------------------------------------------------------
eth0 192.168.153.4 192.168.153.1
eth1 192.168.152.4 192.168.152.1
-----------------------------------------------------------
網卡設定檔:
12345678910111213141516[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=192.168.153.4NETMASK=255.255.255.0GATEWAY=192.168.153.1[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1DEVICE=eth1ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=192.168.152.4NETMASK=255.255.255.0GATEWAY=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參數全部刪除,即
1234567891011121314[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=192.168.153.4NETMASK=255.255.255.0[root@clovem ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1DEVICE=eth1ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=192.168.152.4NETMASK=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. 添加靜態路由表
12345678[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. 此時再次通過正式發行前小眾測試機訪問均可
123456789[root@storage252 ~]# ifconfig eth0eth0 Link encap:Ethernet HWaddr 00:50:56:82:56:55inet addr:192.168.150.252 Bcast:192.168.150.255 Mask:255.255.255.0inet6 addr: fe80::250:56ff:fe82:5655/64Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:25910143 errors:0 dropped:0 overruns:0 frame:0TX packets:19888495 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:26258149440 (24.4 GiB) TX bytes:16323278977 (15.2 GiB)1234567891011121314[root@storage252 ~]# ping -W1 -c2 192.168.152.4PING 192.168.152.4 (192.168.152.4) 56(84) bytes of data.64 bytes from 192.168.152.4: icmp_seq=1 ttl=63time=0.324 ms64 bytes from 192.168.152.4: icmp_seq=2 ttl=63time=0.349 ms--- 192.168.152.4pingstatistics ---2 packets transmitted, 2 received, 0% packet loss,time1000msrtt min/avg/max/mdev= 0.324/0.336/0.349/0.022 ms[root@storage252 ~]# ping -W1 -c2 192.168.153.4PING 192.168.153.4 (192.168.153.4) 56(84) bytes of data.64 bytes from 192.168.153.4: icmp_seq=1 ttl=63time=0.342 ms64 bytes from 192.168.153.4: icmp_seq=2 ttl=63time=0.271 ms--- 192.168.153.4pingstatistics ---2 packets transmitted, 2 received, 0% packet loss,time999msrtt min/avg/max/mdev= 0.271/0.306/0.342/0.039 ms
最後還需要添加一條預設閘道,才能讓該系統訪問其他網段主機
[root@clovem ~]#route add default gw 192.168.153.1
可以根據需要將靜態路由命令添加至相關設定檔,重啟之後仍然生效。