brctl 的使用
brctl 作用: 用来进行以太网桥接(bridge)的管理
主要用法如下:
root@hbg:/# brctl --help
BusyBox v1.22.1 (2016-02-24 11:41:04 CST) multi-call binary.
Usage: brctl COMMAND [BRIDGE [INTERFACE]]
Manage ethernet bridges
Commands:
show Show a list of bridges // 显示桥接信息
addbr BRIDGE Create BRIDGE // 增加桥接端口
delbr BRIDGE Delete BRIDGE // 删除桥接端口
addif BRIDGE IFACE Add IFACE to BRIDGE // 为桥接端口增加绑定接口
delif BRIDGE IFACE Delete IFACE from BRIDGE // 删除桥接端口的绑定接口
setageing BRIDGE TIME Set ageing time
setfd BRIDGE TIME Set bridge forward delay
sethello BRIDGE TIME Set hello time
setmaxage BRIDGE TIME Set max message age
setpathcost BRIDGE COST Set path cost
setportprio BRIDGE PRIO Set port priority
setbridgeprio BRIDGE PRIO Set bridge priority
stp BRIDGE [1/yes/on|0/no/off] STP on/off // 是否参与生成树协议
用法如下:
root@hbg:/# brctl show
bridge name bridge id STP enabled interfaces
br-net 7fff.78c2c0e3004d yes eth0
wlan0
可以看到,目前的桥接接口名称为br-net, 它绑定了两个端口 eth0 和 wlan0.
root@hbg:/# brctl addif br-net eth1
[ 1133.440000] device eth1 entered promiscuous mode
root@hbg:/# brctl show
bridge name bridge id STP enabled interfaces
br-net 7fff.78c2c0e3004d yes eth0
wlan0
eth1
为桥接接口br-net增加绑定接口 eth1, 增加完后查看到已经绑定成功。
root@hbg:/# brctl delif br-net eth1
[ 1248.150000] device eth1 left promiscuous mode
[ 1248.160000] br-net: port 3(eth1) entered disabled state
root@hbg:/# brctl show
bridge name bridge id STP enabled interfaces
br-net 7fff.78c2c0e3004d yes eth0
wlan0
删除桥接接口 br-net 绑定的端口eth1,删除完成后查看已经删除成功。
root@hbg:/# brctl addbr br-lan // 增加了桥接接口"br-lan"
root@hbg:/# brctl show
bridge name bridge id STP enabled interfaces
br-net 7fff.78c2c0e3004d yes eth0
wlan0
br-lan 8000.000000000000 no // 新增的桥接接口默认为“未使能”的
root@hbg:/# brctl addif br-lan eth1 // 为桥接接口br-lan 绑定端口eth1
[ 1375.780000] device eth1 entered promiscuous mode
root@hbg:/# brctl show
bridge name bridge id STP enabled interfaces
br-net 7fff.78c2c0e3004d yes eth0
wlan0
br-lan 8000.78c2c0e3004e no eth1
root@hbg:/# brctl stp br-lan 1 // 参与生成树协议
root@hbg:/# brctl show
bridge name bridge id STP enabled interfaces
br-net 7fff.78c2c0e3004d yes eth0
wlan0
br-lan 8000.78c2c0e3004e yes eth1 // 参与生成树协议,接收和发送BPDU(Bridge Protocol Data Units)
root@TVWS:/# brctl delbr br-lan
[ 1635.570000] device eth1 left promiscuous mode
[ 1635.570000] br-lan: port 1(eth1) entered disabled state
root@TVWS:/#
root@TVWS:/# brctl show
bridge name bridge id STP enabled interfaces
br-net 7fff.78c2c0e3004d yes eth0
wlan0
直接删除桥接接口“br-lan”,查看结果删除成功。