Linux

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > Linux > Linux使用ip link命令设置bond

Linux使用ip link命令设置bond方式

作者:在成都搬砖的鸭鸭

这篇文章主要介绍了Linux使用ip link命令设置bond方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

1、介绍

设置bond的方法有很多种,其中通过命令行ip link设置就是其中一种,只不过这种设置方式不会持久化,当重启服务器或重启网络服务就会失效。

2、设置步骤

【1】创建bonding接口

ip link add bond0 type bond

查看创建的bond接口:

[root@xxx network-scripts]# ip link show bond0
19: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 1e:ce:ba:1e:f5:d3 brd ff:ff:ff:ff:ff:ff

【2】设置bonding模式

ip link set bond0 type bond mode active-backup miimon 100 #设置冗余备份模式,miimon为检测物理链路时间间隔,单位毫秒

查看bond信息:

[root@xxx network-scripts]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup) #负载均衡模式
Primary Slave: None
Currently Active Slave: None #当前激活接口,无
MII Status: down
MII Polling Interval (ms): 100  #检测物理链路时间间隔
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

【3】添加物理网口到bonding接口

ip link set p112p1 down
ip link set p112p1 master bond0
ip link set p112p2 down
ip link set p112p2 master bond0

查看聚合口信息:

[root@xxx network-scripts]# ip link show p112p1
4: p112p1: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc mq master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0d:48:4e:9f:e5 brd ff:ff:ff:ff:ff:ff
[root@xxx network-scripts]# ip link show p112p2
5: p112p2: <NO-CARRIER,BROADCAST,MULTICAST,SLAVE,UP> mtu 1500 qdisc mq master bond0 state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0d:48:4e:9f:e5 brd ff:ff:ff:ff:ff:ff

【4】激活bonding接口

ip link set p112p1 up
ip link set p112p2 up
ip link set bond0 up

查看bond信息:

[root@xxx network-scripts]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: p112p1  #当前使用接口
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: p112p1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0d:48:4e:9f:e5
Slave queue ID: 0

Slave Interface: p112p2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0d:48:4e:9f:e6
Slave queue ID: 0

3、解除步骤

【1】关闭bond接口

ip link set bond0 down

查看bond0接口状态:

[root@xxx ~]# ip link show bond0
11: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0d:48:4e:9f:e5 brd ff:ff:ff:ff:ff:ff

【2】接触从属接口

ip link set p112p1 nomaster
ip link set p112p2 nomaster

查看从接口状态:

[root@xxx ~]# ip link show p112p1 
4: p112p1: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0d:48:4e:9f:e5 brd ff:ff:ff:ff:ff:ff
[root@xxx ~]# ip link show p112p2
5: p112p2: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0d:48:4e:9f:e6 brd ff:ff:ff:ff:ff:ff

查看bond信息:

[root@xxx ~]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: None
MII Status: down
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

【3】删除bond接口

ip link del bond0 type bond

查看bond信息,不存在:

[root@xxx ~]# cat /proc/net/bonding/bond0
cat: /proc/net/bonding/bond0: No such file or directory

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文