命令安装
Centos系统
yum install bridge-utils
Ubuntu系统
apt-get install bridge-utils
命令介绍
参数 | 说明 | 示例 |
---|---|---|
addbr <bridge> |
创建网桥 | brctl addbr br10 |
delbr <bridge> |
删除网桥 | brctl delbr br10 |
addif <bridge> <device> |
将网卡接口接入网桥 | brctl addif br10 eth0 |
delif <bridge> <device> |
删除网桥接入的网卡接口 | brctl delif br10 eth0 |
show <bridge> |
查询网桥信息 | brctl show br10 |
stp <bridge> {on\off} |
启用禁用 STP | brctl stp br10 off/on |
showstp <bridge> |
查看网桥 STP 信息 | brctl showstp br10 |
setfd <bridge> <time> |
设置网桥延迟 | brctl setfd br10 10 |
showmacs <bridge> |
查看 mac 信息 | brctl showmacs br10 |
演示
添加网桥 br0
brctl addbr br0
设置br0
可用
ifconfig br0 192.168.100.1 netmask 255.255.255.0
显示所有的网桥信息
brctl show
显示网桥br0
的信息
brctl show br0
brctl常用命令
brctl addbr br1 #创建网桥
brctl addif br1 enp4s0 #为网桥添加物理接口
brctl delbr br1 #删除网桥
brctl delif br1 enp4s0 #删除网桥接口
brctl show #显示网桥列表信息
brctl show br1 #显示网桥br1的信息
brctl showmacs br1 #显示网桥的MAC地址信息
brctl showstp br1 #显示网桥的stp信息
brctl stp br-test on|off #开|关stp
brctl命令范式,可以通过对应英文参数,执行需要的命令
[root@localhost ~]# brctl
Usage: brctl [commands]
commands:
addbr <bridge> add bridge
delbr <bridge> delete bridge
addif <bridge> <device> add interface to bridge
delif <bridge> <device> delete interface from bridge
hairpin <bridge> <port> {on|off} turn hairpin on/off
setageing <bridge> <time> set ageing time
setbridgeprio <bridge> <prio> set bridge priority
setfd <bridge> <time> set bridge forward delay
sethello <bridge> <time> set hello time
setmaxage <bridge> <time> set max message age
setpathcost <bridge> <port> <cost> set path cost
setportprio <bridge> <port> <prio> set port priority
show [ <bridge> ] show a list of bridges
showmacs <bridge> show a list of mac addrs
showstp <bridge> show bridge stp info
stp <bridge> {on|off} turn stp on/off
brctl场景使用
brctl addbr bridge
brctl addif bridge eth0
brctl addif bridge ath0
ifconfig eth0 0.0.0.0
// 将有线和无线都设置为192.168.1.*网段,即可通过网上邻居进行访问
ifconfig bridge 192.168.1.0 netmask 255.255.255.0 up
// 添加iptables -t nat -A POSTROUTING -o ath0 -j SNAT --to 192.168.2.173