当前位置:首页 > 系统教程 > 正文

Ubuntu 24.04 双网卡 Bonding 绑定完全教程(从零开始实现网卡冗余与负载均衡)

Ubuntu 24.04 双网卡 Bonding 绑定完全教程(从零开始实现网卡冗余与负载均衡)

Ubuntu 24.04 双网卡 Bonding 绑定完全教程(从零开始实现网卡冗余与负载均衡) 网卡绑定  双网卡bond0配置 Linux网络冗余 负载均衡Bonding 第1张

本文SEO关键词:Ubuntu 24.04 网卡绑定、双网卡bond0配置、Linux网络冗余、负载均衡Bonding。

在服务器运维中,网络的高可用性和带宽聚合至关重要。Ubuntu 24.04 网卡绑定(Bonding)技术允许将多块物理网卡虚拟成一块逻辑网卡bond0,实现Linux网络冗余负载均衡。本教程将手把手教你在Ubuntu 24.04上配置双网卡bond0,即使小白也能轻松掌握。

1. 环境准备

确保你的Ubuntu 24.04系统已安装,并拥有两块物理网卡(例如enp0s3和enp0s8)。可通过ip a命令查看网卡名称。

2. 安装必要工具

Bonding依赖ifenslave工具,执行以下命令安装:

    sudo apt updatesudo apt install ifenslave -y  

加载bonding内核模块并设置开机自动加载:

    sudo modprobe bondingecho "bonding" | sudo tee /etc/modules-load.d/bonding.conf  

3. 配置Netplan实现bond0

Ubuntu 24.04使用Netplan管理网络。编辑配置文件(通常位于/etc/netplan/目录下,如01-netcfg.yaml):

    sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.baksudo nano /etc/netplan/01-netcfg.yaml  

将以下配置粘贴,注意根据实际网卡名称修改enp0s3、enp0s8:

    network:  version: 2  renderer: networkd  ethernets:    enp0s3:      dhcp4: no    enp0s8:      dhcp4: no  bonds:    bond0:      dhcp4: yes      interfaces:        - enp0s3        - enp0s8      parameters:        mode: active-backup        primary: enp0s3        mii-monitor-interval: 100  

此配置创建bond0接口,模式为active-backup(主备),即一张网卡工作,另一张备用。若要负载均衡,可将mode改为balance-rr或802.3ad(需交换机支持)。

4. 应用配置并验证

执行以下命令使配置生效:

    sudo netplan apply  

查看bond0接口状态:

    ip a show bond0cat /proc/net/bonding/bond0  

如果看到bond0获取了IP地址,且/proc/net/bonding/bond0中显示Active Slave为enp0s3,说明配置成功。

5. 故障转移测试

断开主网卡(如拔掉网线或执行sudo ip link set enp0s3 down),然后再次查看cat /proc/net/bonding/bond0,应看到Active Slave切换到enp0s8,同时网络连接不中断。再次恢复enp0s3,Active Slave会切回。

6. 总结

通过以上步骤,你已成功在Ubuntu 24.04上配置了双网卡bond0绑定。这大大增强了网络的可靠性,是服务器虚拟化、高可用集群等场景的基石。掌握Ubuntu 24.04 网卡绑定双网卡bond0配置Linux网络冗余负载均衡Bonding,将助你轻松应对企业级网络运维需求。

教程结束,如有疑问欢迎交流。