剛起的虛擬機無法相互ping通,屬於兩個網段,中間通過路由相連接
比如:10.11.12.202 ping 10.11.13.102
首先,ssh到10.11.12.202中,
查看路由表項,發現沒有默認路由:
Destination Gateway Genmask Flags Metric Ref Use Iface
10.11.12.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
添加默認路由:
sudo route add default gw 10.11.12.200 dev eth0
設置默認網關gw 10.11.12.200,即連到別的子網的需要通過該網關,這個網關也是路由連接到本子網的網關地址,dev eth0強制設置爲eth0口
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.11.12.200 0.0.0.0 UG 0 0 0 eth0
10.11.12.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
這時候還不能ping通,因爲10.11.13.102的網關沒設置
ssh到10.11.13.102中,route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.11.13.1 0.0.0.0 UG 0 0 0 eth0
10.11.13.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
發現默認網關爲10.11.13.1,不是正確的網關,我本地該網段連接外網的網關爲10.11.13.100
添加默認網關 並刪除原網關
sudo route add default gw 10.11.13.100 dev eth0
sudo route del default gw 10.11.13.1
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.11.13.100 0.0.0.0 UG 0 0 0 eth0
10.11.13.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
OK 可以ping通了:
[fedora@inst2-8 ~]$ ping 10.11.12.202
PING 10.11.12.202 (10.11.12.202) 56(84) bytes of data.
64 bytes from 10.11.12.202: icmp_seq=1 ttl=63 time=0.980 ms
64 bytes from 10.11.12.202: icmp_seq=2 ttl=63 time=0.951 ms
64 bytes from 10.11.12.202: icmp_seq=3 ttl=63 time=0.672 ms