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

相关内容

热门资讯

安卓共有多少种系统,究竟有多少... 你有没有想过,安卓这个我们每天不离手的操作系统,竟然有那么多不同的版本呢?没错,安卓系统就像一个大家...
安卓系统怎么播放swf,And... 你有没有遇到过这种情况:手里拿着一部安卓手机,想看一个SWF格式的动画,结果发现怎么也打不开?别急,...
pos机安卓系统跟win系统,... 你有没有想过,那些在我们生活中默默无闻的POS机,竟然也有自己的操作系统呢?没错,就是安卓系统和Wi...
俄罗斯封禁安卓系统,本土化替代... 俄罗斯封禁安卓系统的背后:技术、经济与社会的影响在数字化浪潮席卷全球的今天,智能手机已成为我们生活中...
安卓系统总是弹出权限,安卓系统... 手机里的安卓系统是不是总爱和你玩捉迷藏?每次打开一个应用,它就跳出来问你要不要给它开权限,真是让人又...
安卓系统测血氧,便捷健康生活新... 你知道吗?现在科技的发展真是让人惊叹不已!手机,这个我们日常生活中不可或缺的小玩意儿,竟然也能变身成...
蓝光助手安卓系统的,深度解析与... 你有没有发现,现在手机屏幕越来越大,看视频、刷抖音,简直爽到飞起!但是,你知道吗?长时间盯着屏幕,尤...
安卓系统如何隐藏提示,Andr... 你是不是也和我一样,在使用安卓手机的时候,总是被那些弹出来的提示信息打扰到?别急,今天就来教你怎么巧...
安卓6.0系统如何分区,And... 你有没有想过,你的安卓手机里那些神秘的分区到底是怎么来的?别急,今天就来给你揭秘安卓6.0系统如何分...
安卓系统图片怎么涂鸦,指尖上的... 你有没有想过,在安卓系统的手机上,那些单调的图片也能变得生动有趣呢?没错,就是涂鸦!今天,就让我来带...
安卓系统40g,40GB存储空... 你有没有发现,最近你的安卓手机突然变得有点“胖”了呢?没错,就是那个传说中的40G!别急,别慌,今天...
安卓5.0系统怎么重置,轻松实... 手机用久了是不是感觉卡得要命?别急,今天就来教你怎么给安卓5.0系统来个彻底的重置,让它焕发新生!一...
安卓系统是不是快要,安卓系统即... 你有没有发现,最近安卓系统好像有点儿“不安分”了呢?是不是快要发生什么大事情?咱们一起来探个究竟吧!...
安卓6系统和8系统差别,全面对... 你有没有发现,手机更新换代的速度简直就像坐上了火箭呢?这不,安卓系统也跟着时代的步伐,从6系统一路升...
安卓11系统推荐下载,体验全新... 你有没有发现,最近手机界又掀起了一股热潮?没错,就是安卓11系统!这款全新的操作系统一经推出,就吸引...
原生安卓系统怎样升级,从基础到... 你有没有发现,你的安卓手机用久了,有时候就像老牛拉车一样,慢吞吞的?别急,今天就来给你支个招,让你的...
安卓13系统怎么开发,开发者的... 你有没有听说安卓13系统已经发布了?这可是个大新闻呢!作为一个热衷于手机开发的小伙伴,你是不是也跃跃...
安卓q系统镜像下载,轻松升级体... 你有没有听说安卓Q系统已经发布了?这可是安卓家族里的一大亮点呢!今天,我就要来给你详细介绍一下安卓Q...
安卓系统色彩校正软件,打造个性... 你有没有发现,手机屏幕的色彩有时候会让人感觉不太对劲?有时候,画面看起来有点灰蒙蒙的,有时候又太艳丽...
苹果能否下个安卓系统,开启新篇... 你有没有想过,苹果的iOS系统会不会有一天突然宣布,它要拥抱安卓的大家庭呢?想象iPhone和iPa...