ubuntu 创建 tap 设备 (虚拟网卡)
ubuntu 创建 tap 设备原文:Ubuntu Manpage: tunctl — create and manage persistent TUN/TAP interfaces1 首先安装 UML 工具$ apt install uml-utilities2 To create an interface for use by a particular user, invoke tunctl
·
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设置为非永久
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)