ubuntu 创建 tap 设备
原文:Ubuntu Manpage: tunctl — create and manage persistent TUN/TAP interfaces
1 首先安装 UML 工具
$ apt install uml-utilities
2 To create an interface for use by a particular user, invoke tunctl without the -d option: 要创建一个接口给特定用户使用,不要使用 -d 命令
$ tunctl -u someuser
# Set 'tap0' persistent and owned by 'someuser' 创建 tap0 永久设备并属于某个用户 someuser
tunctl 具体语法:
tunctl [-f tun-clone-device] [-u owner] [-t device-name]
tunctl [-f tun-clone-device] -d device-name
3 Then, configure the interface as normal: 然后正常配置接口(设置IP地址)
# 为 tap0 分配 IP 地址并打开 tap0
$ ifconfig tap0 192.168.0.254 up
# eth0的IP是253。添加目标为eth0的设备要经过tap0
$ route add -host 192.168.0.253 dev tap0
# 设置是否对网络上的arp包进行中继。参数值为布尔值,1表示中继,0表示忽略,缺省值为0。该参数通常只对充当路由器的linux主机有用。
$ bash -c 'echo 1 > /proc/sys/net/ipv4/conf/tap0/proxy_arp'
# 当收到IP地址为192.168.0.253的请求时,将会用eth0的MAC地址回答。
$ arp -Ds 192.168.0.253 eth0 pub
4 To delete the interface, use the -d option: 要删除这个接口,使用 -d 选项
$ tunctl -d tap0
# Set 'tap0' nonpersistent 将tap0设置为非永久