我需要将网卡内核分配的名称 ens34 更改为 buslan0。但是,使用 netplan config 中的 set-name 选项(通过 MAC 地址匹配设备)不起作用。操作系统是在虚拟机管理程序 Vmware Workstation Pro 上全新安装的 Ubuntu 桌面 18.04。
操作系统:Ubuntu 18.04.4 LTS。ubuntu 桌面 5.3.0-53-generic #47~18.04.1-Ubuntu SMP 2020 年 5 月 7 日星期四 13:10:50 UTC x86_64 x86_64 x86_64 GNU/Linux
这是我的 netplan 配置:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
buslan0:
dhcp4: no
addresses: [128.204.10.15/24]
gateway4: 128.204.10.15
nameservers:
addresses: [127.0.0.1, 1.1.1.1, 1.0.0.1]
match:
macaddress: 00:50:56:3f:56:d5
set-name: buslan0
这是我当前的网络
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: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:50:56:3f:56:d5 brd ff:ff:ff:ff:ff:ff
inet6 fe80::8103:e788:ac46:e31a/64 scope link noprefixroute
valid_lft forever preferred_lft forever
当我执行时
sudo netplan apply
sudo reboot
我预期 ens34 为 buslan0,对应的 ip 地址为 128.204.10.15。但是,虚拟机启动时仍然显示相同的当前网络。
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: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:50:56:3f:56:d5 brd ff:ff:ff:ff:ff:ff
inet6 fe80::8103:e788:ac46:e31a/64 scope link noprefixroute
valid_lft forever preferred_lft forever
但是,当我删除 set-name 选项并改用此配置时
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
ens34:
dhcp4: no
addresses: [128.204.10.15/24]
gateway4: 128.204.10.15
nameservers:
addresses: [127.0.0.1, 1.1.1.1, 1.0.0.1]
match:
macaddress: 00:50:56:3f:56:d5
# set-name: buslan0
然后执行以下命令
sudo netplan apply
sudo reboot #optional
我的网络状态是
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
inet 128.204.10.15/24 brd 128.204.10.255 scope global noprefixroute ens34
valid_lft forever preferred_lft forever
我如何可靠地更改我的接口名称?
进一步编辑:我决定在新安装的 Ubuntu 18.04 上测试此操作,该 Ubuntu 18.04 具有截至撰写本文时的最新更新。在使用 netplan 之前,我创建了两个快照:这是我在不同 YMAL 配置之前的网络状态
$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.228.140 netmask 255.255.255.0 broadcast 192.168.228.255
inet6 fd15:4ba5:5a2b:1008:36c2:ccfe:4c83:5f65 prefixlen 64 scopeid 0x0<global>
inet6 fe80::7871:1aa8:f5f7:3cc0 prefixlen 64 scopeid 0x20<link>
inet6 fd15:4ba5:5a2b:1008:d108:59df:ac5d:f3d4 prefixlen 64 scopeid 0x0<global>
ether 00:50:56:37:aa:26 txqueuelen 1000 (Ethernet)
RX packets 12 bytes 1370 (1.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 69 bytes 9422 (9.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::527c:66a3:baf4:9ae4 prefixlen 64 scopeid 0x20<link>
ether 00:50:56:3f:56:d5 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 31 bytes 4145 (4.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 122 bytes 9601 (9.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 122 bytes 9601 (9.6 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
在一个快照上我尝试了这个 YMAL 配置
network:
version: 2
renderer: networkd
ethernets:
ens34:
addresses: [128.204.10.15/24]
gateway4: 128.204.10.1
nameservers:
addresses: [1.1.1.1, 1.0.0.1]
match:
macaddress: 00:50:56:3f:56:d5
set-name: buslan0
然后执行这些命令
~$ sudo netplan --debug generate
~$ sudo ifconfig ens34 down
~$ sudo netplan apply
~$ ifconfig
buslan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 128.204.10.15 netmask 255.255.255.0 broadcast 128.204.10.255
inet6 fe80::5c1:b817:995c:58fb prefixlen 64 scopeid 0x20<link>
ether 00:50:56:3f:56:d5 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 109 bytes 15353 (15.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.228.140 netmask 255.255.255.0 broadcast 192.168.228.255
inet6 fd15:4ba5:5a2b:1008:36c2:ccfe:4c83:5f65 prefixlen 64 scopeid 0x0<global>
inet6 fe80::7871:1aa8:f5f7:3cc0 prefixlen 64 scopeid 0x20<link>
inet6 fd15:4ba5:5a2b:1008:ac17:14d4:1aee:3e25 prefixlen 64 scopeid 0x0<global>
ether 00:50:56:37:aa:26 txqueuelen 1000 (Ethernet)
RX packets 51 bytes 6869 (6.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 159 bytes 19464 (19.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 243 bytes 20571 (20.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 243 bytes 20571 (20.5 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
~$ reboot
重启后的网络状态
:~$ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 42 bytes 3817 (3.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 42 bytes 3817 (3.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
~$ ifconfig -a
buslan0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 00:50:56:3f:56:d5 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
ens33: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 00:50:56:37:aa:26 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
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 42 bytes 3817 (3.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 42 bytes 3817 (3.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
在另一个快照上使用这个 YMAL 文件
network:
version: 2
renderer: networkd
ethernets:
ens34:
match:
macaddress: 00:50:56:3f:56:d5
bridges:
buslan0:
addresses: [128.204.10.15/24]
gateway4: 128.204.10.1
nameservers:
addresses: [1.1.1.1, 1.0.0.1]
interfaces:
- ens34
macaddress: 00:50:56:3f:56:d5
然后执行这些命令
sudo netplan --debug generate
sudo netplan apply
~$ ifconfig
buslan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 128.204.10.15 netmask 255.255.255.0 broadcast 128.204.10.255
inet6 fe80::250:56ff:fe3f:56d5 prefixlen 64 scopeid 0x20<link>
ether 00:50:56:3f:56:d5 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 177 bytes 11478 (11.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.228.140 netmask 255.255.255.0 broadcast 192.168.228.255
inet6 fd15:4ba5:5a2b:1008:213b:6d49:9722:144f prefixlen 64 scopeid 0x0<global>
inet6 fe80::7871:1aa8:f5f7:3cc0 prefixlen 64 scopeid 0x20<link>
inet6 fd15:4ba5:5a2b:1008:36c2:ccfe:4c83:5f65 prefixlen 64 scopeid 0x0<global>
ether 00:50:56:37:aa:26 txqueuelen 1000 (Ethernet)
RX packets 1327 bytes 1379455 (1.3 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1018 bytes 88809 (88.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:50:56:3f:56:d5 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 245 bytes 24496 (24.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 336 bytes 28905 (28.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 336 bytes 28905 (28.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
reboot
重启后我的网络状态
~$ ifconfig
buslan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 128.204.10.15 netmask 255.255.255.0 broadcast 128.204.10.255
inet6 fe80::250:56ff:fe3f:56d5 prefixlen 64 scopeid 0x20<link>
ether 00:50:56:3f:56:d5 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 78 bytes 7773 (7.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:50:56:3f:56:d5 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 78 bytes 8021 (8.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 67 bytes 6124 (6.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 67 bytes 6124 (6.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
这里的要点是,一旦我重新启动,我就会失去互联网连接。然而,在每次重新启动之前和 sudo netplan apply 之后,我能够实现将接口名称更改为我选择的名称的目标。
答案1
看完这个之后邮政我找到了一个我用过的解决方案
- 申请网络计划
- cp /run/systemd/network/*.link /etc/systemd/network/
- 更新-initramfs -u
- 重启#现在一切都好了
重点是它强制在 initramfs 中尽早应用重命名,这似乎足以在启动期间配置和启动接口。我已经验证了重命名现在可以提前发生 - 而在解决此问题之前没有 - 通过在
break=mount
内核命令行上使用。