Linux 不同网段两台主机相互ping通 您所在的位置:网站首页 跨网段ping不通 Linux 不同网段两台主机相互ping通

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

2024-07-12 04:06| 来源: 网络整理| 查看: 265

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

比如:10.11.12.202 ping 10.11.13.102

首先,ssh到10.11.12.202中,

代码语言:javascript复制route -n

查看路由表项,发现没有默认路由:

代码语言:javascript复制Destination Gateway Genmask Flags Metric Ref Use Iface 10.11.12.0 0.0.0.0 255.255.255.0 U 0 0 0 eth01

添加默认路由:

代码语言:javascript复制sudo route add default gw 10.11.12.200 dev eth0

设置默认网关gw 10.11.12.200,即连到别的子网的需要通过该网关,这个网关也是路由连接到本子网的网关地址,dev eth0强制设置为eth0口

代码语言:javascript复制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 eth012

这时候还不能ping通,因为10.11.13.102的网关没设置

ssh到10.11.13.102中,

代码语言:javascript复制route -n代码语言:javascript复制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 eth012

发现默认网关为10.11.13.1,不是正确的网关,我本地该网段连接外网的网关为10.11.13.100

添加默认网关 并删除原网关

代码语言:javascript复制sudo route add default gw 10.11.13.100 dev eth0代码语言:javascript复制sudo route del default gw 10.11.13.1代码语言:javascript复制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 eth012

OK 可以ping通了:

代码语言:javascript复制[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


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有