centos7网卡配置bond

来源:yaho 发布时间:2024-01-31 14:25:37 点击数: 2

1.实验环境

[root@localhost ~]# cat /etc/redhat-releaseCentOSLinux release 7.2.1511(Core)[root@localhost ~]# uname -r3.10.0-327.el7.x86_64

2.查看网卡信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~]# ip a
o: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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:em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 0c:0b:23:07:2d:87 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: em2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 0c:24:29:0b:2c:c0 brd ff:ff:ff:ff:ff:ff
4: em3: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
link/ether 0c:00:29:07:9c:ca brd ff:ff:ff:ff:ff:ff

3.备份网卡配置文件

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-em1 ifcfg-em2 ifcfg-em3  ifcfg-lo

4.使用nmcli命令配置bond


1
2
3
4
5
6
7
8
# 生成bond配置文件
[root@localhost network-scripts]# nmcli connection add type bond ifname bond0 mode 1
# 将网卡`em3`与`em4`绑定到bond0
[root@localhost network-scripts]# nmcli connection add type bond-slave ifname em2 master bond0
[root@localhost network-scripts]# nmcli connection add type bond-slave ifname em3 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)

5.修改bond0网卡配置

[root@localhost network-scripts]# vim ifcfg-bond-bond0
DEVICE=bond0
BONDING_OPTS=mode=active-backup   ====>需要不同模式可以将 active-backup 改为其他如balance-rr
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# 配置网关


如果不想修改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

6.重启网络,验证配置结果即可