在Debian Linux上如何创建并配置网桥

时间:2019-11-20 08:53:45  来源:igfitidea点击:

在Debian Linux KVM环境如何春节网桥?
如何在Debian Linux 9中设置网桥?

如何安装brctl

执行以下apt命令/apt-get命令:

$ sudo apt install bridge-utils

如何在Debian Linux上设置网桥

需要编辑/etc/network/interface文件。
不过建议在/etc/network/interface.d/目录中创建一个全新的配置。

在Debian Linux上配置网桥的步骤如下:

查看服务器的物理接口

使用ip命令:

$ ip -f inet a s

更新/etc/network/interface文件

确保只有处于活动状态。
删除与eno1相关的所有配置。

$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
 
source /etc/network/interfaces.d/*
 
# The loopback network interface
auto lo
iface lo inet loopback

在/etc/network/interfaces.d/br0中配置桥接(br0)

首先,在/etc/network/interfaces.d/中创建一个新文件:

$ sudo vi /etc/network/interfaces.d/br0

配置如下:

## static ip config file for br0 ##
auto br0
iface br0 inet static
	address 192.168.2.23
	broadcast 192.168.2.255
	netmask 255.255.255.0
	gateway 192.168.2.254
	# If the resolvconf package is installed, you should not edit 
        # the resolv.conf configuration file manually. Set name server here
        #dns-nameservers 192.168.2.254
        # If you have muliple interfaces such as eth0 and eth1
        # bridge_ports eth0 eth1  
	bridge_ports eno1
	bridge_stp off       # disable Spanning Tree Protocol
        bridge_waitport 0    # no delay before a port becomes available
        bridge_fd 0          # no forwarding delay

如果想设置网桥使用DHCP获取IP地址,则修改为:

## DHCP ip config file for br0 ##
auto br0
 
# Bridge setup
iface br0 inet dhcp
    bridge_ports eno1

在Linux中重启网络服务

重启网络服务:

$ sudo systemctl restart network-manager

验证服务已重启:

$ systemctl status network-manager

如果设置有防火墙,必须更新接口br0的防火墙规则。

使用ip命令查看新的br0接口和路由表:

$ ip a s
$ ip r
$ ping -c 2 theitroad.local

使用brctl命令查看有关网桥的信息:

$ brctl show

显示当前的网桥连接:

$ bridge link