Ubuntu16.04 雙網卡綁定
環境 : 系統: Ubuntu16.04
網卡: em1 em2
ip:192.168.0.46
安裝 ifenslave :
sudo apt-get install ifenslave
echo "bonding" >>/etc/modules
auto bond0
iface bond0 inet static
address 192.168.0.46
netmask 255.255.255.0
gateway 192.168.0.1
bond-slaves none
bond-mode active-backup
bond-miimon 100
auto eno1
iface eno1 inet manual
bond-master bond0
bond-primary eno1 eno2
auto eno2
iface eno2 inet manual
bond-master bond0
bond-primary eno1 eno2
Ubuntu18.04 靜態網卡配置
Ubuntu 18.04 採用netplan作為網絡配置管理,與16.04及之前的版本區別很大
IP配置
sudo vi /etc/netplan/01-netcfg.yaml #最後的名字因服務器而異。
重啟網卡
sudo netplan apply
DNS配置
DNS還是使用resolv.conf
sudo vi /etc/resolv.conf
ubuntu18.04雙網卡綁定
vim /etc/netpan/50-cloud-init.yaml
network:
ethernets:
ens33:
addresses: []
dhcp4: no
dhcp6: no
optional: true
ens38:
addresses: []
dhcp4: no
dhcp6: no
optional: true
bonds:
bond0:
addresses: [192.168.98.112/24]
gateway4: 192.168.98.1
nameservers:
addresses: [114.114.114.114,8.8.8.8]
interfaces:
- ens33
- ens38
version: 2
重啟網卡 netplan apply
查看bond狀態
watch -n 1 ifconfig bond0
watch -n 1 ifconfig ens33
watch -n 1 ifconfig ens38
** Intel Corporation Ethernet Controller X710/X557-AT 10GBASE-T 設定
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s31f6:
dhcp4: true
enp2s0f0:
dhcp4: no
enp2s0f1:
dhcp4: no
enp2s0f2:
dhcp4: no
enp2s0f3:
dhcp4: no
bonds:
bond0:
addresses: [10.10.8.22/24]
gateway4: 10.10.8.254
nameservers:
addresses: [10.10.0.9,10.10.0.10]
mtu: 9000
interfaces:
- enp2s0f0
- enp2s0f1
- enp2s0f2
- enp2s0f3
parameters:
lacp-rate: fast
mode: balance-alb
transmit-hash-policy: layer2
version: 2
~
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s31f6:
dhcp4: true
enp2s0f0:
dhcp4: no
enp2s0f1:
dhcp4: no
enp2s0f2:
dhcp4: no
enp2s0f3:
dhcp4: no
bonds:
bond0:
addresses: [10.10.8.22/24]
gateway4: 10.10.8.254
nameservers:
addresses: [10.10.0.9,10.10.0.10]
mtu: 9000
interfaces:
- enp2s0f0
- enp2s0f1
- enp2s0f2
- enp2s0f3
parameters:
lacp-rate: fast
mode: balance-alb
transmit-hash-policy: layer2
version: 2
~
PS. [10.10.8.22/24] 後面 /24
意思就是指 SubnetMASK 有 24 個 「1」,就等於 255.255.255.0
若是 /22,則是 255.255.252.0 (22個 1= 11111111.11111111.11111100.00000000)
# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: adaptive load balancing
Primary Slave: None
Currently Active Slave: enp2s0f3
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0
Slave Interface: enp2s0f3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 3c:fd:fe:69:29:cb
Slave queue ID: 0
Slave Interface: enp2s0f2
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 3c:fd:fe:69:29:ca
Slave queue ID: 0
Slave Interface: enp2s0f1
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 3c:fd:fe:69:29:c9
Slave queue ID: 0
Slave Interface: enp2s0f0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 3c:fd:fe:69:29:c8
Slave queue ID: 0
1、Bond的工作模式
Linux bonding驅動提供了一個把多個網絡接口設備捆綁為單個的網絡接口設置來使用,用於網絡負載均衡及網絡冗余。
bonding一共有7種工作模式(mode):
- 1)、bond=0,(balance-rr) Round-robin policy: (平衡輪詢策略):傳輸數據包順序是依次傳輸,直到最後一個傳輸完畢,此模式提供負載平衡和容錯能力。
- 2)、bond=1,(active-backup) Active-backup policy:(活動備份策略):只有一個設備處於活動狀態。一個宕掉另一個馬上由備份轉換為主設備。mac地址是外部可見得。此模式提供了容錯能力。
- 3)、bond=2,(balance-xor) XOR policy:(平衡策略):傳輸根據[(源MAC地址xor目標MAC地址)mod設備數量]的布爾值選擇傳輸設備。 此模式提供負載平衡和容錯能力。
- 4)、bond=3,(broadcast) Broadcast policy:(廣播策略):將所有數據包傳輸給所有設備。此模式提供了容錯能力。
- 5)、bond=4,(802.3ad) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad 動態鏈接聚合:創建共享相同的速度和雙工設置的聚合組。此模式提供了容錯能力。每個設備需要基於驅動的重新獲取速度和全雙工支持;如果使用交換機,交換機也需啟用 802.3ad 模式。
- 6)、bond=5,(balance-tlb) Adaptive transmit load balancing(適配器傳輸負載均衡):通道綁定不需要專用的交換機支持。發出的流量根據當前負載分給每一個設備。由當前設備處理接收,如果接受的設 備傳不通就用另一個設備接管當前設備正在處理的mac地址。
- 7)、bond=6,(balance-alb) Adaptive load balancing: (適配器負載均衡):包括mode5,由 ARP 協商完成接收的負載。bonding驅動程序截獲 ARP在本地系統發送出的請求,用其中之一的硬件地址覆蓋從屬設備的原地址。就像是在服務器上不同的人使用不同的硬件地址一樣。
** 使用 ethtool 了解速度
# ethtool bond0
Settings for bond0:
Supported ports: [ ]
Supported link modes: Not reported
Supported pause frame use: No
Supports auto-negotiation: No
Supported FEC modes: Not reported
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Advertised FEC modes: Not reported
Speed: 2000Mb/s
Duplex: Full
Port: Other
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
Link detected: yes
沒有留言:
張貼留言