参考链接:
https://www.go2aaron.com/blog/index.php/archives/28/
https://superuser.com/questions/1000570/why-eth0-is-renamed-to-enx78e7d1ea46da-after-upgrade
https://tinkerboarding.co.uk/forum/thread-990.html
usb网卡命名
在RK3399 Ubuntu系统上使用usb转百兆网卡ASIX AX88772B,因为udev规则配置的原因,出现了usb网卡名称的困扰,我的usb网卡的名称变成了enx000ec6877201,而不是传统的ethX:
forlinx@forlinx:~$ ifconfig
enx000ec6877201: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500ether 00:0e:c6:87:72:01 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500ether 9a:0b:9d:ed:7f:96 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 4 bytes 600 (600.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0device interrupt 24
仔细看这个网卡名称是由enx+mac地址拼接而成的。
网络接口名称规则有以下几种:
1. 包含固件/BIOS 的名称为板载设备提供索引号(例如:eno1)
2. 包含固件/BIOS 提供的 PCI Express 热插拔插槽索引号的名称(例如:ens1)
3. 包含硬件连接器物理/地理位置的名称(例如:enp2s0)
4. 包含接口 MAC 地址的名称(例如:enx78e7d1ea46da)
5. 经典的、不可预测的内核原生 ethX 命名(例如:eth0)
查看打印信息,我们发现usb网卡被重命名了:
forlinx@forlinx:~$ dmesg | grep asix
[ 1.366431] usbcore: registered new interface driver asix
[ 4.686485] asix 5-1:1.0 eth1: register 'asix' at usb-xhci-hcd.10.auto-1, ASIX AX88772B USB 2.0 Ethernet, 00:0e:c6:87:72:01
[ 4.784644] asix 5-1:1.0 enx000ec6877201: renamed from eth1
通过查找,我们发现是udev的某个规则文件按照规则4,对usb网卡的命名进行了设置
/lib/udev/rules.d/73-usb-net-by-mac.rules
# Use MAC based names for network interfaces which are directly or indirectly
# on USB and have an universally administered (stable) MAC address (second bit
# is 0). Don't do this when ifnames is disabled via kernel command line or
# customizing/disabling 99-default.link (or previously 80-net-setup-link.rules).IMPORT{cmdline}="net.ifnames"
ENV{net.ifnames}=="0", GOTO="usb_net_by_mac_end"ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb", NAME=="", \ATTR{address}=="?[014589cd]:*", \TEST!="/etc/udev/rules.d/80-net-setup-link.rules", \TEST!="/etc/systemd/network/99-default.link", \IMPORT{builtin}="net_id", NAME="$env{ID_NET_NAME_MAC}"# Some Dell BIOS perform "MAC passthrough" which forces the same MAC address
# for the onboard nic and the in-dock nic, which obviously prevents naming
# the interfaces by mac. Since those nics are usb, we have to prevent trying
# to rename both of them to the same name. This sets a value that will
# cause udevd to skip its repeated attempts at renaming the interface if the
# first rename attempt fails.
ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb", \ATTR{[dmi/id]sys_vendor}=="Dell Inc.", \ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="8153", \ENV{DELL_MAC_PASSTHROUGH}="1"LABEL="usb_net_by_mac_end"
在系统缺失"/etc/udev/rules.d/80-net-setup-link.rules"和"/etc/systemd/network/99-default.link"这两个文件时,usb网卡就会被重命名。
我们尝试创建99-default.link,未添加规则,只是个空文件,usb网卡名称就变回来了:
forlinx@forlinx:~$ ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500ether 9a:0b:9d:ed:7f:96 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0device interrupt 24 eth1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500ether 00:0e:c6:87:72:01 txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
相关内容
网络配置
RK3399 Ubuntu系统网络使用NetworkManager进行管理,开发板默认千兆以太网的配置保存在如下路径中:
/etc/NetworkManager/system-connections/
配置文件的生成可以通过NetworkManager任务栏图标进行更改,内容类似如下:
[connection]
id=eth0
uuid=1c27ec71-91e9-37ad-9cee-ff94afa20c4c
type=ethernet
autoconnect-priority=-999
permissions=
timestamp=1623739551[ethernet]
mac-address=9A:0B:9D:ED:7F:96
mac-address-blacklist=[ipv4]
dns-search=
method=auto[ipv6]
addr-gen-mode=stable-privacy
dns-search=
ip6-privacy=0
method=auto
网络名称更改
/etc/systemd/network/99-default.link
[Match]
MACAddress=00:0E:C6:87:72:01[Link]
Name=eth1
/lib/udev/rules.d/
forlinx@forlinx:~$ vi /lib/udev/rules.d/
39-usbmuxd.rules
40-usb_modeswitch.rules
40-vm-hotadd.rules
50-apport.rules
50-firmware.rules
50-udev-default.rules
55-dm.rules
55-ippusbxd.rules
60-block.rules
60-cdrom_id.rules
60-crda.rules
60-drm.rules
60-evdev.rules
60-input-id.rules
60-libgphoto2-6.rules
60-libsane1.rules
60-persistent-alsa.rules
60-persistent-input.rules
60-persistent-storage-dm.rules
60-persistent-storage-tape.rules
60-persistent-storage.rules
60-persistent-v4l.rules
60-sensor.rules
60-serial.rules
60-triggerhappy.rules
61-gnome-settings-daemon-rfkill.rules
61-persistent-storage-android.rules
64-btrfs.rules
64-xorg-xkb.rules
65-libwacom.rules
69-cd-sensors.rules
69-libmtp.rules
70-96boards-common.rules
70-joystick.rules
70-mouse.rules
70-power-switch.rules
70-printers.rules
70-touchpad.rules
70-uaccess.rules
71-power-switch-proliant.rules
71-seat.rules
73-seat-late.rules
73-special-net-names.rules
73-usb-net-by-mac.rules
75-net-description.rules
75-probe_mtd.rules
77-mm-cinterion-port-types.rules
77-mm-dell-port-types.rules
77-mm-ericsson-mbm.rules
77-mm-fibocom-port-types.rules
77-mm-haier-port-types.rules
77-mm-huawei-net-port-types.rules
77-mm-longcheer-port-types.rules
77-mm-mtk-port-types.rules
77-mm-nokia-port-types.rules
77-mm-pcmcia-device-blacklist.rules
77-mm-qdl-device-blacklist.rules
77-mm-sierra.rules
77-mm-simtech-port-types.rules
77-mm-telit-port-types.rules
77-mm-ublox-port-types.rules
77-mm-usb-device-blacklist.rules
77-mm-usb-serial-adapters-greylist.rules
77-mm-x22x-port-types.rules
77-mm-zte-port-types.rules
78-graphics-card.rules
78-sound-card.rules
80-debian-compat.rules
80-drivers.rules
80-iio-sensor-proxy.rules
80-libinput-device-groups.rules
80-mm-candidate.rules
80-net-setup-link.rules
80-udisks2.rules
84-nm-drivers.rules
85-hdparm.rules
85-nm-unmanaged.rules
85-regulatory.rules
90-alsa-restore.rules
90-console-setup.rules
90-libinput-model-quirks.rules
90-pulseaudio.rules
95-cd-devices.rules
95-dm-notify.rules
95-upower-csr.rules
95-upower-hid.rules
95-upower-wup.rules
97-hid2hci.rules
99-systemd.rules