网卡绑定使两个或多个网络接口能够充当一个接口,同时增大带宽并提供冗余。

active-backup、balance-tlb 和 balance-alb 模式不需要对交换机进行任何具体的配 置。其他绑定模式需要配置交换机来聚合链接。

最新的操作系统可以通过文本用户界面工具 nmtui 可用于在终端窗口中配置绑定

1
nmtui

由于nmtui可以解决大多数问题,本文提供的是命令行手动配置bond方式,请自行选择配置方式。

绑定模式概述

模式交换机要求特性概述
0 - balance-rr需要启用静态的 Etherchannel(未启用 LACP 协商)为容错和负载平衡设置循环策略。从第一个可用的接口开始,在每个绑定的从接口上依次接收和发送传输。
1 - active-backup需要指定主端口为容错设置主动备份策略。通过第一个可用的绑定从接口接收和发送传输。仅当活动的绑定从属接口出现故障时,才使用另一个绑定从属接口。
2 - balance-xor需要启用静态的 Etherchannel(未启用 LACP 协商)为容错和负载平衡设置 XOR(异或)策略。使用此方法,接口将传入请求的 MAC 地址与其中一个从属 NIC 的 MAC 地址相匹配。一旦建立此链路,就会从第一个可用接口开始顺序发送传输。
3 - broadcast需要启用静态的 Etherchannel(未启用 LACP 协商)为容错设置广播策略。所有传输都在所有从接口上发送。
4 - 802.3ad需要启用 LACP 协商的 Etherchannel设置 IEEE 802.3ad 动态链路聚合策略。创建共享相同速度和双工设置的聚合组。在活动聚合器中的所有从属设备上发送和接收。需要符合 802.3ad 的交换机。
5 - balance-tlb需要指定主端口为容错和负载平衡设置传输负载平衡 (TLB) 策略。根据每个从接口上的当前负载分配传出流量。当前从站接收传入流量。如果接收从机发生故障,另一个从机接管故障从机的 MAC 地址。
6 - balance-alb需要指定主端口指定主设备的接口名称,例如 eth0。主设备是第一个使用的绑定接口,除非失败,否则不会放弃。当绑定接口中的一个 NIC 速度更快并因此能够处理更大的负载时,此设置特别有用。此设置仅在绑定接口处于主动备份模式时有效。

配置环境介绍

Linux地址:192.168.0.1
Linux网关:192.168.0.254

网口1:eth0 3c:ab:0e:35:fc:18
网口2:eth1 3c:ab:0e:35:fc:19

绑定模式 0 配置脚本

RHEL5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
ethtool eth0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

echo alias bond0 bonding >> /etc/modprobe.conf
set_rhel5_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel5_bond_config -b bond0 -m 0 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100"
set_rhel5_ethx_config() {
bond_name=$1
eth_name=$2

mac_address=`cat /sys/class/net/$eth_name/address`
eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
HWADDR=$mac_address
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel5_ethx_config bond0 eth0
set_rhel5_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
ethtool eth0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

set_rhel6_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel6_bond_config -b bond0 -m 0 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100"

set_rhel6_ethx_config() {
bond_name=$1
eth_name=$2

eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel6_ethx_config bond0 eth0
set_rhel6_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL7

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli con add type bond ifname bond0 bond.options "mode=balance-rr,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet ifname eth0 master bond0
nmcli connection add type ethernet ifname eth1 master bond0
nmcli connection up eth0
nmcli connection up eth1
nmcli connection up bond0

RHEL8 9

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=balance-rr,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet slave-type bond con-name eth0 ifname eth0 master bond0
nmcli connection add type ethernet slave-type bond con-name eth1 ifname eth1 master bond0
nmcli connection up eth0
nmcli connection up eth1
nmcli connection up bond0

绑定模式 1 配置脚本

RHEL5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

echo alias bond0 bonding >> /etc/modprobe.conf
set_rhel5_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel5_bond_config -b bond0 -m 1 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100 primary=eht0"
set_rhel5_ethx_config() {
bond_name=$1
eth_name=$2

mac_address=`cat /sys/class/net/$eth_name/address`
eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
HWADDR=$mac_address
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel5_ethx_config bond0 eht0
set_rhel5_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

set_rhel6_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel6_bond_config -b bond0 -m 1 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100 primary=eht0"

set_rhel6_ethx_config() {
bond_name=$1
eth_name=$2

eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel6_ethx_config bond0 eht0
set_rhel6_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL7

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli con add type bond ifname bond0 bond.options "mode=active-backup,primary=eht0,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet ifname eht0 master bond0
nmcli connection add type ethernet ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

RHEL8 9

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=active-backup,primary=eht0,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet slave-type bond con-name eht0 ifname eht0 master bond0
nmcli connection add type ethernet slave-type bond con-name eth1 ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

绑定模式 2 配置脚本

RHEL5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

echo alias bond0 bonding >> /etc/modprobe.conf
set_rhel5_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel5_bond_config -b bond0 -m 2 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100 xmit_hash_policy=layer3+4"
set_rhel5_ethx_config() {
bond_name=$1
eth_name=$2

mac_address=`cat /sys/class/net/$eth_name/address`
eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
HWADDR=$mac_address
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel5_ethx_config bond0 eht0
set_rhel5_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

set_rhel6_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel6_bond_config -b bond0 -m 2 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100 xmit_hash_policy=layer3+4"

set_rhel6_ethx_config() {
bond_name=$1
eth_name=$2

eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel6_ethx_config bond0 eht0
set_rhel6_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL7

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli con add type bond ifname bond0 bond.options "mode=balance-xor,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet ifname eht0 master bond0
nmcli connection add type ethernet ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

RHEL8 9

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=balance-xor,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet slave-type bond con-name eht0 ifname eht0 master bond0
nmcli connection add type ethernet slave-type bond con-name eth1 ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

绑定模式 3 配置脚本

RHEL5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

echo alias bond0 bonding >> /etc/modprobe.conf
set_rhel5_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel5_bond_config -b bond0 -m 3 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100"
set_rhel5_ethx_config() {
bond_name=$1
eth_name=$2

mac_address=`cat /sys/class/net/$eth_name/address`
eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
HWADDR=$mac_address
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel5_ethx_config bond0 eht0
set_rhel5_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

set_rhel6_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel6_bond_config -b bond0 -m 3 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100"

set_rhel6_ethx_config() {
bond_name=$1
eth_name=$2

eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel6_ethx_config bond0 eht0
set_rhel6_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL7

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli con add type bond ifname bond0 bond.options "mode=broadcast,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet ifname eht0 master bond0
nmcli connection add type ethernet ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

RHEL8 9

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=broadcast,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet slave-type bond con-name eht0 ifname eht0 master bond0
nmcli connection add type ethernet slave-type bond con-name eth1 ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

绑定模式 4 配置脚本

RHEL5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

echo alias bond0 bonding >> /etc/modprobe.conf
set_rhel5_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel5_bond_config -b bond0 -m 4 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100 xmit_hash_policy=layer2+3"
set_rhel5_ethx_config() {
bond_name=$1
eth_name=$2

mac_address=`cat /sys/class/net/$eth_name/address`
eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
HWADDR=$mac_address
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel5_ethx_config bond0 eht0
set_rhel5_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

set_rhel6_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel6_bond_config -b bond0 -m 4 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100 xmit_hash_policy=layer2+3"

set_rhel6_ethx_config() {
bond_name=$1
eth_name=$2

eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel6_ethx_config bond0 eht0
set_rhel6_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL7

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli con add type bond ifname bond0 bond.options "mode=802.3ad,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet ifname eht0 master bond0
nmcli connection add type ethernet ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

RHEL8 9

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=802.3ad,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet slave-type bond con-name eht0 ifname eht0 master bond0
nmcli connection add type ethernet slave-type bond con-name eth1 ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

绑定模式 5 配置脚本

RHEL5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

echo alias bond0 bonding >> /etc/modprobe.conf
set_rhel5_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel5_bond_config -b bond0 -m 5 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100"
set_rhel5_ethx_config() {
bond_name=$1
eth_name=$2

mac_address=`cat /sys/class/net/$eth_name/address`
eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
HWADDR=$mac_address
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel5_ethx_config bond0 eht0
set_rhel5_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

set_rhel6_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel6_bond_config -b bond0 -m 5 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100"

set_rhel6_ethx_config() {
bond_name=$1
eth_name=$2

eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel6_ethx_config bond0 eht0
set_rhel6_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL7

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli con add type bond ifname bond0 bond.options "mode=balance-tlb,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet ifname eht0 master bond0
nmcli connection add type ethernet ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

RHEL8 9

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=balance-tlb,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet slave-type bond con-name eht0 ifname eht0 master bond0
nmcli connection add type ethernet slave-type bond con-name eth1 ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

绑定模式 6 配置脚本

RHEL5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

echo alias bond0 bonding >> /etc/modprobe.conf
set_rhel5_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel5_bond_config -b bond0 -m 6 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100"
set_rhel5_ethx_config() {
bond_name=$1
eth_name=$2

mac_address=`cat /sys/class/net/$eth_name/address`
eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
HWADDR=$mac_address
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel5_ethx_config bond0 eht0
set_rhel5_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
ethtool eht0 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eht0
exit 1
fi

ethtool eth1 |grep "Link detected: yes"> /dev/null
if [ $? -ne 0 ] ;then
echo Can not detect the link of eth1
exit 1
fi

set_rhel6_bond_config ()
{
unset OPTIND
while getopts 'b:m:i:n:g:s:t:' opt; do
case $opt in
b) bond_name=$OPTARG;;
m) bond_mode=$OPTARG;;
i) ip=$OPTARG;;
n) mask=$OPTARG;;
g) gateway=$OPTARG;;
s) bond_opts=$OPTARG;;
t) network_type=$OPTARG;;
esac
done
bond_config_file="/etc/sysconfig/network-scripts/ifcfg-$bond_name"
echo $bond_config_file
if [ -f $bond_config_file ]; then
echo "Backup original $bond_config_file to bondhelper.$bond_name"
mv $bond_config_file /etc/sysconfig/network-scripts/bondhelper.$bond_name -f
fi

if [ "static" == $network_type ]; then
if [ ! -n "$gateway" ]; then
ip_setting="IPADDR=$ip
NETMASK=$mask
USERCTL=no"
else
ip_setting="IPADDR=$ip
NETMASK=$mask
GATEWAY=$gateway
USERCTL=no"
fi
else
ip_setting="USERCTL=no"
fi
cat << EOF > $bond_config_file
DEVICE=$bond_name
ONBOOT=yes
BOOTPROTO=$network_type
$ip_setting
BONDING_OPTS="mode=$bond_mode $bond_opts"
NM_CONTROLLED=no
EOF
}
set_rhel6_bond_config -b bond0 -m 6 -i 192.168.0.1 -n 255.255.255.0 -g 192.168.0.254 -t static -s "miimon=100"

set_rhel6_ethx_config() {
bond_name=$1
eth_name=$2

eth_config_file="/etc/sysconfig/network-scripts/ifcfg-$eth_name"
if [ -f $eth_config_file ]; then
echo "Backup original $eth_config_file to bondhelper.$eth_name"
mv $eth_config_file /etc/sysconfig/network-scripts/bondhelper.$eth_name -f
fi

cat << EOF > $eth_config_file
DEVICE=$eth_name
BOOTPROTO=none
ONBOOT=yes
MASTER=$bond_name
SLAVE=yes
USERCTL=no
NM_CONTROLLED=no
EOF
}

set_rhel6_ethx_config bond0 eht0
set_rhel6_ethx_config bond0 eth1

echo "Network service will be restarted."
service network restart
cat /proc/net/bonding/bond0

RHEL7

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli con add type bond ifname bond0 bond.options "mode=balance-alb,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet ifname eht0 master bond0
nmcli connection add type ethernet ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0

RHEL8 9

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
nmcli connection add type bond con-name bond0 ifname bond0 bond.options "mode=balance-alb,miimon=100"
nmcli connection modify bond0 ipv4.addresses '192.168.0.1/24'
nmcli connection modify bond0 ipv4.gateway '192.168.0.254'
nmcli connection modify bond0 ipv4.method manual
nmcli connection add type ethernet slave-type bond con-name eht0 ifname eht0 master bond0
nmcli connection add type ethernet slave-type bond con-name eth1 ifname eth1 master bond0
nmcli connection up eht0
nmcli connection up eth1
nmcli connection up bond0