硬件:树莓派3B+
软件:Raspberry Pi OS Lite / Release date: December 11th 2023 / System: 64-bit / Kernel version: 6.1 / Debian version: 12 (bookworm)
网关:192.168.1.1
1.查看当前地址192.168.1.X和网卡
$ ip add show
找到eth0以及192.168.1.X/24 (当前IP)
2.获取连接名称
$ nmcli connection
找到eth0前对应的name,比如:Wired connection 1
3.分配静态 ipv4 地址 192.168.1.XX
$ sudo nmcli connection modify ‘Wired connection 1’ ipv4.address 192.168.1.XX/24
4.设置网关
$ sudo nmcli connection modify ‘Wired connection 1’ ipv4.gateway 192.168.1.1
5.将分配方式从 DHCP 更改为 Manual (保证IP 将是静态和持久的)
$ sudo nmcli connection modify ‘Wired connection 1’ ipv4.method manual
6.设置 DNS 服务器 IP
$ sudo nmcli connection modify ‘Wired connection 1’ ipv4.dns ‘8.8.8.8’
7.重启系统
$ sudo reboot