在具有正常环回接口的
linux机器上:
$ifconfig lo lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:36621784 errors:0 dropped:0 overruns:0 frame:0 TX packets:36621784 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:6752024976 (6.2 GiB) TX bytes:6752024976 (6.2 GiB)
当我ping 127.0.0.0/8范围内的任何添加地址时,我收到回复:
$ping -c1 127.7.23.4 PING 127.7.23.4 (127.7.23.4) 56(84) bytes of data. 64 bytes from 127.7.23.4: icmp_seq=1 ttl=64 time=0.045 ms --- 127.7.23.4 ping statistics --- 1 packets transmitted,1 received,0% packet loss,time 0ms rtt min/avg/max/mdev = 0.045/0.045/0.045/0.000 ms
这种行为特别适用于Linux,因为我在Mac OS X Lion机器上看不到它.我没有为loopback接口设置任何IP别名,这是我希望todo有这个工作.
为什么会发生这种情况并且是预期的行为?
解决方法
Windows也有这种行为.我猜这是对
rfc 3330的不同解释
127.0.0.0/8 – This block is assigned for use as the Internet host loopback address. A datagram sent by a higher level protocol to an address anywhere within this block should loop back inside the host. This is ordinarily implemented using only 127.0.0.1/32 for loopback,but no addresses within this block should ever appear on any network anywhere [RFC1700,page 5].
看起来Linux解释为这意味着127.0.0.0/8范围内的任何(甚至是未配置的地址)应该被循环回来,从而得到ping的响应.