raspberry5

[toc]

换源

  • 清华源bookworm
1
2
3
4
5
6
7
8
9
10
11
cat >/etc/apt/sources.list<<EOF
# 清华源
deb https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
#deb-src https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
#deb-src https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
#deb-src https://mirrors4.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors4.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
#deb-src https://mirrors4.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
EOF

在树莓派5(bookworm)上设置静态IP地址

随着 Raspberry Pi OS Bookworm 的发布,Raspberry Pi 上的网络改为使用 NetworkManager 作为网络的标准控制器,取代了之前的 dhcpcd 系统。 NetworkManager 包括一个名为nmcli的命令行工具,它可以控制 NetworkManager 并报告网络状态。

接下来,我将使用nmcli将网络配置为使用静态 IP 地址。

  • 找到网络接口名称(树莓派5有两张网卡wlan0和eth0,一般都叫这个,我的可能特别,但是教程都适用)
1
2
3
4
5
6
7
8
9
10
11
root@R5:~# sudo nmcli -p connection show
======================================
NetworkManager connection profiles
======================================
NAME UUID TYPE DEVICE
--------------------------------------------------------------------------------------------------->
preconfigured add9af6e-dda9-4bb5-b69c-845989b05ee4 wifi wlan0
docker0 b899dcfa-19fd-4c29-9aae-42e3851f29a3 bridge docker0
lo ddd0da87-3ac9-4752-9619-b744001c7f8f loopback lo
utun bbd48214-4665-4ec6-8f06-13b466e1829a tun utun
ztk4jl4ggs 6cb57bf8-5c8a-4833-aa72-3ff3f8c69788 tun ztk4jl4ggs

通过上面一堆的网卡,我们都没找到需要的eth0在哪里,反而找到其他的网卡,其实除了eth0wlan0其他都是我的虚拟网卡和本地回环网卡lo网卡

那我的物理网卡接口eth0呢!因为我没接线!所以用connection show是看不出来滴!所以采用更加原始的办法,用你们的tab补全弹出网卡选项

1
2
3
root@R5:~# nmcli device show 
docker0 help p2p-dev-wlan0 wlan0
end0 lo utun ztk4jl4ggs

这里就多出一个end0网卡了,我说它就是eth0你信吗?改个设备名字而已,别慌!!!就是它

因为,我没有接有线,有线网卡没有自动创建它的设备名称和对应的配置

所以,我接下来给它创建一个名称就叫R5_eth0

1
2
root@R5:~# nmcli connection add type ethernet ifname end0 con-name R5_eth0
Connection 'R5_eth0' (0e6c5292-f391-49be-b1f4-1981c5c26538) successfully added.

再看看

1
2
3
4
5
6
7
8
9
10
11
12
root@R5:~# sudo nmcli -p connection show
======================================
NetworkManager connection profiles
======================================
NAME UUID TYPE DEVICE
-----------------------------------------------------------------------------------------------------------------
preconfigured add9af6e-dda9-4bb5-b69c-845989b05ee4 wifi wlan0
docker0 b899dcfa-19fd-4c29-9aae-42e3851f29a3 bridge docker0
lo ddd0da87-3ac9-4752-9619-b744001c7f8f loopback lo
utun bbd48214-4665-4ec6-8f06-13b466e1829a tun utun
ztk4jl4ggs 6cb57bf8-5c8a-4833-aa72-3ff3f8c69788 tun ztk4jl4ggs
R5_eth0 0e6c5292-f391-49be-b1f4-1981c5c26538 ethernet --

额!为啥R5_eth0对应的设备是--而不是end0,我也不知道!但是我可以确认配置有没有生效!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@R5:~# cat /etc/NetworkManager/system-connections/R5_eth0.nmconnection
[connection]
id=R5_eth0
uuid=0e6c5292-f391-49be-b1f4-1981c5c26538
type=ethernet
interface-name=end0

[ethernet]

[ipv4]
method=auto

[ipv6]
addr-gen-mode=default
method=auto

[proxy]

很好,下一步,插上网线

设置静态ip、网关、dns

1
root@R5:~# nmcli connection modify R5_eth0 ipv4.addresses 192.168.0.30/24 ipv4.method manual connection.autoconnect yes ipv4.gateway 192.168.0.1 ipv4.dns 8.8.8.8

网卡启动

1
root@R5:~# nmcli connection up R5_eth0

然后就发现,静态ip设置成功

image-20231228214539257