Debian 16.04 配置雙網卡綁定bond


Debian 16.04 配置雙網卡綁定bond

Debian 16.04 bonding多網卡配置

  1. 安裝負載均衡軟件 fenslave
root@ubuntu:~# apt-get install ifenslave
root@ubuntu:~# dpkg -l | grep ifenslave
ii  ifenslave                             2.7ubuntu1                                      all          configure network interfaces for parallel routing (bonding)
  1. 添加 bonding 模塊,使之可以開機自動加載該模塊
root@ubuntu:~# echo "bonding" >> /etc/modules
root@ubuntu:~# cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
bonding
  • 接着可以手動加載綁定內核模塊,也可以重啟
root@ubuntu:~# modprobe bonding
root@ubuntu:~# lsmod | grep bonding
bonding 
  1. 編輯 /etc/network/interfaces 配置文件
  • 設置主備模式 (active-backup
root@ubuntu:~# vim /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

# The primary network interface

auto eth0                        #該網卡使用來遠程使用的
iface eth0 inet static
        address 192.168.121.16
        netmask 255.255.255.0
        gateway 192.168.121.2

auto eth1                    #綁定的網卡eth1
iface eth1 inet manual       #最好設置為手動,設置為static可能會出問題
        bond-master bond0    #綁定的接口
        bond-primary eth1    #表示該網卡是主網卡,有流浪優先走該網卡

auto eth2                    #綁定的網卡eth2
iface eth2 inet manual
        bond-master bond0    #綁定的接口

auto bond0                   #綁定網卡名
iface bond0 inet static
        address 192.168.121.100
        netmask 255.255.255.0
        gateway 192.168.121.2
        bond-slaves none       #主備模式,沒有從屬網卡
        bond-mode 1            #1代表主備模式active-backup
        bond-miimon 200        #200毫秒監測一次網卡狀態,如果有一條線路不通就切換另一條線路
  • 設置負載均衡模式 (balace-rr)
root@ubuntu:~# vim /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

# The primary network interface

auto eth0
iface eth0 inet static
        address 192.168.121.16
        netmask 255.255.255.0
        gateway 192.168.121.2

auto eth1
iface eth1 inet manual
        bond-master bond0

auto eth2
iface eth2 inet manual
        bond-master bond0

auto bond0
iface bond0 inet static
        address 192.168.121.100
        netmask 255.255.255.0
        gateway 192.168.121.2
        bond-slaves eth1 eth2        #添加兩個從屬網卡
        bond-mode 0         #0表示負載均衡模式
        bond-miimon 200
  1. 重啟網絡服務
root@ubuntu:~# systemctl restart networking
  1. 查看bond
root@ubuntu:~# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:57:67:25 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.16/24 brd 192.168.121.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe57:6725/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
    link/ether 00:0c:29:57:67:39 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
    link/ether 00:0c:29:57:67:39 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:57:67:39 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.100/24 brd 192.168.121.255 scope global bond0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe57:6739/64 scope link tentative dadfailed 
       valid_lft forever preferred_lft forever


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM