Linux 创建虚拟网卡

安装相关依赖

1
apt install -y uml-utilities bridge-utils

添加网桥

1
brctl addbr br0

激活网桥

1
ip link set br0 up

添加虚拟网卡

1
ip link set tap0 up

将虚拟网卡添加到指定网桥上

1
brctl addif br0 tap0

给网桥配制ip地址

1
ifconfig br0 172.24.16.10 up

移除

1
2
3
4
5
brctl delif br0 tap0

tunctl -d tap0

brctl delbr br0

brctl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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