文章目录
RedHat 系统双网卡绑定配置
一. 配置原理
通过将两个物理网卡(如eth0/eth1)绑定为逻辑网卡bond0,实现:
- 网络冗余(主备模式):单网卡故障时自动切换
- 带宽叠加(负载均衡模式):提升网络吞吐量
- 链路聚合(802.3ad模式):需交换机支持
- 支持版本:RHEL6/RHEL7/RHEL8
二. 配置文件设置
1 虚拟网卡配置(bond0)
/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BONDING_OPTS="mode=1 miimon=100 primary=eth0"
ONBOOT=yes
BOOTPROTO=static
2 物理网卡配置示例
# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
ONBOOT=yes
# /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
MASTER=bond0
SLAVE=yes
BOOTPROTO=none
ONBOOT=yes
三. 核心操作步骤
1 加载绑定驱动
RHEL6需手动加载模块
echo "alias bond0 bonding" >> /etc/modprobe.d/bonding.conf
echo "options bond0 miimon=100 mode=1" >> /etc/modprobe.d/bonding.conf
modprobe bonding
2 服务重启
# RHEL7+/RHEL8
systemctl restart NetworkManager
systemctl restart network
# RHEL6
service NetworkManager stop
chkconfig NetworkManager off
service network restart
四. 绑定模式详解
模式 | 名称 | 特点 | 适用场景 |
---|---|---|---|
0 | balance-rr | 轮询传输,带宽翻倍,需交换机支持 | FTP服务器 |
1 | active-backup | 主备自动切换,仅1块网卡工作 | 数据库服务器 |
4 | 802.3ad | 动态链路聚合,需交换机支持LACP协议 | 虚拟化集群 |
6 | balance-alb | 自适应负载均衡,无需交换机支持 | 临时测试环境 |
推荐模式:生产环境优先使用mode1(主备)
五. 验证与监控
查看绑定状态
cat /proc/net/bonding/bond0
实时流量监控
watch -n 1 "ethtool bond0 | grep Speed"
强制切换测试(主备模式)
ifdown eth0 && sleep 30 && ifup eth0
六. 注意事项
- 物理网卡一致性:建议使用相同型号网卡
- 交换机配置:mode0/mode4需启用端口聚合
- 虚拟机环境:VMware需关闭"网络故障切换检测"
- 版本差异:
- RHEL7+推荐使用
nmcli
工具 - RHEL8默认使用NetworkManager
- RHEL7+推荐使用
七. 故障排查
# 查看内核日志
dmesg | grep -i bond
# 检查模块加载
lsmod | grep bonding
# 网络调试模式
echo 1 > /sys/class/net/bond0/bonding/debug