[Raspberry PI CM4] 设置网卡静态IP
1. NetworkManager
在版本比较旧的树莓派系统上,可以修改 /etc/dhcpcd.conf 设置静态IP
但在新的系统上需要使用 NetworkManager 进行网络管理
首先使用
nmcli connection show
NAME UUID TYPE DEVICE
HMS-Lab-5G 7f8194c6-a86a-4517-8517-198b1eeb8069 wifi wlan0
lo 693c2185-73c8-4466-bb50-e9c17cf36b24 loopback lo
Wired connection 1 e197b89b-7a02-3621-9bf9-668a997539fa ethernet eth0
查看当前的网络连接情况
然后使用
sudo nmcli connection modify "Wired connection 1" ipv4.method manual ipv4.addresses 192.168.0.2/24
注意连接名称需使用双引号
配置需要的静态IP 地址
最后重启生效
sudo reboot
查看是否生效
ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::131:1b88:fe03:502d prefixlen 64 scopeid 0x20<link>
ether d8:3a:dd:64:8b:e3 txqueuelen 1000 (Ethernet)
RX packets 1 bytes 115 (115.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28 bytes 3907 (3.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0