舒泽文 發表於 2021-1-22 15:28:00

Debian 16.04 配置双网卡绑定bond

<h2 id="debian-1604-配置双网卡绑定bond">Debian 16.04 配置双网卡绑定bond</h2>
<h3 id="debian-1604-bonding多网卡配置">Debian 16.04 bonding多网卡配置</h3>
<ol>
<li>安装负载均衡软件 <strong>fenslave</strong></li>
</ol>
<pre><code>root@ubuntu:~# apt-get install ifenslave
root@ubuntu:~# dpkg -l | grep ifenslave
iiifenslave                           2.7ubuntu1                                    all          configure network interfaces for parallel routing (bonding)
</code></pre>
<ol start="2">
<li>添加 <strong>bonding</strong> 模块,使之可以开机自动加载该模块</li>
</ol>
<pre><code>root@ubuntu:~# echo "bonding" &gt;&gt; /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
</code></pre>
<ul>
<li>接着可以手动加载绑定内核模块,也可以重启</li>
</ul>
<pre><code>root@ubuntu:~# modprobe bonding
root@ubuntu:~# lsmod | grep bonding
bonding
</code></pre>
<ol start="3">
<li>编辑 <strong>/etc/network/interfaces</strong> 配置文件</li>
</ol>
<ul>
<li>设置主备模式 (<strong>active-backup</strong>)</li>
</ul>
<pre><code>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毫秒监测一次网卡状态,如果有一条线路不通就切换另一条线路
</code></pre>
<ul>
<li>设置负载均衡模式 (<strong>balace-rr</strong>)</li>
</ul>
<pre><code>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
</code></pre>
<ol start="4">
<li>重启网络服务</li>
</ol>
<pre><code>root@ubuntu:~# systemctl restart networking
</code></pre>
<ol start="5">
<li>查看bond</li>
</ol>
<pre><code>root@ubuntu:~# ip add
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; 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: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; 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: &lt;BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP&gt; 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: &lt;BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP&gt; 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: &lt;BROADCAST,MULTICAST,MASTER,UP,LOWER_UP&gt; 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
</code></pre><br><br>
来源:https://www.cnblogs.com/itwangqiang/p/14313584.html
頁: [1]
查看完整版本: Debian 16.04 配置双网卡绑定bond