Centos 7 双网卡绑定,主备工作状态

深藏阁楼爱情的钟 2023-07-25 05:25 55阅读 0赞

介绍:

  1. 系统版本:
  2. [root@localhost ~]# cat /etc/redhat-release
  3. CentOS Linux release 7.6.1810 (Core)
  4. 网卡eth0初始配置:
  5. [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
  6. TYPE=Ethernet
  7. BOOTPROTO=static
  8. NAME=eth0
  9. DEVICE=eth0
  10. ONBOOT=yes
  11. IPADDR=192.168.14.211
  12. PREFIX=24
  13. GATEWAY=192.168.14.254
  14. DNS1=10.1.2.30
  15. DNS2=114.114.114.114
  16. 网卡eth1初始配置:
  17. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
  18. TYPE=Ethernet
  19. BOOTPROTO=static
  20. NAME=eth1
  21. DEVICE=eth1
  22. ONBOOT=yes
  23. IPADDR=192.168.14.215
  24. PREFIX=24
  25. GATEWAY=192.168.14.254
  26. DNS1=10.1.2.30
  27. DNS2=114.114.114.114

一、配置双网卡主备

1、关闭 NetworkManager服务

  1. [root@localhost ~]# systemctl stop NetworkManager
  2. [root@localhost ~]# systemctl disable NetworkManager

2、添加bond0

  1. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
  2. TYPE=Bond
  3. DEVICE=bond0
  4. IPADDR=192.168.14.220
  5. PREFIX=24
  6. BONDING_OPTS=mode=active-backup
  7. NAME=bond0
  8. ONBOOT=yes

3、修改eth0

  1. [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
  2. TYPE=Ethernet
  3. BOOTPROTO=static
  4. NAME=eth0
  5. DEVICE=eth0
  6. ONBOOT=yes
  7. IPADDR=192.168.14.211
  8. PREFIX=24
  9. GATEWAY=192.168.14.254
  10. DNS1=10.1.2.30
  11. DNS2=114.114.114.114
  12. MASTER=bond0 #新增
  13. SLAVE=yes #新增

4、修改eth1

  1. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
  2. TYPE=Ethernet
  3. BOOTPROTO=static
  4. NAME=eth1
  5. DEVICE=eth1
  6. ONBOOT=yes
  7. IPADDR=192.168.14.215
  8. PREFIX=24
  9. GATEWAY=192.168.14.254
  10. DNS1=10.1.2.30
  11. DNS2=114.114.114.114
  12. MASTER=bond0 #新增
  13. SLAVE=yes #新增

5、重启网卡

  1. [root@localhost ~]# systemctl restart network

6、查看状态

  1. [root@localhost ~]# cat /proc/net/bonding/bond0
  2. Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
  3. Bonding Mode: fault-tolerance (active-backup)
  4. Primary Slave: None
  5. Currently Active Slave: eth0
  6. MII Status: up
  7. MII Polling Interval (ms): 0
  8. Up Delay (ms): 0
  9. Down Delay (ms): 0
  10. Slave Interface: eth0
  11. MII Status: up
  12. Speed: 1000 Mbps
  13. Duplex: full
  14. Link Failure Count: 0
  15. Permanent HW addr: 00:0c:29:08:01:5d
  16. Slave queue ID: 0
  17. Slave Interface: eth1
  18. MII Status: up
  19. Speed: 1000 Mbps
  20. Duplex: full
  21. Link Failure Count: 0
  22. Permanent HW addr: 00:0c:29:08:01:67
  23. Slave queue ID: 0

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RsYWRhZ2lv_size_16_color_FFFFFF_t_70

7、添加临时默认路由(永久路由自行添加配置文件)

  1. [root@localhost ~]# route add -net 0.0.0.0/0 gw 192.168.14.254 dev bond0

二、模拟生产环境网卡故障

1、关闭eth0主网卡模拟故障,eth1从备转为主

  1. [root@localhost ~]# ifdown eth0

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RsYWRhZ2lv_size_16_color_FFFFFF_t_70 1

2、故障网卡eth0恢复之后并不会抢占eth1,从而避免网络波动

  1. [root@localhost ~]# ifup eth0

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RsYWRhZ2lv_size_16_color_FFFFFF_t_70 2

发表评论

表情:
评论列表 (有 0 条评论,55人围观)

还没有评论,来说两句吧...

相关阅读