将TunTap与linux内核2.6一起使用

时间:2013-07-26 16:11:32

标签: networking linux-kernel tunnel tun

TunTap文档on the vtun site指出驱动程序仅支持Linux内核2.4。有没有办法让它在2.6和3.2版本的Linux上运行?

设备上的猫显示:

# cat /dev/net/tun
 cat: File descriptor in bad state

我尝试直接从rpm文件安装,看看我能走得多远:

# rpm -i tun-1.1-6.rh71.i386.rpm
error: Failed dependencies:
     /bin/sh is needed by tun-1.1-6.i386

有什么方法可以让我在linux 2.6+上工作,或者你知道有什么比tuntap更好的选择吗?

2 个答案:

答案 0 :(得分:2)

tuntap文档已过时。此外,在较新版本的Linux中,您可能需要使用

tunctl 

而不是

ip tuntap add

要在debian Squeeze上安装tunctl,请安装提供tunctl命令的软件包'uml-utilities'。您可以使用

添加新隧道
tunctl -t tun1

答案 1 :(得分:1)

使用以下脚本自动创建,只需将内容复制到file.sh,将“ETHOIPADDR”更改为您的IP地址,同样也可以更改网关和广播地址,并使用sudo权限运行脚本。

#!/bin/sh 
# 
# script to bring up the tun device in QEMU in bridged mode 
# first parameter is name of tap device (e.g. tap0)
#
# some constants specific to the local host - change to suit your host
#
ETH0IPADDR=192.168.0.3
GATEWAY=192.168.0.1
BROADCAST=192.168.0.255
#
# First take eth0 down, then bring it up with IP address 0.0.0.0 
#
/sbin/ifdown eth0
/sbin/ifconfig eth0 0.0.0.0 promisc up
#
# Bring up the tap device (name specified as first argument, by QEMU)
#
/usr/sbin/openvpn --mktun --dev $1 --user `id -un`
/sbin/ifconfig $1 0.0.0.0 promisc up
#
# create the bridge between eth0 and the tap device
#
/usr/sbin/brctl addbr br0
/usr/sbin/brctl addif br0 eth0
/usr/sbin/brctl addif br0 $1
# 
# only a single bridge so loops are not possible, turn off spanning tree protocol
#
/usr/sbin/brctl stp br0 off 
# 
# Bring up the bridge with ETH0IPADDR and add the default route 
#
/sbin/ifconfig br0 $ETH0IPADDR netmask 255.255.255.0 broadcast $BROADCAST
/sbin/route add default gw $GATEWAY
#
# stop firewall - comment this out if you don't use Firestarter
#
/sbin/service firestarter stop