ubuntu22.04为kvm虚拟机设置网桥

cd /etc/netplan/

找到00-installer-config.yaml01-netcfg.yaml

原配置文件:

1
2
3
4
5
6
7
8
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
dhcp4: true
version: 2


添加内容后:

1
2
3
4
5
6
7
8
9
10
11
12
13
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
dhcp4: true
version: 2


bridges:
br0:
interfaces: [ens33]
dhcp4: yes

应用配置:

1
netplan apply

这时会重置网络,如果是DHCP,IP会变,连不上,找到新的IP连接。

网络中会看到br0

image-20220424224233396

虚拟机中网络设置:源为br0。

image-20220424221055601