IP 冲突引起的问题

jw-2 开放的端口会出现间歇性的连接不上,直接 “connection refused”,比如从 jw-1 连接
[email protected]:~$ ssh jw-2
ssh: connect to host 192.168.10.50 port 22: Connection refused

查看 jw-1 上当前的 arp 表:
[email protected]:~$ arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.10.50              ether   78:2b:cb:77:d5:3f   C                     eth1

在 jw-2 上查看网络连接:
[email protected]:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr d4:be:d9:ed:64:9d 
          inet addr:192.168.10.50  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:36 Memory:d2000000-d2012800 


发现竟然 MAC 地址竟然不匹配,很有可能是 ip 冲突了,在内网通过 nmap 扫描出重合的 mac:
$ sudo nmap -sP | tee ip-mac
$ grep MAC ip-mac  | awk '{print $3}' | sort | uniq -d

找到了 jw-3 这台机器的 ip 抢占了 jw-2 的:
[email protected]:~$ ifconfig  -a
eth0      Link encap:Ethernet  HWaddr 78:2b:cb:77:d5:3e 
          inet addr:192.168.10.59  Bcast:192.168.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:42363505819 errors:51 dropped:51 overruns:0 frame:51
          TX packets:39027559424 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:37740015735361 (37.7 TB)  TX bytes:40923761865209 (40.9 TB)
          Interrupt:36 Memory:da000000-da012800

eth1      Link encap:Ethernet  HWaddr 78:2b:cb:77:d5:3f 
          inet addr:192.168.10.50  Bcast:192.168.10.255  Mask:255.255.255.0
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:48 Memory:dc000000-dc012800

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:20730207106 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20730207106 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:76932828082803 (76.9 TB)  TX bytes:76932828082803 (76.9 TB)

注意:ifconfig 需要加上 -a 参数,否则不会显示出全部的端口。

此类问题先前在上机器的时候也遇到过,明明是想登录 a 机器,最终结果却登录到了 b 机器,原因跟上面一样。除了能及时发现此类问题,在最初网络规划,分配 ip 地址的时候就要做好相应的功课。