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”,查看結果刪除成功。