千家信息网

Centos7/RHEL7双网卡怎么绑定

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,本篇内容主要讲解"Centos7/RHEL7双网卡怎么绑定",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Centos7/RHEL7双网卡怎么绑定"吧!1.
千家信息网最后更新 2026年11月02日Centos7/RHEL7双网卡怎么绑定

本篇内容主要讲解"Centos7/RHEL7双网卡怎么绑定",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Centos7/RHEL7双网卡怎么绑定"吧!

1. 简要

双网卡绑定技术在centos7中使用了teaming技术,而在rhel6/centos7中使用的是bonding技术,在centos7中双网卡绑定既能使用teaming也可以使用bonding,这里推荐使用teaming技术,方便与查看和监控。

2. 原理

这里介绍两种最常见的双网卡绑定模式:

(1) roundrobin - 轮询模式

所有链路处于负载均衡状态,这种模式的特点增加了带宽,同时支持容错能力。

(2) activebackup - 主备模式

一个网卡处于活动状态,另一个处于备份状态,所有流量都在主链路上处理,当活动网卡down掉时,启用备份网卡。

3. 基础环境

系统:centos7

在centos7中,关闭虚拟机添加网卡,再开启虚拟机,系统是不会自动生成网卡的配置文件:

在centos7中要生成网卡配置文件的方法很简单,使用如下命令:

  # 查看物理网卡信息[root@localhost ~]# nmcli devdevice    type   state   connection     eno16777736 ethernet connected eno16777736    eno33554984 ethernet connected wired connection 1 eno50332208 ethernet connected wired connection 2 lo      loopback unmanaged --

上面的信息可以看到,一共有四张网卡,其中lo是本地回环网卡,另外三张为物理网卡。

  # 查看网卡连接信息[root@localhost ~]# nmcli con shname        uuid                 type      device   wired connection 2 9a1314bf-d273-406a-930a-dc4160dee4ec 802-3-ethernet eno50332208 wired connection 1 47eef4a3-7fa4-4a73-83ef-1485bda9b950 802-3-ethernet eno33554984 eno16777736     51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736

上面的信息可以查看到一共有3个连接,其中两个有线连接,表示没有设置过的网卡连接,还有一个enoxx连接。接下来要修改两个有线连接的命名方法,并生成网卡配置文件:

  # 首先,删除两个无用的有线连接[root@localhost ~]# nmcli con del 9a1314bf-d273-406a-930a-dc4160dee4ecconnection 'wired connection 2' (9a1314bf-d273-406a-930a-dc4160dee4ec) successfully deleted.[root@localhost ~]# nmcli con del 47eef4a3-7fa4-4a73-83ef-1485bda9b950connection 'wired connection 1' (47eef4a3-7fa4-4a73-83ef-1485bda9b950) successfully deleted.
# 再次创建新的连接并生成配置文件[root@localhost ~]# nmcli conn add type ethernet con-name eno50332208 ifname eno50332208 connection 'eno50332208' (eea2a115-63f8-4f33-be84-12559f02542c) successfully added.[root@localhost ~]# nmcli conn add type ethernet con-name eno33554984 ifname eno33554984connection 'eno33554984' (32d2389e-4e82-4419-9d18-5aff8f0be003) successfully added.
 # 最后,查看下[root@localhost ~]# nmcli con shname     uuid                 type      device   eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208[root@localhost ~]# ll /etc/sysconfig/network-scripts/ifcfg-eno*-rw-r--r--. 1 root root 394 nov 26 05:59 /etc/sysconfig/network-scripts/ifcfg-eno16777736-rw-r--r--. 1 root root 288 dec 26 08:44 /etc/sysconfig/network-scripts/ifcfg-eno33554984-rw-r--r--. 1 root root 288 dec 26 08:44 /etc/sysconfig/network-scripts/ifcfg-eno50332208

网络连接和配置文件都成功生成了。 接下来通过eno33554984 和 eno50332208 使用teaming模式进行双网卡绑定

4. roundrobin模式:

roundrobin模式也称为轮询模式,它 基于每一个包 ,当某一台服务器的两张网卡设置为roundrobin模式teaming,此时服务器发出的数据包,就会在两个物理网卡上进行轮询,即第一个数据包走一张网卡,第二个数据包走第二张网卡,依次轮询。

注意:

(1)roundrobin具有容错性,当一张网卡down掉,数据包依然发送成功。

(2)在使用roundrobin模式必须要在交换机上做以太通道,不然会出现网络无法连通。

实际操作:

  # 使用nmcli命令操作,创建team接口team0,同时设置teaming模式为roundrobin[root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "roundrobin"}}'connection 'team0' (9dc48bd6-54b9-48db-b7dd-ecf34ae9196f) successfully added.
  # 给接口team0设置ip地址[root@localhost ~]# nmcli con modify team0 ipv4.address '10.0.0.2/24' ipv4.gateway '10.0.0.1'   # 设置为手动模式,取消dhcp[root@localhost ~]# nmcli con modify team0 ipv4.method manual
  # 将两张物理网卡加入到team中[root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0connection 'team0-port1' (22d3640e-f5c8-499c-b0dd-913c8970d800) successfully added.[root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname eno50332208 master team0connection 'team0-port2' (12660d2a-0e1f-41e6-96b2-53de4fc6b78c) successfully added.[root@localhost ~]# nmcli con shname     uuid                 type      device   team0-port2 12660d2a-0e1f-41e6-96b2-53de4fc6b78c 802-3-ethernet --     eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0-port1 22d3640e-f5c8-499c-b0dd-913c8970d800 802-3-ethernet --     team0    9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team      team0    eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208
  # 查看team0的状态[root@localhost ~]# teamdctl team0 stsetup: runner: roundrobin

4.1 roundrobin问题排查

第一次查看出现的是这样的结果,检查下配置:

  # 通过直接查看网卡发现team0并没有启动[root@localhost ~]# ip a | grep team05: team0:  mtu 1500 qdisc noqueue state down  # 使用ifup 启动team0并没有成功,继续排查[root@localhost ~]# ifup team0[root@localhost ~]# ip a | grep team05: team0:  mtu 1500 qdisc noqueue state down

直接sysetmctl restart network 也没有成功。

  # 发现team0-port1 team0-port2没有添加成功物理网卡,怎么回事呢?[root@localhost ~]# nmcli con shname     uuid                 type      device   team0-port2 ec96c1e1-d268-4ba1-a2f9-0133a9f02655 802-3-ethernet --     eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0-port1 22d3640e-f5c8-499c-b0dd-913c8970d800 802-3-ethernet --     team0    9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team      team0    eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208
  # 删除掉[root@localhost ~]# nmcli con del team0-port1connection 'team0-port1' (22d3640e-f5c8-499c-b0dd-913c8970d800) successfully deleted.[root@localhost ~]# nmcli con del team0-port2connection 'team0-port2' (ec96c1e1-d268-4ba1-a2f9-0133a9f02655) successfully deleted.  # 删除两张物理网卡的连接[root@localhost ~]# nmcli con shname     uuid                 type      device   eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0    9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team      team0    eno33554984 32d2389e-4e82-4419-9d18-5aff8f0be003 802-3-ethernet eno33554984 eno50332208 eea2a115-63f8-4f33-be84-12559f02542c 802-3-ethernet eno50332208 [root@localhost ~]# nmcli con del eno33554984 eno50332208connection 'eno33554984' (32d2389e-4e82-4419-9d18-5aff8f0be003) successfully deleted.connection 'eno50332208' (eea2a115-63f8-4f33-be84-12559f02542c) successfully deleted.  # 删除成功[root@localhost ~]# nmcli con shname     uuid                 type      device   eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0    9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team      team0
  # 再次将两张物理网卡添加到team[root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0connection 'team0-port1' (0331ea43-95c0-4106-b388-8484d4c3940d) successfully added.[root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname eno50332208 master team0connection 'team0-port2' (880f2146-fe93-42dd-8d28-7d0dd50b4011) successfully added.[root@localhost ~]# nmcli con shname     uuid                 type      device   team0-port1 0331ea43-95c0-4106-b388-8484d4c3940d 802-3-ethernet eno33554984 eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0    9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team      team0    team0-port2 880f2146-fe93-42dd-8d28-7d0dd50b4011 802-3-ethernet eno50332208

现在成功将两张物理网卡绑定到了team组中

  # 现在查看team0的状态就出现了,模式是:roundrobin[root@localhost ~]# teamdctl team0 st setup: runner: roundrobinports: eno33554984  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0 eno50332208  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0

这样,team模式的roundrobin搭建成功。

总结:

在做链路聚合的时候,所要使用到的物理网卡不能独立存在连接,也就是在nmcli con sh查看时,不能独立存在,否则就无法绑定到team模式中。

4.2 测试

因为这里是虚拟机环境,只能通过down掉网卡进行查看。

[root@localhost ~]# teamdctl team0 stsetup: runner: roundrobinports: eno33554984  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0 eno50332208  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0

两张网卡同时在线,现在down掉其中一张网卡,

[root@localhost ~]# nmcli con del team0-port1connection 'team0-port1' (0331ea43-95c0-4106-b388-8484d4c3940d) successfully deleted.[root@localhost ~]# nmcli con shname     uuid                 type      device   eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0    9dc48bd6-54b9-48db-b7dd-ecf34ae9196f team      team0    team0-port2 880f2146-fe93-42dd-8d28-7d0dd50b4011 802-3-ethernet eno50332208[root@localhost ~]# teamdctl team0 stsetup: runner: roundrobinports: eno50332208  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0

这样就发现eno33554984网卡已经down掉了。

[root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0connection 'team0-port1' (59acd6bf-affc-4994-a050-83c45816859a) successfully added.[root@localhost ~]# [root@localhost ~]# teamdctl team0 stsetup: runner: roundrobinports: eno33554984  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0 eno50332208  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0

虚拟机环境就这样测试了吧,至于生产环境就直接拔网线,ping测试。

资料有说linux下roundrobin具有容错的效果,为了测试是否有容错的效果,虚拟机做了下更改来验证:

这一次网卡全部改成桥接模式,为了更好的测试是否具有容错性。

roundrobin已经配置完毕。接下来我们down掉一张网卡检查是否具有容错性。

通过虚拟机测试,容错性是存在的。

5. 双网卡绑定activebackup的实现

[root@localhost ~]# nmcli con sh name     uuid                 type      device   team0-port2 2a1aa534-e021-4452-bb0a-2002dabcbc08 802-3-ethernet eno50332208 team0-port1 9a10c9ef-ee9c-4151-9a47-59b4668e8934 802-3-ethernet --     eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 team0    c2278f3f-5c6b-4e1d-b925-514d3c3832b6 team      team0    [root@localhost ~]# nmcli con del team0 team0-port1 team0-port2connection 'team0' (c2278f3f-5c6b-4e1d-b925-514d3c3832b6) successfully deleted.connection 'team0-port1' (9a10c9ef-ee9c-4151-9a47-59b4668e8934) successfully deleted.connection 'team0-port2' (2a1aa534-e021-4452-bb0a-2002dabcbc08) successfully deleted.[root@localhost ~]# nmcli con sh name     uuid                 type      device   eno16777736 51d00668-2cf5-41da-ad8d-5019d62e98ad 802-3-ethernet eno16777736 # 以上操作就删除了roundrobin模式,恢复到初始状态。
# 添加逻辑网卡team0,并启用activebackup模式[root@localhost ~]# nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'connection 'team0' (f0794e59-419d-4c2a-96b9-464610b6321a) successfully added.# 绑定ip[root@localhost ~]# nmcli con modify team0 ipv4.address 192.168.118.122/24 ipv4.gateway 192.168.118.1[root@localhost ~]# nmcli con modify team0 ipv4.method manual# 添加物理网卡到activebackup模式[root@localhost ~]# nmcli con add type team-slave con-name team0-port1 ifname eno33554984 master team0connection 'team0-port1' (52656904-6e85-4a04-98b4-2b19773fa290) successfully added.[root@localhost ~]# nmcli con add type team-slave con-name team0-port2 ifname eno50332208 master team0connection 'team0-port2' (44d96e3a-014a-481f-9122-4ca2d3be9f7a) successfully added.
[root@localhost ~]# teamdctl team0 stsetup: runner: activebackupports: eno33554984  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0 eno50332208  link watches:   link summary: up   instance[link_watch_0]:    name: ethtool    link: up    down count: 0runner: active port: eno33554984

成功,处于活动中的网卡为 eno33554984

5.1 测试

通过down掉活动网卡测试网络是否仍然处于连通状态

测试成功。

注意: 在做网卡绑定的时候,如果发现物理网卡总是无法绑定到team0,请检查该物理网卡是否处于up状态。

到此,相信大家对"Centos7/RHEL7双网卡怎么绑定"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

网卡 模式 物理 成功 测试 状态 容错 配置 文件 生成 两个 信息 容错性 技术 数据 环境 活动 接下来 同时 方法 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网的科技 互联网科技行业发展 互联网下的科技发展 互联网科技小贷 狮子座互联网科技培训 哈尔滨新华互联网科技 华脉科技工业互联网产品 上海电发互联网科技有限公司 成都玖崟互联网科技有限公司乐商圈怎么样 中国科技互联网公司收入 以后互联网后是啥科技 荆州市昕露互联网络科技有限公司 银川新华互联网科技学校联系电话 天津腾达互联网科技有限公司 合肥互联网科技公司公章图片 互联网领先科技宣传片 南京一网一红互联网科技有限公司 互联网科技包装股 银川新华互联网科技学校原画 平安好医生打造互联网科技医疗 互联网金融科技 互联网金融监管科技数据 互联网电商科技 互联网科技会 善班互联网科技 哈尔滨新华互联网科技学院 须眉科技是互联网公司吗 湖南诚度互联网科技有限公司 广州市恰铎互联网科技有限公司 35岁以上互联网科技行业
0