适用场景

服务器两张网卡需要做bond,并且bond后网卡需配置不同网段的地址,用于走不同流量,这个时候就可以采用起子接口的方式。

实验场景

  • 设备

    • 服务器:Server_A
    • 核心交换机:Switch_A、Switch_B
  • 交换机连接方式:堆叠
  • 服务器网卡:enp176s0f0、enp176s0f1做bond
  • IP段划分
    • 业务段

      • VLAN 201:10.10.51.0/24
    • 公网
      • VLAN 401:111.20.200.88/27
  • 要求

    服务器Server_A上联的两台核心交换机Switch_A和Switch_B采用堆叠方式,Server_A的enp176s0f0和enp176s0f1光口分别互联Switch_A和Switch_B;现要求enp176s0f0和enp176s0f1做bond,地址10.10.51.16走业务流量,地址111.20.200.90走公网流量,交换机端口做捆绑eth-trunk并透传VLAN201和VLAN401。

网卡配置脚本

# 停掉NetworkManager服务
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service # 备份
cp /etc/sysconfig/network-scripts/ifcfg-enp176s0f0{,.bak}
cp /etc/sysconfig/network-scripts/ifcfg-enp176s0f1{,.bak} # 将网卡协议改为none并设备未开机自启动,并做双网卡配置
sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=none/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f0
sed -i 's/ONBOOT=no/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f0
echo "MASTER=bond0" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f0
echo "SLAVE=yes" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f0 sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=none/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f1
sed -i 's/ONBOOT=no/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f1
echo "MASTER=bond0" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f1
echo "SLAVE=yes" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f1 # 配置网卡bond0
echo "DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static" >/etc/sysconfig/network-scripts/ifcfg-bond0 # 写模块文件,bond模式为mode 0
echo "alias bond0 bonding
options bond0 miimon=100 mode=0" >/etc/modprobe.d/bond.conf
# 加载模块
modprobe bonding # 起子接口bond0.201
echo "DEVICE=bond0.201
TYPE=Vlan
PHYSDEV=bond0
ONBOOT=yes
BOOTPROTO=static
REORDER_HDR=yes
IPADDR=10.10.51.16
GATEWAY=10.10.51.1
NETMASK=255.255.255.0
DNS1=114.114.114.114
DNS2=8.8.8.8
VLAN=yes
VLAN_ID=201" >/etc/sysconfig/network-scripts/ifcfg-bond0.201 # 起子接口bond0.401
echo "DEVICE=bond0.401
TYPE=Vlan
PHYSDEV=bond0
ONBOOT=yes
BOOTPROTO=static
REORDER_HDR=yes
IPADDR=111.20.200.90
GATEWAY=111.20.200.89
NETMASK=255.255.255.0
DNS1=114.114.114.114
DNS2=8.8.8.8
VLAN=yes
VLAN_ID=401" >/etc/sysconfig/network-scripts/ifcfg-bond0.401 # 加载模块并重启主机
modprobe 8021q
reboot

关键点

  • 交换机侧如果起eth-trunk,那么服务器侧则必须起子接口
  • 交换机侧和服务器侧要么都起lacp协商,要么都不起,否则将造成端口不同
    • 交换机侧eth-trunk口配置示例
      [HH2B108-H01-2-HW9006X-SW001-Eth-Trunk12]display this
      #
      interface Eth-Trunk12
      port link-type trunk
      port trunk allow-pass vlan 201 401
      #
      return
    • 服务器侧起lacp协议使用bond模式4,示例如下
       # more /etc/modprobe.d/bond.conf
      alias bond0 bonding
      options bond0 miimon=100 mode=4 lacp_rate=1
  • 子接口配置文件中"DEVICE=bond0.401“中的VLAN号一定要和需要透传的VLAN号保持一致
  • 配置子接口后一定要重启服务器才能生效!!!
05-19 15:06