Ubuntu 16.04 Bridge配置
阅读原文时间:2023年07月14日阅读:1
root@ubuntu:~# apt-get install bridge-utils

二、创建网桥设备

  //安装网桥拓展包会安装 brctl 命令,使用该命令创建网桥设备
root@ubuntu:~# brctl addbr br1       # br1是网桥设备名,类似网卡名称;也可以创建多个网桥设备

  //可以在 /proc/sys/net/ipv4/conf/ 目录下查看创建的和已经存在的网卡设备文件
root@ubuntu:~# ls /proc/sys/net/ipv4/conf/
all  br0  default  eth0  eth1  eth2  eth3  eth4  lo        # br0 就是刚刚创建的网桥名称
  • 如果存在在工作的网卡,需要先将其停下来

三、配置 bridge-utils

root@ubuntu:~# vim /etc/network/interfaces
# network interface settings; autogenerated
# Please do NOT modify this file directly, unless you know what
# you're doing.
#
# If you want to manage parts of the network configuration manually,
# please utilize the 'source' or 'source-directory' directives to do
# so.
# PVE will preserve these directives, but will NOT read its network
# configuration from sourced files, so do not attempt to move any of
# the PVE managed interfaces into external files!

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto eth1
iface eth1 inet manual

auto eth2
iface wth2 inet manual

auto eth3
iface eth3 inet manual

auto br0
iface br0 inet static
    address 192.168.121.24
        netmask 255.255.255.0
    gateway 211.91.165.129
    bridge_ports eth0
    bridge_stp off
    bridge_fd 0    

auto br1
iface br1 inet manual
    bridge_ports eth1
    bridge_stp off
    bridge_fd 0

auto br2
iface br2 inet manual
    bridge_ports eth2
    bridge_stp off
    bridge_fd 0

auto br3
iface br3 inet manual
    bridge_ports eth3
    bridge_stp off
    bridge_fd 0
  • 也可以配置动态(dhcp)

    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet manual

    auto eth1
    iface eth1 inet manual

    auto eth2
    iface wth2 inet manual

    auto eth3
    iface eth3 inet manual

    auto br0
    iface br0 inet dhcp
    bridge_ports eth0
    bridge_ports eth1
    bridge_ports eth2
    bridge_ports eth3
    bridge_stp off
    bridge_fd 0

四、开启路由转发

  //网桥设置好后,需要设置路由转发功能
root@ubuntu:~#  /etc/sysctl.conf
......
net.ipv4.ip_forward=1        # 添加或者去掉注释这一行
......

   //让转发路由生效
root@ubuntu:~# sysctl -p

五、重启网络服务

root@ubuntu:~#  systemctl restart networking.service