Linux系统之Bonding 网卡绑定配置方法
创始人
2024-05-14 20:42:38
0

Linux系统之Bonding 网卡绑定配置方法

  • 一、检查本地系统环境
    • 1.检查系统版本
    • 2.查看服务器网卡
  • 二、创建网卡配置文件
    • 1.进入网卡配置文件目录
    • 2.拷贝eth0的网卡配置文件
    • 3.修改bond0网卡配置文件
    • 4.修改eth1网卡配置文件
    • 5.修改eth2网卡配置文件
  • 三、创建bonding的配置文件
    • 1.编辑bonding.conf
    • 2.停止 NetworkManager 服务
    • 3.加载 bonding 模块
    • 4.重启网络服务
  • 四、查看网卡绑定情况
    • 1.再次检查本地网卡
    • 2.查看网卡绑定状态
  • 五、测试网卡连通情况
    • 1.本地客户端ping服务器
  • 六、关闭eth1网卡测试连通情况
    • 1.关闭eth1网卡
    • 2.查看本地客户端连通情况
    • 3.查看当前的bond0状态
  • 七、关闭eth2网卡测试连通情况
    • 1.开启eth1网卡,关闭eth2网卡
    • 2.测试本地客户端连通情况
    • 3.查看当前的bond0状态

一、检查本地系统环境

1.检查系统版本

[root@Server001 ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

2.查看服务器网卡

[root@Server001 network-scripts]# ifconfig  -a
bond0: flags=5123  mtu 1500inet 192.168.30.122  netmask 255.255.255.0  broadcast 192.168.30.255ether a6:ad:e5:84:f0:6e  txqueuelen 1000  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0eth0: flags=4163  mtu 1500inet 192.168.3.55  netmask 255.255.255.0  broadcast 192.168.3.255inet6 fe80::2a6e:d4ff:fe89:8720  prefixlen 64  scopeid 0x20ether 28:6e:d4:89:87:20  txqueuelen 1000  (Ethernet)RX packets 2256  bytes 439140 (428.8 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 428  bytes 68770 (67.1 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0eth1: flags=4163  mtu 1500inet6 fe80::2a6e:d4ff:fe8a:3299  prefixlen 64  scopeid 0x20ether 28:6e:d4:8a:32:99  txqueuelen 1000  (Ethernet)RX packets 1617  bytes 386452 (377.3 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 7  bytes 586 (586.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0eth2: flags=4163  mtu 1500inet6 fe80::2a6e:d4ff:fe88:f490  prefixlen 64  scopeid 0x20ether 28:6e:d4:88:f4:90  txqueuelen 1000  (Ethernet)RX packets 1617  bytes 386452 (377.3 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 7  bytes 586 (586.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10loop  txqueuelen 1000  (Local Loopback)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

二、创建网卡配置文件

1.进入网卡配置文件目录

[root@Server001 ~]# cd /etc/sysconfig/network-scripts/
[root@Server001 network-scripts]# ls
ifcfg-bond0  ifdown-eth   ifdown-ppp       ifdown-tunnel  ifup-ippp   ifup-post    ifup-TeamPort      network-functions-ipv6
ifcfg-eth0   ifdown-ippp  ifdown-routes    ifup           ifup-ipv6   ifup-ppp     ifup-tunnel
ifcfg-lo     ifdown-ipv6  ifdown-sit       ifup-aliases   ifup-isdn   ifup-routes  ifup-wireless
ifdown       ifdown-isdn  ifdown-Team      ifup-bnep      ifup-plip   ifup-sit     init.ipv6-global
ifdown-bnep  ifdown-post  ifdown-TeamPort  ifup-eth       ifup-plusb  ifup-Team    network-functions

2.拷贝eth0的网卡配置文件

[root@Server001 network-scripts]# cp ifcfg-eth0 ifcfg-eth1
[root@Server001 network-scripts]# cp ifcfg-eth0 ifcfg-eth2
[root@Server001 network-scripts]# cp ifcfg-eth0 ifcfg-bond0

3.修改bond0网卡配置文件

[root@Server001 network-scripts]# cat ifcfg-bond0 
DEVICE=bond0
BOOTPROTO=none
TYPE=bond0
ONBOOT=yes
IPADDR=192.168.30.122
NETMASK=255.255.255.0

4.修改eth1网卡配置文件

[root@Server001 network-scripts]# cat ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
TYPE=Ethernet
MASTER=bond0
SLAVE=yes

5.修改eth2网卡配置文件

[root@Server001 network-scripts]# cat ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
TYPE=Ethernet
MASTER=bond0
SLAVE=yes

三、创建bonding的配置文件

1.编辑bonding.conf

[root@node network-scripts]# vim /etc/modprobe.d/bonding.conf
[root@node network-scripts]# cat /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bonding mode=1 miimon=100

注:关于mode的说明
mode=0 //平衡循环
mode=1 //主备
mode=3 //广播
mode=4 //链路聚合

2.停止 NetworkManager 服务

systemctl stop NetworkManager
systemctl disable NetworkManage

3.加载 bonding 模块

[root@Server001 network-scripts]# lsmod |grep bonding
[root@Server001 network-scripts]#  modprobe bonding
[root@Server001 network-scripts]#  lsmod |grep bonding
bonding               152656  0 

4.重启网络服务

systemctl restart network

四、查看网卡绑定情况

1.再次检查本地网卡

[root@Server001 network-scripts]# ifconfig 
bond0: flags=5187  mtu 1500inet 192.168.30.122  netmask 255.255.255.0  broadcast 192.168.30.255inet6 fe80::2a6e:d4ff:fe8a:3299  prefixlen 64  scopeid 0x20ether 28:6e:d4:8a:32:99  txqueuelen 1000  (Ethernet)RX packets 2426  bytes 748394 (730.8 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 13  bytes 838 (838.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0eth0: flags=4163  mtu 1500inet 192.168.3.55  netmask 255.255.255.0  broadcast 192.168.3.255inet6 fe80::2a6e:d4ff:fe89:8720  prefixlen 64  scopeid 0x20ether 28:6e:d4:89:87:20  txqueuelen 1000  (Ethernet)RX packets 2853  bytes 740694 (723.3 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 478  bytes 75189 (73.4 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0eth1: flags=6211  mtu 1500ether 28:6e:d4:8a:32:99  txqueuelen 1000  (Ethernet)RX packets 2229  bytes 689858 (673.6 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 13  bytes 838 (838.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0eth2: flags=6211  mtu 1500ether 28:6e:d4:8a:32:99  txqueuelen 1000  (Ethernet)RX packets 2243  bytes 690766 (674.5 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10loop  txqueuelen 1000  (Local Loopback)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.查看网卡绑定状态

[root@Server001 network-scripts]# cat  /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: eth1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 28:6e:d4:8a:32:99
Slave queue ID: 0Slave Interface: eth2
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 28:6e:d4:88:f4:90
Slave queue ID: 0

五、测试网卡连通情况

1.本地客户端ping服务器

ping 192.168.30.122

image.png

六、关闭eth1网卡测试连通情况

1.关闭eth1网卡

[root@Server001 network-scripts]# ifdown eth1
[root@Server001 network-scripts]# 

2.查看本地客户端连通情况

可以正常ping通
image.png

3.查看当前的bond0状态

当前活动网卡已经切换到eth2,eth2网卡提供服务

[root@Server001 network-scripts]# cat  /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: eth2
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 28:6e:d4:88:f4:90
Slave queue ID: 0

七、关闭eth2网卡测试连通情况

1.开启eth1网卡,关闭eth2网卡

[root@Server001 network-scripts]# ifup eth1
[root@Server001 network-scripts]# ifdown eth2

2.测试本地客户端连通情况

可以正常ping通

image.png

3.查看当前的bond0状态

当前活动网卡已经切换到eth1,eth1网卡提供服务

[root@Server001 network-scripts]# cat  /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: eth1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 28:6e:d4:8a:32:99
Slave queue ID: 0

相关内容

热门资讯

安卓系统计划软件推荐,精选计划... 你有没有发现,手机里的安卓系统越来越智能了?这不,最近我可是挖到了一些超棒的安卓计划软件,它们不仅能...
收钱吧安卓系统插件,便捷支付新... 你有没有发现,现在的生活越来越离不开手机了?手机里装满了各种应用,而今天我要跟你聊聊一个特别实用的工...
鸿蒙系统是否还属于安卓,独立于... 你有没有想过,那个在我们手机上默默无闻的鸿蒙系统,它到底是不是安卓的“亲戚”呢?这个问题,估计不少手...
安卓系统手机用什么钱包,轻松管... 你有没有想过,你的安卓系统手机里装了那么多应用,但最离不开的,可能就是那个小小的钱包了。没错,就是那...
安卓系统能玩部落冲突吗,部落冲... 你有没有想过,安卓系统上的手机,是不是也能玩那款风靡全球的《部落冲突》呢?这款游戏自从推出以来,就吸...
智能机器人安卓系统,引领未来智... 你知道吗?在科技飞速发展的今天,智能机器人已经不再是科幻电影里的专属了。它们正悄悄地走进我们的生活,...
华为win10系统改装安卓系统... 你有没有想过,你的华为笔记本电脑里的Windows 10系统,能不能来个华丽变身,变成安卓系统呢?这...
旧电脑上安什么安卓系统,适配不... 你那台旧电脑是不是已经闲置好久了?别让它默默无闻地躺在角落里,给它来个华丽变身吧!今天,就让我来告诉...
安卓app语言跟随系统,随系统... 你知道吗?在手机世界里,有一个神奇的小功能,它就像你的贴身翻译官,无论你走到哪里,都能帮你轻松应对各...
惠城安卓系统降级在哪,揭秘降级... 你有没有遇到过手机系统升级后,发现新系统让你头疼不已,想回到那个熟悉的安卓系统呢?别急,今天就来告诉...
阿里云系统转安卓,揭秘安卓平台... 你知道吗?最近有个大动作在互联网圈里引起了不小的波澜,那就是阿里云系统竟然要转战安卓阵营了!这可不是...
安卓系统有最美壁纸么,探寻最美... 哦,亲爱的安卓用户,你是否曾在某个午后,百无聊赖地翻看着手机,突然被那一张张壁纸惊艳了眼眸?是的,我...
安卓系统采用Linux操作系统... 你知道吗?安卓系统,这个在我们手机上无处不在的小家伙,它的心脏竟然是Linux操作系统内核!是不是觉...
安卓原生平板通用系统,探索安卓... 你有没有发现,现在市面上平板电脑的品牌和型号真是五花八门,让人挑花了眼?不过,你知道吗?在众多安卓平...
小米1系统是安卓几,搭载安卓几... 你有没有想过,你的小米手机里那个熟悉的系统,其实是基于安卓的哦!没错,就是那个全球最流行的手机操作系...
可以安装安卓系统的相机,智能摄... 你有没有想过,一台相机不仅能拍出美美的照片,还能像智能手机一样,玩转各种应用?没错,现在市面上就有这...
安卓系统gps定位不准,安卓G... 你是不是也遇到过这种情况?手机里的安卓系统GPS定位总是不准,让人头疼不已。有时候,你明明就在家附近...
电信机顶盒装安卓系统,开启智能... 你有没有想过,家里的电信机顶盒其实也可以装上安卓系统呢?听起来是不是有点不可思议?别急,让我带你一步...
安卓系统可以做苹果桌面,打造个... 你知道吗?现在科技的发展真是让人眼花缭乱,竟然有人想出了安卓系统可以做苹果桌面的神奇想法!是不是觉得...
安卓系统自带的网页,功能与特色... 你有没有发现,每次打开安卓手机,那熟悉的系统界面里总有一个默默无闻的小家伙——安卓系统自带的网页浏览...