加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Linux上的Loopback接口捕获所有环回流量

发布时间:2020-12-13 16:56:09 所属栏目:Linux 来源:网络整理
导读:在具有正常环回接口的 linux机器上: $ifconfig lolo 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
在具有正常环回接口的 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的响应.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读