Linux雙網絡卡bond、起子介面
阿新 • • 發佈:2018-11-06
適用場景
伺服器兩張網絡卡需要做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號保持一致
- 配置子介面後一定要重啟伺服器才能生效!!!