【家庭服务器计划】brctl | 配置 LAN 口桥接

安装 bridge-utils

apt install bridge-utils

现有网卡 板载 Realtek (eth0),Intel I350-T4 (eth1, eth2, eth3, eth4)。

将 eth0 备用,eth1 作为 WAN ,桥接 eth2 – 4

创建网桥 br0

brctl addbr br0

添加网卡至 br0

brctl addif br0 eth2
brctl addif br0 eth3
brctl addif br0 eth4

设置好 IP 地址和子网掩码

iface br0 inet static
address 192.168.233.1
netmask 255.255.255.0

设置开机运行,编辑 rc.local,在 exit 0 之前添加

brctl addbr br0
brctl addif br0 eth2
brctl addif br0 eth3
brctl addif br0 eth4
ip link set br0 up

还要在 br0 up 的时候把所有 LAN 端口都 up。经过实验直接在 rc.local 中用 ip 和 ifconfig 都不起作用,在 /etc/network/interface 中使用 allow-hotplug 和 auto 也不起作用。

最终管用的方案,在 interface 中对 br0 使用 pre-up。
pre-up,在网卡 up 前执行命令。

pre-up ip link set eth2 up
pre-up ip link set eth3 up
pre-up ip link set eth4 up

1 条评论
发表一条评论