Ubuntu 22.04 桥接配置
1. 网卡配置文件备份
sudo cp /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all.yaml.bak
1.1 静态ip配置
1.1.3 解释
network:
version: 2
ethernets:# 网卡名称 使用ifconfig查看
ens33:
dhcp4: false
dhcp6: false
bridges:# 网桥名称 自定义的,一般第一块都是叫这个名称
br0:# 绑定到桥上的网卡 ifconfig查看
interfaces: [ens33]
dhcp4: false# 一般根据自己的网卡ens33 我的是192.168.227.134,所以网桥ip设置了135
addresses: [192.168.227.135/24]
routes:
- to: default# route -n 查看
via: 192.168.227.2
nameservers:
addresses: [114.114.114.114, 8.8.8.8]
parameters:
stp: false
dhcp6: false
1.1.4 配置
network:
version: 2
ethernets:
ens33:
dhcp4: false
dhcp6: false
bridges:
br0:
interfaces: [ens33]
dhcp4: false
addresses: [192.168.227.135/24]
routes:
- to: default
via: 192.168.227.2
nameservers:
addresses: [114.114.114.114, 8.8.8.8]
parameters:
stp: false
dhcp6: false
1.2 动态IP配置
network:
version: 2
ethernets:
ens33:
dhcp4: false
dhcp6: false
bridges:
br0:
interfaces: [ens33]
dhcp4: true
parameters:
stp: false
dhcp6: false
2. 激活
sudo netplan apply
sudo netplan generate
sudo netplan --debug apply
3. 查看
sudo apt install bridge-utils -y
brctl show