Linux 不同网段两台主机相互ping通

刚起的虚拟机无法相互ping通,属于两个网段,中间通过路由相连接

比如:10.11.12.202 ping 10.11.13.102

首先,ssh到10.11.12.202中,
route -n
查看路由表项,发现没有默认路由:
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



  • 4
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值