Linux 配置bridge & vlan

  • 服务器型号:DELL R620,R730xd
  • 网卡端口:eno1 ~ eno4(eno1~2为万兆光口,eno3~eno4为千兆电口)
  • 目前使用的端口
    • eno1:万兆光口,上联至交换机的trunk口,allow vlan all;
    • eno3:千兆电口,上联至交换机的access口,vid=200;
  • 服务器安装KVM hypervisor,增加bridge接口,方便将虚拟机接入不同vlan
    • br1:vlan1,带DHCP的网段,并配置服务器ip;
    • br2:vlan2,带DHCP的网段;
    • br3:vlan3,不带DHCP的网段;
    • brdmz:vlan200,DMZ网段;

安装必要包:

sudo apt install bridge-utils
/etc/network/interfaces
source /etc/network/interfaces.d/*
 
# The loopback network interface
auto lo
iface lo inet loopback
 
# vlan 1
auto eno1
iface eno1 inet manual
# vlan 2
auto eno1.2
iface eno1.2 inet manual
# vlan 3
auto eno1.3
iface eno1.3 inet manual
# br1
auto br1
iface br1 inet static
address 172.17.1.1
netmask 255.255.255.0
gateway 172.17.1.254
dns-nameservers 10.1.1.254
bridge_ports eno1
bridge_stp off
# br2
auto br2
iface br2 inet manual
bridge_ports eno1.2
bridge_stp off
# br3
auto br3
iface br3 inet manual
bridge_ports eno1.3
bridge_stp off
# br_dmz
auto brdmz
iface brdmz inet manual
bridge_ports eno3
bridge_stp off
# br100
auto br100
iface br100 inet manual
bridge_ports none
bridge_stp off
# br101
auto br101
iface br101 inet manual
bridge_ports none
bridge_stp off

其他参数:

  • bridge_stp off # disable Spanning Tree Protocol
  • bridge_waitport 0 # no delay before a port becomes available
  • bridge_fd 0 # no forwarding delay
  • bridge_ports none # if you do not want to bind to any ports
  • bridge_ports regex eth* # use a regular expression to define ports
# 生效
systemctl restart networking
# 清除原有接口ip
ip add flush dev eno1

/etc/netplan/01-netcfg.yaml
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  # general interface
  ethernets:
    eno1:
      dhcp4: no
      dhcp6: no
    eno3:
      dhcp4: no
      dhcp6: no
  # bridges
  bridges:
    br1:
      interfaces: [eno1]
      dhcp4: no
      dhcp6: no
      addresses: [172.17.1.2/24]
      gateway4: 172.17.1.254
      nameservers:
        addresses: [10.1.1.254]
      parameters:
        stp: false
    br2:
      interfaces: [vlan2]
      dhcp4: no
      dhcp6: no
      parameters:
        stp: false
    br3:
      interfaces: [vlan3]
      dhcp4: no
      dhcp6: no
      parameters:
        stp: false
    brdmz:
      interfaces: [eno3]
      dhcp4: no
      dhcp6: no
      parameters:
        stp: false
    br100:
      interfaces: []
      dhcp4: no
      dhcp6: no
      parameters:
        stp: false
    br101:
      interfaces: []
      dhcp4: no
      dhcp6: no
      parameters:
        stp: false
  # vlans
  vlans:
    vlan2:
      id: 2
      link: eno1
      dhcp4: no
      dhcp6: no
    vlan3:
      id: 3
      link: eno1
      dhcp4: no
      dhcp6: no

安装必要的包:

yum install bridge-utils -y
modprobe 8021q
lsmod | grep 8021q

4.1 网卡配置文件

配置parent interface ifcfg-em1:

DEVICE=em1
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
BRIDGE=br1
MTU=9000

配置子接口(VLAN 2) ifcfg-em1.2:

DEVICE=em1.2
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
VLAN=yes
BRIDGE=br2
MTU=9000

配置ifcfg-br1:

DEVICE=br1
TYPE=Bridge
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
IPADDR=172.17.1.2
PREFIX=24
GATEWAY=172.17.1.254
DNS1=10.1.1.254
MTU=9000

配置ifcfg-br2:

DEVICE=br2
TYPE=Bridge
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
MTU=9000

重启生效:

systemctl restart network
  • linux/others/bridge_vlan.txt
  • 最后更改: 2019/08/30 11:33
  • 由 mrco