centos7.x网卡bond配置

时间:2024-04-13 08:08:24

本文摘抄自 https://www.cnblogs.com/liwanggui/p/6807212.html

centos7网卡bond配置

实验环境

[root@localhost ~]# cat /etc/redhat-release
CentOSLinux release 7.2.1511(Core)
[root@localhost ~]# uname -r
3.10.0-327.el7.x86_64

linux服务器 eno33554960 与 eno50332184 两张网卡配置 bond 步骤(如果要配置多个bond0,1…按照这个流程重复操作即可)参考

查看网卡信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~]# ip addr
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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: eno16777736:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:07:2c:86 brd ff:ff:ff:ff:ff:ff
inet 192.168.92.11/24 brd 192.168.92.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe07:2c86/64 scope link
valid_lft forever preferred_lft forever
3: eno33554960:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:07:2c:90 brd ff:ff:ff:ff:ff:ff
4: eno50332184:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:07:2c:9a brd ff:ff:ff:ff:ff:ff

  

1 备份网卡配置文件

1
2
3
4
5
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# mkdir /tmp/net_bak
[root@localhost network-scripts]# cp ifcfg-*/tmp/net_bak/
[root@localhost network-scripts]# ls /tmp/net_bak/
ifcfg-eno16777736 ifcfg-eno33554960 ifcfg-eno50332184 ifcfg-eno67109408 ifcfg-eno83886632 ifcfg-lo

  

2 使用nmcli命令配置bond

1
2
3
4
5
6
7
8
# 生成bond配置文件
[root@localhost network-scripts]# nmcli connection add type bond ifname bond0 mode 0
# 将网卡`eno33554960`与`eno50332184`绑定到bond0
[root@localhost network-scripts]# nmcli connection add type bond-slave ifname eno33554960 master bond0
[root@localhost network-scripts]# nmcli connection add type bond-slave ifname eno50332184 master bond0
# 查看生成的配置文件
[root@localhost network-scripts]# ls ifcfg-bond-*
ifcfg-bond-bond0 ifcfg-bond-slave-eno33554960 ifcfg-bond-slave-eno50332184

bond的mode如下:

  • balance-rr (0) –轮询模式,负载均衡(bond默认的模式)
  • active-backup (1) –主备模式(常用)
  • balance-xor (2)
  • broadcast (3)
  • 802.3ad (4) –聚合模式
  • balance-tlb (5)
  • balance-alb (6)

3 修改bond0网卡配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@localhost network-scripts]# vim ifcfg-bond-bond0
DEVICE=bond0
BONDING_OPTS=mode=active-backup
TYPE=Bond
BONDING_MASTER=yes
BOOTPROTO=static====>将 dhcp 改为static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=bond-bond0
UUID=af2d6662-608c-4f5d-8018-1984cc3d87ef
ONBOOT=yes
IPADDR=192.168.92.20# 配置 IP 地址
PREFIX=24# 配置掩码 也可以使用 NETMASK=255.255.255.0
GATEWAY=192.168.92.2# 配置网关

  

Tips: 如果不想修改bond网络接口配置文件可以在第2步的第一条命令后加上 ip4 "ip地址" gw4 "网关地址"

nmcli connection add type bond ifname bond0 mode 1 ip4 192.168.92.20/24 gw4 192.168.92.2

4 重启网络,验证配置结果

1. 查看网卡信息

centos7.x网卡bond配置
[root@localhost network-scripts]# ip addr show
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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: eno16777736:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:07:2c:86 brd ff:ff:ff:ff:ff:ff
inet 192.168.92.11/24 brd 192.168.92.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe07:2c86/64 scope link
valid_lft forever preferred_lft forever
3: eno33554960:<BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether 00:0c:29:07:2c:90 brd ff:ff:ff:ff:ff:ff
4: eno50332184:<BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether 00:0c:29:07:2c:90 brd ff:ff:ff:ff:ff:ff
31: bond0:<BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 00:0c:29:07:2c:90 brd ff:ff:ff:ff:ff:ff
inet 192.168.92.20/24 brd 192.168.92.255 scope global bond0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe07:2c90/64 scope link
valid_lft forever preferred_lft forever
centos7.x网卡bond配置

2. 查看bond信息

centos7.x网卡bond配置
[root@localhost network-scripts]# cat /proc/net/bonding/bond0
EthernetChannelBondingDriver: v3.7.1(April27,2011)
BondingMode: fault-tolerance (active-backup)===> bond主备模式
PrimarySlave:None
CurrentlyActiveSlave: eno33554960 ===>当前激活的网卡eno33554960
MII Status: up
MII PollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0
SlaveInterface: eno33554960 ===> bond0 组内的网卡
MII Status: up
Speed:1000Mbps
Duplex: full
LinkFailureCount:0
Permanent HW addr:00:0c:29:07:2c:90
Slave queue ID:0
SlaveInterface: eno50332184 ===> bond0 组内的网卡
MII Status: up
Speed:1000Mbps
Duplex: full
LinkFailureCount:0
Permanent HW addr:00:0c:29:07:2c:9a
Slave queue ID:0
centos7.x网卡bond配置

5 删除 bond 设备

当我们需要删除bond设备的时候,该如何删除呢?请看下面操作

1.查看网络设备

[root@localhost ~]# ls /sys/class/net/
bond0 bond1 bonding_masters eno16777736 eno33554960 eno50332184 eno67109408 eno83886632 lo

2.删除bond网络设备

直接删除bond0,会提示无权限。 
可以通过bonding_masters文件删除bond设备,但是bonding_masters文件是无法直接修改的。

[root@localhost ~]# echo -bond0 >/sys/class/net/bonding_masters

echo 后面的 ‘-’ 是删除设备,‘+’是增加设备