拔下并重新插入 USB 电缆(USB 上的以太网)后,ifconfig 显示不同的接口

拔下并重新插入 USB 电缆(USB 上的以太网)后,ifconfig 显示不同的接口

我将我的 ARM64 开发板连接到我的 Ubuntu 20.04.1 主机 PC,该开发板带有一个配置为外围设备的 USB 端口,并带有 USB 以太网小工具所需的驱动程序。我使用 USB 公对公电缆将开发板连接到主机 PC。之后,ifconfig -a 向我显示了一个 usb0 接口:

usb0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether ae:1f:07:23:57:06  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

当我拔下电缆并重新插入时,ifconfig -a 接口有一个新名称:

enx7ef758273481: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 7e:f7:58:27:34:81  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

当我设置接口 (ifconfig ) 时,当接口名称为 usb0 时,与主板的连接似乎要快得多。主板上的接口名称也是 usb0,拔出并重新插入不会对主板产生任何影响。dmesg 显示以下输出:

[   89.145321] usb 1-5: new high-speed USB device number 2 using xhci_hcd
[   89.295266] usb 1-5: New USB device found, idVendor=0525, idProduct=a4a2, bcdDevice= 5.15
[   89.295269] usb 1-5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[   89.295270] usb 1-5: Product: RNDIS/Ethernet Gadget
[   89.295271] usb 1-5: Manufacturer: Linux 5.15.32+gfa6c3168595c with dwc3-gadget
[   89.310530] cdc_subset: probe of 1-5:1.0 failed with error -22
[   89.311814] cdc_subset 1-5:1.1 usb0: register 'cdc_subset' at usb-0000:00:14.0-5, Linux Device, ae:1f:07:23:57:06
[   89.311829] usbcore: registered new interface driver cdc_subset
[   89.311846] cdc_ether: probe of 1-5:1.0 failed with error -16
[   89.311868] usbcore: registered new interface driver cdc_ether
[  213.382913] usb 1-5: USB disconnect, device number 2
[  213.382990] cdc_subset 1-5:1.1 usb0: unregister 'cdc_subset' usb-0000:00:14.0-5, Linux Device
[  215.220424] usb 1-5: new high-speed USB device number 3 using xhci_hcd
[  215.370333] usb 1-5: New USB device found, idVendor=0525, idProduct=a4a2, bcdDevice= 5.15
[  215.370337] usb 1-5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  215.370338] usb 1-5: Product: RNDIS/Ethernet Gadget
[  215.370338] usb 1-5: Manufacturer: Linux 5.15.32+gfa6c3168595c with dwc3-gadget
[  215.371653] cdc_subset: probe of 1-5:1.0 failed with error -22
[  215.372954] cdc_ether 1-5:1.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-5, CDC Ethernet Device, 7e:f7:58:27:34:81
[  215.379101] cdc_ether 1-5:1.0 enx7ef758273481: renamed from usb0

为什么要重命名界面以及如何避免这种行为?

编辑 我发现在重新插入电缆之前删除 cdc_ether 驱动程序 (sudo rmmod cdc_ether) 可以解决问题。但我认为这不是完美的解决方法,我想了解为什么要重命名它以及为什么这会影响性能。

答案1

请尝试移除您的设备并创建此文件

/etc/systemd/network/10-usb0.link

包含以下内容

[Match]
Driver=cdc_ether 

[Link]
Name=usb0

让 udev 重新读取规则

sudo udevadm control -R

来源

相关内容