树莓派5 raspberry pi 5 netplan vlan网桥配置
一、 安装netplan openvswitch
sudo apt-get install netplan.io -y sudo apt install openvswitch-switch -y sudo apt install vlan bridge-utils
二、
sudo nano /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: NetworkManager #networkd
wifis:
wlan0: # 主网口配置,可以是DHCP或静态IP
dhcp4: true
nameservers:
addresses: [8.8.8.8, 180.76.76.76] # DNS 服务器
access-points:
“chanking”:
password: “password”
ethernets:
eth0: # 主网口配置,可以是DHCP或静态IP
dhcp4: true #eth0配置 …
nameservers:
addresses: [8.8.8.8, 180.76.76.76] # DNS 服务器
vlans:
vlan10: # VLAN ID为10
id: 10
link: eth0
addresses: [192.168.10.100/24]
routes:
– to: default
via: 192.168.10.1
metric: 4001
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
link-local: [] # 表示禁用链路本地地址的自动分配
vlan20: # VLAN ID为20
id: 20
link: eth0
addresses: [192.168.20.100/24]
routes:
– to: default
via: 192.168.20.1
metric: 4002
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
link-local: []
vlan30: # VLAN ID为30
id: 30
link: wlan0
addresses: [192.168.30.100/24]
routes:
– to: default
via: 192.168.30.1
metric: 4003
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
link-local: [] # 表示禁用链路本地地址的自动分配
四、
netplan apply
五、
1、 编辑/etc/sysctl.conf文件,启用 IP 转发
sudo nano /etc/sysctl.conf
2、执行命令生效
sudo sysctl -p
四、其他补充
1、renderer: networkd
出现错误
stevenroc@stevenroc:~ $ sudo netplan apply
** (generate:2823): WARNING **: 20:55:29.065: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.
** (process:2821): WARNING **: 20:55:29.585: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.
** (process:2821): WARNING **: 20:55:30.249: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.
** (process:2821): WARNING **: 20:55:30.863: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.
** (process:2821): WARNING **: 20:55:30.863: Permissions for /etc/netplan/01-netcfg.yaml are too open. Netplan configuration should NOT be accessible by others.
WARNING: systemd-networkd is not running, output will be incomplete.
Failed to reload network settings: Unit dbus-org.freedesktop.network1.service not found.
![]()

解决如下:
renderer: NetworkManager
/etc/netplan/01-netcfg.yaml,附件如下01-netcfg
自适应IP