ubuntu 创建 tap 设备 (虚拟网卡)

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设置为非永久
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值