问题：﻿如果两个IP一样，但是网段不一样，能ping通吗？ 比如我在同一个路由器上，左边接口设置192.168.1.1 子网掩码255.255.255.0 ，右边接口192.168.1.1 子网掩码255.25…
话题：﻿科技、路由器、Ping、计算机网络、IP地址
回答：﻿2019年04月05日修改：你们啊，想象力太差了。来重新审一下题。题主说的是在同一个路由器的两个接口上配置相同的IP但子网掩码不同。在这种情况下，其他路由器能不能ping通这个路由器。今天放假，我花时间部署了一下环境。给你们看看实际情况里到底可以还是不可以。简单画了个拓扑图：网络拓扑拓扑图里每条连线都是独立网桥连接。A和C、D之间、B和D之间均不可直连（二层不可达）。图中，B和C均是两个接口配置相同IP，只是子网不同。符合问题的条件。我们以B作为实验对象。各机器配置机器A机器B机器C机器D这里机器B和机器C均有两张网卡。各自IP相同且路由范围重叠。看实际分别从A、B、C、Dping机器B的结果：全都是通的。而且可以看到，D机器上ping的应答中ttl减小了1的，说明报文确实是被路由过的。说明IP路由是正常的。还有什么要反对的。评论区提出来。原答案：好多人都在说不能这么配置啊。那我来反驳一下你们所有人。来看看这台Linux。杠精们不要来杠Linux不是路由器，Linux可是完全能做路由器的。（见隔壁openwrt）1:lo:mtu65536qdiscnoqueuestateUNKNOWNgroupdefaultqlen1000
link/loopback00:00:00:00:00:00brd00:00:00:00:00:00
inet127.0.0.1/8scopehostlo
valid_lftforeverpreferred_lftforever
inet192.168.2.5/16scopegloballo
valid_lftforeverpreferred_lftforever
inet6::1/128scopehost
valid_lftforeverpreferred_lftforever
2:br-inet:mtu1500qdiscnoqueuestateUPgroupdefaultqlen1000
link/etherae:86:b4:ec:b7:cbbrdff:ff:ff:ff:ff:ff
inet192.168.2.5/24brd192.168.2.255scopeglobaldynamicbr-inet
valid_lft42843secpreferred_lft42843sec
inet6fdc9:760b:4d02::1f3/128scopeglobalnoprefixroute
valid_lftforeverpreferred_lftforever
inet6fdc9:760b:4d02:0:ac86:b4ff:feec:b7cb/64scopeglobalmngtmpaddrnoprefixroute
valid_lftforeverpreferred_lftforever
inet6fe80::ac86:b4ff:feec:b7cb/64scopelink
valid_lftforeverpreferred_lftforever一个192.168.2.5配置到两个接口上。再看下路由表，如下：defaultvia192.168.2.1devbr-inetprotodhcpsrc192.168.2.5metric1024
192.168.2.0/24devbr-inetprotokernelscopelinksrc192.168.2.5
192.168.2.1devbr-inetprotodhcpscopelinksrc192.168.2.5metric1024
broadcast127.0.0.0devlotablelocalprotokernelscopelinksrc127.0.0.1
local127.0.0.0/8devlotablelocalprotokernelscopehostsrc127.0.0.1
local127.0.0.1devlotablelocalprotokernelscopehostsrc127.0.0.1
broadcast127.255.255.255devlotablelocalprotokernelscopelinksrc127.0.0.1
broadcast192.168.0.0devlotablelocalprotokernelscopelinksrc192.168.2.5
local192.168.0.0/16devlotablelocalprotokernelscopehostsrc192.168.2.5
broadcast192.168.2.0devbr-inettablelocalprotokernelscopelinksrc192.168.2.5
local192.168.2.5devbr-inettablelocalprotokernelscopehostsrc192.168.2.5
local192.168.2.5devlotablelocalprotokernelscopehostsrc192.168.2.5
broadcast192.168.2.255devbr-inettablelocalprotokernelscopelinksrc192.168.2.5
broadcast192.168.255.255devlotablelocalprotokernelscopelinksrc192.168.2.5可以看到br-inet和lo上都有192.168.2.5这个地址。意味着从这两个接口进来的icmpechorequest都是合法的报文，不会被丢弃。Linux完全能做到icmpechorequest从哪个接口进站，response就从哪个接口出站。看从**另一台机器**的ping结果[xuan@rpi~]$ping192.168.2.5
PING192.168.2.5(192.168.2.5)56(84)bytesofdata.
64bytesfrom192.168.2.5:icmp_seq=1ttl=64time=0.400ms
64bytesfrom192.168.2.5:icmp_seq=2ttl=64time=0.360ms
64bytesfrom192.168.2.5:icmp_seq=3ttl=64time=0.301ms
^C
---192.168.2.5pingstatistics---
3packetstransmitted,3received,0%packetloss,time96ms
rttmin/avg/max/mdev=0.301/0.353/0.400/0.046ms从本机lo接口ping$sudoping-Ilo192.168.2.5
PING192.168.2.5(192.168.2.5)from192.168.2.5lo:56(84)bytesofdata.
64bytesfrom192.168.2.5:icmp_seq=1ttl=64time=0.053ms
64bytesfrom192.168.2.5:icmp_seq=2ttl=64time=0.093ms
^C
---192.168.2.5pingstatistics---
2packetstransmitted,2received,0%packetloss,time23ms
rttmin/avg/max/mdev=0.053/0.073/0.093/0.020ms所以说ping完全没压力。被评论的@AndOne喷了。你喷也想想原理啊。只要二层实现以太网协议，Linux内核路由层面根本不会区分它到底是个网桥还是实际以太网口。来给你看看这个，这是在一个真实的OpenWRT路由器里设置的。2:eth0:mtu1500qdiscfq_codelstateUPgroupdefaultqlen1000
link/ether46:94:fc:73:27:64brdff:ff:ff:ff:ff:ff
inet192.168.1.11/16scopeglobaleth0
valid_lftforeverpreferred_lftforever
inet6fe80::4494:fcff:fe73:2764/64scopelink
valid_lftforeverpreferred_lftforever
3:eth1:mtu1500qdiscfq_codelstateUPgroupdefaultqlen1000
link/ether44:94:fc:73:27:65brdff:ff:ff:ff:ff:ff
inet192.168.1.11/24brd192.168.1.255scopeglobaleth1
valid_lftforeverpreferred_lftforever
inet6fe80::4694:fcff:fe73:2765/64scopelink
valid_lftforeverpreferred_lftforever