(我不是超级用户的常客,所以如果我没有在正确的地方问这个家庭网络问题,请原谅我——我在这里选择了网络工程或服务器故障,基于这个答案)
我有一台 Raspberry Pi 4,它通过以太网电缆连接到我的路由器,并且还连接到 Wi-Fi 网络。我更喜欢使用以太网连接,因为它(大概?)会更快、更稳定。但是,界面eth0
无法访问,我认为这是因为它没有通过 DHCP 正确分配 LAN IP 地址。
我的路由器配置为提供以下范围内的 IP 地址192.168.42.0 / 255.255.255.0
:
该wlan0
接口具有该范围内的 IP 地址,但是eth0
接口没有:
$ ip addr
[...]
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether dc:a6:32:57:f1:ee brd ff:ff:ff:ff:ff:ff
inet 169.254.195.99/16 brd 192.168.42.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::4b37:1a72:26a4:5abb/64 scope link
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether dc:a6:32:57:f1:ef brd ff:ff:ff:ff:ff:ff
inet 192.168.42.95/24 brd 192.168.42.255 scope global dynamic noprefixroute wlan0
valid_lft 40794sec preferred_lft 29994sec
inet6 fe80::bf5f:ba1c:f4b2:f427/64 scope link
valid_lft forever preferred_lft forever
[...]
但 IP 地址eth0
不可用...
# Executed from another machine on the network
$ ping 169.254.195.99
PING 169.254.195.99 (169.254.195.99): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
^C
--- 169.254.195.99 ping statistics ---
5 packets transmitted, 0 packets received, 100.0% packet loss
$ ssh [email protected]
ssh: connect to host 169.254.195.99 port 22: No route to host
$ ping 192.168.42.95
PING 192.168.42.95 (192.168.42.95): 56 data bytes
64 bytes from 192.168.42.95: icmp_seq=0 ttl=64 time=2.424 ms
64 bytes from 192.168.42.95: icmp_seq=1 ttl=64 time=2.580 ms
64 bytes from 192.168.42.95: icmp_seq=2 ttl=64 time=77.418 ms
^C
--- 192.168.42.95 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 2.424/27.474/77.418/35.316 ms
$ ssh [email protected]
[successful connection]
...尝试获取eth0
接口的新地址失败:
# Executed from the Raspberry Pi
$ sudo dhclient eth0 -v
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/dc:a6:32:57:f1:ee
Sending on LPF/eth0/dc:a6:32:57:f1:ee
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 15
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 21
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 9
No DHCPOFFERS received.
No working leases in persistent database - sleeping.
我不想尝试运行sudo dhclient wlan0 -v
进行比较,以防错误配置wlan0
接口并阻止我连接到 Pi。
我怀疑这DHCPDISCOVER on eth0 to 255.255.255.255
是不正确的 - 我认为 的广播地址eth0
应该DHCPDISCOVER
是192.168.42.255
- 但我不知道如何强制执行。我认为没有任何东西dhclient.conf
可以阻止这一点:
$ cat /etc/dhcp/dhclient.conf
# Configuration file for /sbin/dhclient.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
# man page for more information about the syntax of this file
# and a more comprehensive list of the parameters understood by
# dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
# not leave anything out (like the domain name, for example), then
# few changes must be made to this file, if any.
#
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
#prepend domain-name-servers 127.0.0.1;
#require subnet-mask, domain-name-servers;
#timeout 60;
#retry 60;
#reboot 10;
#select-timeout 5;
#initial-interval 2;
#script "/sbin/dhclient-script";
#media "-link0 -link1 -link2", "link0 link1";
#reject 192.33.137.209;
#alias {
# interface "eth0";
# fixed-address 192.5.5.213;
# option subnet-mask 255.255.255.255;
#}
#lease {
# interface "eth0";
# fixed-address 192.33.137.200;
# medium "link0 link1";
# option host-name "andare.swiftmedia.com";
# option subnet-mask 255.255.255.0;
# option broadcast-address 192.33.137.255;
# option routers 192.33.137.250;
# option domain-name-servers 127.0.0.1;
# renew 2 2000/1/12 00:00:01;
# rebind 2 2000/1/12 00:00:01;
# expire 2 2000/1/12 00:00:01;
#}