我有一个 WiFi 适配器华硕 USB-AC53 Nano使用我自己编译的rtl88x2bu驱动程序。当我启动计算机时,由于该功能可预测的接口名称通过systemd,我总是得到一个接口名称(wlx
+它的MAC地址)。有时,我需要拔下适配器并稍后再重新插入。但随后接口名称更改为wlan0
.然后我过去的 WiFi 密码会被 NetworkManager 忽略,因为它通过接口名称来识别网络连接。
重新插入后,我发现以下行指示失败(下面有详细的系统日志;我将 MAC 地址替换为wlxAABBCCDDEEFF
):
wlan0: Network interface 'wlan0' is already up, refusing to rename to 'wlxAABBCCDDEEFF'.
如果我在拔出之前关闭接口rfkill
,问题就会消失,即接口重命名将会成功。但每次接口断开连接时都这样做是非常烦人的。 WiFi 适配器应该是可热插拔的,并且我不想禁用接口重命名触发器。
所以我的问题是,可以指示systemd以便在恢复rfkill状态之前完成接口重命名工作吗?或者我可以制作一个脚本,以便每次重新插回适配器时都可以使用它吗?
这是我的系统日志中的摘录。我使用的是 Ubuntu 22.04。
Oct 14 20:05:55 qbane-pop kernel: [416632.769664] usb 1-9: USB disconnect, device number 15
Oct 14 20:05:55 qbane-pop dhcpcd[101874]: wlan0: removing interface
Oct 14 20:05:55 qbane-pop NetworkManager[808]: <info> [1665749155.8863] device (wlan0): state change: disconnected -> unmanaged (reason 'removed', sys-iface-state: 'removed')
Oct 14 20:05:55 qbane-pop NetworkManager[808]: <info> [1665749155.8906] device (p2p-dev-wlan0): state change: disconnected -> unmanaged (reason 'removed', sys-iface-state: 'removed')
Oct 14 20:05:55 qbane-pop NetworkManager[808]: <info> [1665749155.9023] radio killswitch /sys/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/ieee80211/phy4/rfkill4 disappeared
Oct 14 20:05:55 qbane-pop wpa_supplicant[881]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Oct 14 20:05:55 qbane-pop systemd[1]: Starting Load/Save RF Kill Switch Status...
Oct 14 20:05:55 qbane-pop systemd[1]: Started Load/Save RF Kill Switch Status.
Oct 14 20:05:55 qbane-pop wpa_supplicant[881]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Oct 14 20:05:55 qbane-pop wpa_supplicant[881]: nl80211: deinit ifname=wlan0 disabled_11b_rates=0
Oct 14 20:05:55 qbane-pop kernel: [416632.837039] rtl88x2bu 1-9:1.0: Runtime PM usage count underflow!
Oct 14 20:05:56 qbane-pop kernel: [416633.108966] usb 1-9: new high-speed USB device number 16 using xhci_hcd
Oct 14 20:05:56 qbane-pop kernel: [416633.257416] usb 1-9: New USB device found, idVendor=0b05, idProduct=184c, bcdDevice= 2.10
Oct 14 20:05:56 qbane-pop kernel: [416633.257431] usb 1-9: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Oct 14 20:05:56 qbane-pop kernel: [416633.257439] usb 1-9: Product: 802.11ac NIC
Oct 14 20:05:56 qbane-pop kernel: [416633.257444] usb 1-9: Manufacturer: Realtek
Oct 14 20:05:56 qbane-pop kernel: [416633.257449] usb 1-9: SerialNumber: 123456
Oct 14 20:05:56 qbane-pop NetworkManager[808]: <info> [1665749156.5956] device (wlan0): driver supports Access Point (AP) mode
Oct 14 20:05:56 qbane-pop NetworkManager[808]: <info> [1665749156.5964] manager: (wlan0): new 802.11 Wi-Fi device (/org/freedesktop/NetworkManager/Devices/18)
Oct 14 20:05:56 qbane-pop mtp-probe: checking bus 1, device 16: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-9"
Oct 14 20:05:56 qbane-pop mtp-probe: bus: 1, device: 16 was not an MTP device
Oct 14 20:05:56 qbane-pop systemd-udevd[1127599]: Using default interface naming scheme 'v249'.
Oct 14 20:05:56 qbane-pop NetworkManager[808]: <info> [1665749156.6197] rfkill5: found Wi-Fi radio killswitch (at /sys/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/ieee80211/phy5/rfkill5) (driver rtl88x2bu)
Oct 14 20:05:57 qbane-pop kernel: [416634.154843] start_addr=(0x20000), end_addr=(0x40000), buffer_size=(0x20000), smp_number_max=(16384)
Oct 14 20:05:57 qbane-pop dhcpcd[101874]: wlan0: waiting for carrier
Oct 14 20:05:57 qbane-pop systemd-udevd[1127599]: wlan0: Network interface 'wlan0' is already up, refusing to rename to 'wlxAABBCCDDEEFF'.
Oct 14 20:05:57 qbane-pop NetworkManager[808]: <info> [1665749157.2909] device (wlan0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Oct 14 20:05:57 qbane-pop mtp-probe: checking bus 1, device 16: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-9"
Oct 14 20:05:57 qbane-pop mtp-probe: bus: 1, device: 16 was not an MTP device
Oct 14 20:05:57 qbane-pop NetworkManager[808]: <info> [1665749157.3798] device (wlan0): supplicant interface state: internal-starting -> disconnected
Oct 14 20:05:57 qbane-pop NetworkManager[808]: <info> [1665749157.3799] Wi-Fi P2P device controlled by interface wlan0 created
Oct 14 20:05:57 qbane-pop NetworkManager[808]: <info> [1665749157.3801] manager: (p2p-dev-wlan0): new 802.11 Wi-Fi P2P device (/org/freedesktop/NetworkManager/Devices/19)
Oct 14 20:05:57 qbane-pop NetworkManager[808]: <info> [1665749157.3802] device (p2p-dev-wlan0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Oct 14 20:05:57 qbane-pop NetworkManager[808]: <info> [1665749157.3805] device (wlan0): state change: unavailable -> disconnected (reason 'supplicant-available', sys-iface-state: 'managed')
Oct 14 20:05:57 qbane-pop NetworkManager[808]: <info> [1665749157.3809] device (p2p-dev-wlan0): state change: unavailable -> disconnected (reason 'none', sys-iface-state: 'managed')
答案1
尝试使用udev
规则。
例如,您可以创建一个udev 规则文件直接分配NAME=
(例如您可以创建文件 a /etc/udev/rules.d/70-custom-names.rules
)。将以下规则添加到规则文件中:
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan0", NAME="wlxAABBCCDDEEFF"
如果此解决方案不起作用,则问题可能出在相对于其他 udev 规则的顺序/位置上。
修改后记得重启系统或者尝试使用以下命令避免重启:
udevadm control --reload-rules
我觉得这是解决您的问题的有用链接。
该解决方案适用于自定义 Linux 发行版,遗憾的是我无法在 Ubuntu 发行版上尝试它。