ip addr show 在一个接口上显示两个 IP 地址

The*_*enx 9 networking ip

我以一种奇怪的方式在单个接口上看到两个 IP 地址。这是我的ifconfig -a输出

eth0      Link encap:Ethernet  HWaddr b8:27:eb:26:b1:c8  
          inet addr:10.0.0.22  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:456 errors:0 dropped:0 overruns:0 frame:0
          TX packets:519 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:63643 (62.1 KiB)  TX bytes:111910 (109.2 KiB)
Run Code Online (Sandbox Code Playgroud)

这是我的/etc/network/interfaces文件输出

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
        address 10.0.0.22
        subnet  255.255.255.0
        gateway 10.0.0.1

auto eth1
allow-hotplug eth1
iface eth1 inet static
#       address 0
#       subnet  255.255.255.0
#       gateway 192.168.0.2
Run Code Online (Sandbox Code Playgroud)

这是我的sudo ip addr show输出

1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether b8:27:eb:26:b1:c8 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.22/8 brd 10.255.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.0.0.100/24 brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UP qlen 1000
    link/ether 00:00:00:00:6c:f8 brd ff:ff:ff:ff:ff:ff
    inet 169.254.78.64/16 brd 169.254.255.255 scope global eth1
       valid_lft forever preferred_lft forever
Run Code Online (Sandbox Code Playgroud)

正如我们在这里看到的,eth0有两个 ip 地址,并且仅由 ip 命令显示,而不由 ifconfig 或 /etc/network/interfaces 文件显示。我无法理解这是从何而来或如何永久禁用第二个 IP。我想永久摆脱第二个 IP 地址。

我还注意到,当系统启动时,这个 IP 会在大约一秒钟后出现。当我执行 dmesg 时,我看到这些是最后几行-

[   15.270464] device eth1 entered promiscuous mode
[   15.576206] asix 1-1.4:1.0 eth1: link up, 100Mbps, full-duplex, lpa 0xCDE1
Run Code Online (Sandbox Code Playgroud)

小智 5

我遇到过同样的问题。

最后发现在我的发行版(debian jessie)中,静态IP设置在文件/etc/dhcpcd.conf中,如下所示:

 ...
 39 # A hook script is provided to lookup the hostname if not set by the DHCP
 40 # server, but it should not be run by default.
 41 nohook lookup-hostname
 42 ## interface eth0
 43   static ip_address=192.168.1.2/24
 44   static routers=192.168.1.254
 45   static domain_name_servers=192.168.1.254
 46 ## interface eth0
 47   static ip_address=192.168.0.3/24
 48   static routers=192.168.0.1
 49   static domain_name_servers=192.168.0.1
Run Code Online (Sandbox Code Playgroud)

因此,我从该文件中删除了该附加记录,并永久解决了该问题。

希望它能帮助某人...


Don*_*Don 2

我知道旧线程,但是,

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether b8:27:eb:26:b1:c8 brd ff:ff:ff:ff:ff:ff
    **inet 10.0.0.22/8** brd 10.255.255.255 scope global eth0
       valid_lft forever preferred_lft forever

    **inet 10.0.0.100/24** brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
Run Code Online (Sandbox Code Playgroud)

请求是“如何删除“10.0.0.100/24”地址

这将摆脱它

ip address del 10.0.0.100/24 dev eth0
Run Code Online (Sandbox Code Playgroud)

这会将其放回

ip address add 10.0.0.100/24 dev eth0
Run Code Online (Sandbox Code Playgroud)

这些都是“非持久性”的,因此更好的问题可能是是什么让该地址一直存在于您的界面上


wal*_*tor -4

Awhois对该 IP 地址的查询显示

\n\n
WHOIS results for 169.254.78.64\nNetRange:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 169.254.0.0 - 169.254.255.255\nCIDR:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 169.254.0.0/16\nNetName:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 LINKLOCAL-RFC3927-IANA-RESERVED\nNetHandle:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 NET-169-254-0-0-1\nParent:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 NET169 (NET-169-0-0-0-0)\nNetType:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 IANA Special Use\nOriginAS:\nOrganization:\xc2\xa0\xc2\xa0 Internet Assigned Numbers Authority (IANA)\nRegDate:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 1998-01-27\nUpdated:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 2014-01-09\nComment:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 Computers use addresses starting with "169.254." when they do not have a manually configured address or when they are not told which address to use by a service on the network.\xc2\xa0 They are commonly called the "link local" addresses.\nComment:\nComment:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 Routers are not allowed to forward packets sent from an IPv4 "link local" address, so they are always used by a directly connected device.\nComment:\nComment:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 These addresses were assigned by the IETF, the organization that develops Internet protocols, in the Standards Track document, RFC3927, which can be found at:\nComment:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 http://datatracker.ietf.org/doc/rfc3927\nRef:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 http://whois.arin.net/rest/net/NET-169-254-0-0-1\n
Run Code Online (Sandbox Code Playgroud)\n\n

所以这不是一个大问题。界面是promiscuous,这意味着它将接收所有数据包。

\n\n

要查看哪些进程已打开它man lsofsudo lsof /dev/eth1会有所帮助。

\n