![ubuntu20.04中想修改网卡名称,添加虚拟网卡,请问有什么问题吗?](https://linux22.com/image/1069482/ubuntu20.04%E4%B8%AD%E6%83%B3%E4%BF%AE%E6%94%B9%E7%BD%91%E5%8D%A1%E5%90%8D%E7%A7%B0%EF%BC%8C%E6%B7%BB%E5%8A%A0%E8%99%9A%E6%8B%9F%E7%BD%91%E5%8D%A1%EF%BC%8C%E8%AF%B7%E9%97%AE%E6%9C%89%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98%E5%90%97%EF%BC%9F.png)
我的目标:
1:将网卡“ens33”重命名为“mangment_interface”。
2:添加名为“provider_interface”的虚拟网卡。
如何修改yaml文件中的代码?
可能有用:
/etc/netplan/01-network-manager-all.yaml
文件
network:
version: 2
renderer: NetworkManager
ethernets:
mangment_interface:
dhcp4: true
optional: true
addresses: []
provider_interface:
addresses: [192.168.95.130/24]
gateway4: 192.168.95.1
dhcp4: no
nameservers:
addresses: [8.8.8.8,8.8.4.4]
enp0s8:
dhcp4: true
addresses: []
optional: true
显示结果ip a
:
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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:3b:28:3e brd ff:ff:ff:ff:ff:ff
inet 192.168.95.130/24 brd 192.168.95.255 scope global dynamic noprefixroute ens33
valid_lft 1789sec preferred_lft 1789sec
inet6 fe80::63c0:b4a0:db9e:aca5/64 scope link noprefixroute
valid_lft forever preferred_lft forever
执行时sudo netplan --debug apply
:
(可能有用的部分)
DEBUG:mangment_interface not found in {}
DEBUG:provider_interface not found in {'mangment_interface': {'dhcp4': True, 'optional': True, 'addresses': []}}
(全部信息)
** (generate:4408): DEBUG: 21:02:13.381: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:4408): DEBUG: 21:02:13.381: starting new processing pass
** (generate:4408): DEBUG: 21:02:13.381: We have some netdefs, pass them through a final round of validation
** (generate:4408): DEBUG: 21:02:13.381: enp0s8: setting default backend to 2
** (generate:4408): DEBUG: 21:02:13.381: Configuration is valid
** (generate:4408): DEBUG: 21:02:13.381: mangment_interface: setting default backend to 2
** (generate:4408): DEBUG: 21:02:13.381: Configuration is valid
** (generate:4408): DEBUG: 21:02:13.381: provider_interface: setting default backend to 2
** (generate:4408): DEBUG: 21:02:13.381: Configuration is valid
** (generate:4408): DEBUG: 21:02:13.381: Generating output files..
** (generate:4408): DEBUG: 21:02:13.381: networkd: definition mangment_interface is not for us (backend 2)
** (generate:4408): DEBUG: 21:02:13.382: networkd: definition provider_interface is not for us (backend 2)
** (generate:4408): DEBUG: 21:02:13.382: networkd: definition enp0s8 is not for us (backend 2)
(generate:4408): GLib-DEBUG: 21:02:13.382: posix_spawn avoided (fd close requested)
DEBUG:no netplan generated networkd configuration exists
DEBUG:netplan generated NM configuration changed, restarting NM
DEBUG:mangment_interface not found in {}
DEBUG:provider_interface not found in {'mangment_interface': {'dhcp4': True, 'optional': True, 'addresses': []}}
DEBUG:enp0s8 not found in {'mangment_interface': {'dhcp4': True, 'optional': True, 'addresses': []}, 'provider_interface': {'addresses': ['192.168.95.130/24'], 'gateway4': '192.168.95.1', 'dhcp4': False, 'nameservers': {'addresses': ['8.8.8.8', '8.8.4.4']}}}
DEBUG:Merged config:
network:
bonds: {}
bridges: {}
ethernets:
enp0s8:
addresses: []
dhcp4: true
optional: true
mangment_interface:
addresses: []
dhcp4: true
optional: true
provider_interface:
addresses:
- 192.168.95.130/24
dhcp4: false
gateway4: 192.168.95.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
vlans: {}
wifis: {}
DEBUG:Skipping non-physical interface: lo
DEBUG:Skipping non-physical interface: ens33
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for ens33
答案1
默认情况下,netplan 中用于标识以太网接口的名称应该是内核提供的名称。
如果要更改设备的名称,则需要使用match
和的组合set-name
,如https://netplan.io/reference/#common-properties-for-physical-device-types。
例如:
network:
version: 2
renderer: NetworkManager
ethernets:
mangment_interface:
match:
name: ens33
set-name: mangment_interface
dhcp4: true
optional: true
您对“虚拟网卡”的理解有些不清楚。如果您指的是接口veth
,那么从 0.100 版开始,netplan 目前不支持这些接口。但是,我不清楚为什么 veth 接口(位于内核内部,不连接到任何物理链路)会被描述为“provider_interface”。您可能想要的是 vlan,但您在问题中没有提到 vlan ID。
VLAN 看起来类似于:
vlans:
provider_interface:
link: mangment_interface
addresses: [192.168.95.130/24]
gateway4: 192.168.95.1
dhcp4: no
nameservers:
addresses: [8.8.8.8,8.8.4.4]