我有一个覆盆子3通过以太网和wifi连接到我的路由器。 所以我知道我应该有2个IP地址引用它。
但我写了hostname -I
并获得3个不同的IP地址:
192.168.1.100
,192.168.1.33
和192.168.1.35
第三个IP来自哪里?
如果我从RPI断开以太网电缆并重新写入hostname -I
我得到:
192.168.1.100
和192.168.1.33
这对'ifconfig'结果没有意义:
eth0 Link encap:Ethernet HWaddr b8:27:eb:d6:xx:xx
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:fed6:xxxx/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:23152 errors:0 dropped:6 overruns:0 frame:0
TX packets:51977 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12371346 (11.7 MiB) TX bytes:58608891 (55.8 MiB)
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:65536 Metric:1
RX packets:416 errors:0 dropped:0 overruns:0 frame:0
TX packets:416 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:47205 (46.0 KiB) TX bytes:47205 (46.0 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:83:xx:xx
inet addr:192.168.1.33 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::8df4:f4d0:xxxx:115/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:28407 errors:0 dropped:23070 overruns:0 frame:0
TX packets:4040 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7492811 (7.1 MiB) TX bytes:4725779 (4.5 MiB)
更新
正如Bugfinger指出使用ip addr show
显示地址分配给哪个设备:
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:d6:fb:5a brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.35/24 brd 192.168.1.255 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::ba27:ebff:fed6:fb5a/64 scope link
valid_lft forever preferred_lft forever`
我有两个不同的地址到eth0:
scope global eth0
和scope global secondary eth0
答案 0 :(得分:1)
最近的Raspbian版本(因为 Jessie )正在使用 DHCP客户端守护程序(DHCPCD)来配置网络设备。因此,要在/etc/dhcpcd.conf
中配置静态IP地址。如果您手动或通过/etc/network/interfaces
将它们配置为静态,则最终会在同一设备上使用一个静态IP地址和一个动态IP地址。至于我读到它,它还不清楚,如果这是 DHCPCD 中的错误或错误配置后的预期行为。
无论如何,要改变这种情况,你必须按照以下步骤进行。
要查看它是否正在运行,请检查输出:
sudo service dhcpcd status
如果它没有运行,请使用以下命令启动它:
sudo service dhcpcd start
sudo systemctl enable dhcpcd
如果您已更改/etc/network/interfaces
,则需要还原这些更改。该文件的原始内容(在 Jessie 中)是:
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
现在应该再次通过DHCP配置所有接口。如果您现在要为eth0
设置静态IP地址,请修改/etc/dhcpcd.conf
并输入:
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1 # or whatever your router is
static domain_name_servers=192.168.1.1 # same as router
保存文件和sudo reboot
后,您的 Raspi 应该使用静态eth0
和动态wlan0
重启,并且不会留下额外的IP地址。