centos系统下服务器网卡配置文件,CentOS服务器网卡绑定配置

本文转载自【微信公众号:WalkingCloud,ID:WalkingCloud2018】经微信公众号授权转载,如需转载与原文作者联系

网卡绑定是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡。bond在实际网络应用部署中是一种常用的技术

下面介绍如何在CentOS服务器上实现网卡绑定

1、服务器ifconfig查看可以看到有两块网卡eth0,eth1

859d70480d0a5074931ffce100778b7d.png

要实现物理网口eth0,eth1网卡绑定,绑定后的虚拟逻辑网口bond0 IP地址和原来的eth0的IP保持一致

2、modinfo bonding 检查自己的操作系统是否支持bonding

a3f72b309d8b8069788b1dc739493df4.png

如果没有消息返回,说明内核不支持bonding,需要重新编译内核

3、检查ifenslave,是否有这个命令

1bce7f7dc0e9d2c7d6b47349402ff2d4.png

4、接下来进入正题

在cd /etc/sysconfig/network-scripts/下创建ifcfg-bond0配置文件

[root@YuanFan-CentOS ~]# cd /etc/sysconfig/network-scripts/

[root@YuanFan-CentOS network-scripts]# vi ifcfg-bond0

DEVICE=bond0

TYPE=Ethernet

ONBOOT=yes

BOOTPROTO=none

IPADDR=192.168.31.2

NETMASK=255.255.255.0

GATEWAY=192.168.31.1

DNS1=114.114.114.114

DNS2=1.1.1.1

USERCTL=no

8066d1a6eb3274b683086b3f8875aca5.png

接下来修改ifcfg-eth0和ifcfg-eth1两块物理网卡的配置文件

将原有的IP、子网掩码、网关信息等信息全部删除,修改成如下格式

[root@YuanFan-CentOS ~]# cd /etc/sysconfig/network-scripts/

[root@YuanFan-CentOS network-scripts]# vi ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

85403e6d8b9343bc7fb8f395d850dfd8.png

[root@YuanFan-CentOS network-scripts]# vi ifcfg-eth1

DEVICE=eth1

ONBOOT=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

2e1a45f6558fc8f2fba900aa311684bb.png

5、修改modprobe相关设定文件,并加载bonding模块

[root@YuanFan-CentOS ~]#

vi /etc/modprobe.d/bonding.conf

alias bond0 bonding

options bonding mode=6 miimon=200

15cc8c277aa3f8d578809ab1dd87d69d.png

加载bonding模块

[root@YuanFan-CentOS ~]# modprobe bonding

如果这时是SecureCRT等SSH终端连接的服务器后台,会话可能会断开,在服务器上确认bonding模块是否加载,然后用service network restart或者/etc/init.d/network restart命令重启网络

[root@YuanFan-CentOS ~]# lsmod | grep bonding

bonding 132885 0

[root@YuanFan-CentOS ~]# service network restart

Shutting down interface bond0: [ OK ]

Shutting down loopback interface: [ OK ]

Bringing up loopback interface: [ OK ]

Bringing up interface bond0: Determining if ip address 192.168.31.2 is already in use for device bond0...

[ OK ]

[root@YuanFan-CentOS ~]#

b7b754f14f80d9293c2e8c59e0089a3d.png

查看bond网卡绑定后的模式

cat /proc/net/bonding/bond0

[root@YuanFan-CentOS ~]#cat /proc/net/bonding/bond0

972ad87e3b06079027356f527ac1a6ae.png

6、测试一下负载均衡功能

手动断开eth0链路的网线,看网络是否还通

如下图所示ethtool eth0 可以看到eth0网口已经断开,右侧可以看到ping 192.168.31.1网关一直可以ping通

10746bed61a57f13c6d2d88f19d2c08c.png

注:mode bond网卡绑定的几种模式之前有介绍,请参见本公众号历史文章

mode:Mode of operation

0 for balance-rr,

1 for active-backup,

2 for balance-xor,

3 for broadcast,

4 for 802.3ad,

5 for balance-tlb,

6 for balance-alb (charp)

举报/反馈

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS 7.6 下创建双网卡绑定,可以使用 Linux 内核提供的固定链接聚合(bonding)技术。下面是创建双网卡绑定的步骤: 1. 确认服务器上有两个网卡,并且已经正确安装了驱动程序。 2. 安装 bonding 模块: ``` yum install -y bonding ``` 3. 编辑 `/etc/modprobe.d/bonding.conf` 文件,添加以下配置: ``` alias bond0 bonding options bonding mode=0 miimon=100 ``` 其中,`mode=0` 表示使用轮询模式(Round-Robin),`miimon=100` 表示每 100 毫秒检测一次链路状态。 4. 编辑 `/etc/sysconfig/network-scripts/ifcfg-eth0` 文件,添加以下配置: ``` DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=no MASTER=bond0 SLAVE=yes BOOTPROTO=none ``` 其中,`MASTER=bond0` 表示将该网卡绑定到 bond0 接口上。 5. 编辑 `/etc/sysconfig/network-scripts/ifcfg-eth1` 文件,添加以下配置: ``` DEVICE=eth1 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=no MASTER=bond0 SLAVE=yes BOOTPROTO=none ``` 同样,`MASTER=bond0` 表示将该网卡绑定到 bond0 接口上。 6. 重启网络服务: ``` systemctl restart network ``` 7. 验证双网卡绑定是否生效: ``` cat /proc/net/bonding/bond0 ``` 如果看到类似以下输出,则表示双网卡绑定已经成功: ``` Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: load balancing (round-robin) MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth0 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:ef:2f:58 Slave queue ID: 0 Slave Interface: eth1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:ef:2f:62 Slave queue ID: 0 ``` 注意:双网卡绑定需要设备端口和交换机端口配置一致,否则会导致链路不稳定。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值