目前遇到过树莓派和其他设备安装 ubuntu22.04, 使用有线网络一段时间(可能有其他软件安装导致)造成有线网络未启动无ip分配的问题。
1、动态分配
通过命令行启动dhcpclient实现
网络eth0存在异常,网口灯电源和信号灯均点亮,但是信号灯常亮。
首先启动 eth,再自动分配,最后重启网络。
sudo ip link set eth0 up
sudo dhclient eth0
sudo systemctl restart NetworkManager
不出意外,正常自动获取ip。
通过netplan配置自动获取
修改 配置 vim /etc/netplan/50-cloud-init.yaml
中的有线部分,
重启或执行 sudo netplan apply
即可,再使用 ping www.baidu.com -I eth0
验证。
2、静态分配
进入系统之后,默认无ip分配
$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether dc:a6:32:fb:fe:c4 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether dc:a6:32:fb:fe:c5 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.16/24 metric 600 brd 192.168.3.255 scope global dynamic wlan0
valid_lft 86022sec preferred_lft 86022sec
inet6 fe80::dea6:32ff:fefb:fec5/64 scope link
valid_lft forever preferred_lft forever
直接使用netplan配置 vim /etc/netplan/50-cloud-init.yaml
,增加有线网络部分配置
ethernets:
eth0:
dhcp4: no
addresses: [192.168.3.36/24]
gateway4: 192.168.3.254
nameservers:
addresses: [192.168.3.254,8.8.8.8,4.4.4.4]
主要层级,截图如下
保存后,使用 sudo netplan apply
进行启动当前配置。
$ sudo netplan apply
$
$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether dc:a6:32:fb:fe:c4 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.36/24 brd 192.168.3.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::dea6:32ff:fefb:fec4/64 scope link
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether dc:a6:32:fb:fe:c5 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.16/24 metric 600 brd 192.168.3.255 scope global dynamic wlan0
valid_lft 86393sec preferred_lft 86393sec
inet6 fe80::dea6:32ff:fefb:fec5/64 scope link
valid_lft forever preferred_lft forever
之后,使用ping 指定有线网络接口是否可用
$ ping www.baidu.com -I eth0
PING www.a.shifen.com (180.101.50.188) from 192.168.3.36 eth0: 56(84) bytes of data.
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=1 ttl=53 time=7.06 ms
64 bytes from 180.101.50.188 (180.101.50.188): icmp_seq=2 ttl=53 time=6.61 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 6.609/6.832/7.056/0.223 ms
一切正常。