我在 Raspberry Pi 4 上运行 Ubuntu 20.04 桌面操作系统。我已将打印机连接到 Pi 的以太网端口,但在使用 netplan 分配静态 IP 时遇到了麻烦。问题是我找不到接口卡的名称。现在,我已经使用网络管理器创建了一个静态 IP,使用以下命令我可以看到它在 eth0 上,IP 为192.168.123.101
。问题是我找不到接口卡名称。
hd2900@hd2900:~$ ip add show
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 e4:5f:01:49:85:7f brd ff:ff:ff:ff:ff:ff
inet 192.168.123.101/24 brd 192.168.123.255 scope global noprefixroute eth0
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 e4:5f:01:49:85:80 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.94/24 brd 192.168.1.255 scope global dynamic noprefixroute wlan0
valid_lft 50472sec preferred_lft 50472sec
inet6 fe80::5d0a:3259:a2fc:a0d4/64 scope link noprefixroute
valid_lft forever preferred_lft forever
我/etc/netplan/0-rpi-ethernet-eth0.yaml
有这个内容,并且我怀疑这driver bcmgenet smsc95xx and lan78xx
是导致问题的原因。
hd2900@hd2900:/etc/netplan$ cat 10-rpi-ethernet-eth0.yaml
network:
ethernets:
eth0:
# Rename the built-in ethernet device to "eth0"
match:
driver: bcmgenet smsc95xx lan78xx
set-name: eth0
dhcp4: true
optional: true
要设置静态 IP 地址,我需要编辑/etc/netplan/01-network-manager-all.yaml
,并且需要知道网络接口卡的名称。
hd2900@hd2900:/etc/netplan$ cat 01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
根据 Simon Banks 的建议,我更改了文件,如下所示。但是,我需要添加 wifi 连接。
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses: [192.168.123.101/24]
gateway4: 192.168.123.1
match:
driver: bcmgenet smsc95xx lan78xx
set-name: eth0
为了添加 wifi,下面的代码是否可以起作用?
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses: [192.168.123.101/24]
gateway4: 192.168.123.1
match:
driver: bcmgenet smsc95xx lan78xx
set-name: eth0
wifis:
wlan0:
dhcp4: true
access-points: "SSID NAME"
password: "password"
根据 Simon 的建议,我将文件更改/etc/netplan/01-network-manager-all.yaml
为
cat /etc/netplan/01-network-manager-all.yaml
让 NetworkManager 管理此系统上的所有设备
网络: 版本:2 渲染器:networkd 以太网:eth0:dhcp4:false 地址:[192.168.123.101/24] 网关4:192.168.123.1 匹配: 驱动程序:bcmgenet smsc95xx lan78xx 设置名称:eth0 版本:2 wifis:wlan0:dhcp4:是 可选:true 接入点:“HiddenDimsum2900_24Ghz”: 密码:“mysecretPassword”
此后我这样做sudo netplan --debug apply
并得到了这个输出
sudo netplan --debug apply
** (generate:161651): DEBUG: 20:57:29.401: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:161651): DEBUG: 20:57:29.402: starting new processing pass
** (generate:161651): WARNING **: 20:57:29.402: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
** (generate:161651): DEBUG: 20:57:29.402: wlan0: adding wifi AP 'HiddenDimsum2900_24Ghz'
** (generate:161651): DEBUG: 20:57:29.402: Processing input file /etc/netplan/10-rpi-ethernet-eth0.yaml..
** (generate:161651): DEBUG: 20:57:29.403: starting new processing pass
** (generate:161651): DEBUG: 20:57:29.403: We have some netdefs, pass them through a final round of validation
** (generate:161651): DEBUG: 20:57:29.403: wlan0: setting default backend to 1
** (generate:161651): DEBUG: 20:57:29.403: Configuration is valid
** (generate:161651): DEBUG: 20:57:29.403: eth0: setting default backend to 1
** (generate:161651): DEBUG: 20:57:29.403: Configuration is valid
** (generate:161651): DEBUG: 20:57:29.405: Generating output files..
** (generate:161651): DEBUG: 20:57:29.405: openvswitch: definition eth0 is not for us (backend 1)
** (generate:161651): DEBUG: 20:57:29.405: NetworkManager: definition eth0 is not for us (backend 1)
** (generate:161651): DEBUG: 20:57:29.405: Creating wpa_supplicant config
** (generate:161651): DEBUG: 20:57:29.406: wlan0: Creating wpa_supplicant configuration file run/netplan/wpa-wlan0.conf
** (generate:161651): DEBUG: 20:57:29.406: Creating wpa_supplicant unit /run/systemd/system/netplan-wpa-wlan0.service
** (generate:161651): DEBUG: 20:57:29.421: Creating wpa_supplicant service enablement link /run/systemd/system/systemd-networkd.service.wants/netplan-wpa-wlan0.service
** (generate:161651): DEBUG: 20:57:29.421: openvswitch: definition wlan0 is not for us (backend 1)
** (generate:161651): DEBUG: 20:57:29.421: NetworkManager: definition wlan0 is not for us (backend 1)
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:eth0 not found in {}
DEBUG:wlan0 not found in {}
DEBUG:eth0 exists in {'eth0': {'dhcp4': False, 'addresses': ['192.168.123.101/24'], 'gateway4': '192.168.123.1', 'match': {'driver': 'bcmgenet smsc95xx lan78xx'}, 'set-name': 'eth0'}}
DEBUG:Merged config:
network:
ethernets:
eth0:
addresses:
- 192.168.123.101/24
dhcp4: true
gateway4: 192.168.123.1
match:
driver: bcmgenet smsc95xx lan78xx
optional: true
set-name: eth0
renderer: networkd
version: 2
wifis:
wlan0:
access-points:
HiddenDimsum2900_24Ghz:
password: mySecretPassword
dhcp4: true
optional: true
DEBUG:netplan generated NM configuration changed, restarting NM
DEBUG:eth0 not found in {}
DEBUG:wlan0 not found in {}
DEBUG:eth0 exists in {'eth0': {'dhcp4': False, 'addresses': ['192.168.123.101/24'], 'gateway4': '192.168.123.1', 'match': {'driver': 'bcmgenet smsc95xx lan78xx'}, 'set-name': 'eth0'}}
DEBUG:Merged config:
network:
ethernets:
eth0:
addresses:
- 192.168.123.101/24
dhcp4: true
gateway4: 192.168.123.1
match:
driver: bcmgenet smsc95xx lan78xx
optional: true
set-name: eth0
renderer: networkd
version: 2
wifis:
wlan0:
access-points:
HiddenDimsum2900_24Ghz:
password: mysecretPassword
dhcp4: true
optional: true
INFO:[]
WARNING:Cannot find unique matching interface for eth0: {'driver': 'bcmgenet smsc95xx lan78xx'}
DEBUG:Link changes: {}
DEBUG:netplan triggering .link rules for lo
从上面的输出中,我想知道我无法连接到 wlan0 的问题是否是因为首先没有找到 wlan0?
当我这样做时,ip addr
我得到了以下输出
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 e4:5f:01:49:85:7f brd ff:ff:ff:ff:ff:ff
inet 192.168.123.101/24 brd 192.168.123.255 scope global noprefixroute eth0
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 e4:5f:01:49:85:80 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.94/24 brd 192.168.1.255 scope global dynamic noprefixroute wlan0
valid_lft 51306sec preferred_lft 51306sec
inet6 fe80::5d0a:3259:a2fc:a0d4/64 scope link noprefixroute
valid_lft forever preferred_lft forever
iwconfig
产生以下输出
lo no wireless extensions.
eth0 no wireless extensions.
wlan0 IEEE 802.11 ESSID:"HiddenDimsum2900_24Ghz"
Mode:Managed Frequency:2.462 GHz Access Point: 90:F8:91:3F:5F:5F
Bit Rate=72.2 Mb/s Tx-Power=31 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:on
Link Quality=64/70 Signal level=-46 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:93 Invalid misc:0 Missed beacon:0
答案1
我通过 ubuntu 和 RPI OS 在 raspberry pi 上使用 netplan。这是从我的家庭服务器 netplan 直接剪切和粘贴的静态配置。因此,只需更改 IP/子网以匹配您的本地。Netplan 确实抱怨无法匹配驱动程序,但它似乎确实有效,所以不用担心。
为了使其正常工作并且不与宽带路由器 DHCP 分配冲突,我已将其配置为不使用 192.168.0.32-192.168.0.253 范围进行 DHCP。
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
addresses: [192.168.0.10/24]
gateway4: 192.168.0.254
nameservers:
addresses: [192.168.0.254]
match:
driver: bcmgenet smsc95xx lan78xx
set-name: eth0
wlan1:
match:
name: wlx0013eff402eb
set-name: wlan1
wifis:
wlan0:
dhcp4: yes
optional: true
access-points:
RedactedEESID:
band: 5GHz
password: "REDACTED PASSWORD"