我以奇怪的方式在单个接口上看到两个 IP 地址。这是我的输出配置文件
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)
这是我的/etc/网络/接口文件输出
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
这是我的输出sudo ip addr 显示
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
正如我们在这里看到的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
答案1
我遇到过同样的问题。
最后发现,在我的发行版(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
因此,我从该文件中删除了该额外记录,并永久解决了该问题。
希望它能够帮助到别人...
答案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
请求是“如何摆脱“10.0.0.100/24”地址
这将摆脱它
ip address del 10.0.0.100/24 dev eth0
这将使其恢复
ip address add 10.0.0.100/24 dev eth0
这些都是“非持久性的”,所以更好的问题可能是,是什么让这个地址一直放在你的接口上
答案3
我遇到了同样的问题。
尝试在我的电脑中设置静态 IP 后/etc/netplan/99-config.yaml
,仍然无法获得网络连接(以及看到两个 IP 地址ip a
)。我四处寻找并发现 dhcpd 可能是原因之一。
cat /etc/dhcpd.conf
制作:
...
# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private
interface enp3s0
static ip_address=192.168.0.15/24
static routers=192.168.0.1
static domain_name_servers=127.0.0.1
我可以看到,由于某种原因,我设置了一个静态 IP /etc/dhcpd.conf
。
所以我删除了那些行,最后我能够建立网络连接,并且ip a
只显示我设置的静态 IP /etc/netplan/99-config.yaml
。
答案4
whois
对该 IP 地址进行查询显示 :
WHOIS results for 169.254.78.64
NetRange: 169.254.0.0 - 169.254.255.255
CIDR: 169.254.0.0/16
NetName: LINKLOCAL-RFC3927-IANA-RESERVED
NetHandle: NET-169-254-0-0-1
Parent: NET169 (NET-169-0-0-0-0)
NetType: IANA Special Use
OriginAS:
Organization: Internet Assigned Numbers Authority (IANA)
RegDate: 1998-01-27
Updated: 2014-01-09
Comment: 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. They are commonly called the "link local" addresses.
Comment:
Comment: Routers are not allowed to forward packets sent from an IPv4 "link local" address, so they are always used by a directly connected device.
Comment:
Comment: These addresses were assigned by the IETF, the organization that develops Internet protocols, in the Standards Track document, RFC3927, which can be found at:
Comment: http://datatracker.ietf.org/doc/rfc3927
Ref: http://whois.arin.net/rest/net/NET-169-254-0-0-1
所以这不是什么大问题。接口是promiscuous
,这意味着它将接收所有数据包。
要查看哪些进程已打开它,man lsof
将会sudo lsof /dev/eth1
有所帮助。