安装 brctl工具
sudo apt-get install bridge-utils
添加桥
brctl addbr br0 #创建桥接 br0 brctl addif br0 eth0 eth1 #添加 eth0, eth1 到 br0 ifconfig br0 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
打开ip转发
sudo vim /etc/sysctl.conf net.ipv4.ip_forward=1
去掉该行前面的注释符#
sudo sysctl -p /etc/sysctl.conf
文件立即生效
修改配置
vim /etc/network/interfaces auto lo br0 iface lo inet loopback auto eth0 iface eth0 inet manual auto eth1 iface eth1 inet manual iface br0 inet dhcp bridge_ports eth0 eth1
或者使用静态IP
iface br0 inet static bridge_ports eth0 eth1 address 192.168.1.2 broadcast 192.168.1.255 netmask 255.255.255.0 gateway 192.168.1.1
重启机器
查看网桥信息
brctl show



