Difference between revisions of "tun/tap driver"

From Noah.org
Jump to navigationJump to search
m
m
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Engineering]]
 
[[Category:Engineering]]
 +
 +
There are two ways to create tuntap interfaces. They can be created with '''ip''' or with '''tunctl''' (part of  uml-utilities).
  
 
<pre>
 
<pre>
Line 11: Line 13:
 
brctl addif br0 eth0
 
brctl addif br0 eth0
 
brctl addif br0 tap0
 
brctl addif br0 tap0
 +
</pre>
 +
 +
== enable routing in Linux ==
 +
 +
The kernel needs to be told to forward IP packets.
 +
<pre>
 +
# cat /proc/sys/net/ipv4/ip_forward
 +
0
 +
# sysctl net.ipv4.ip_forward
 +
net.ipv4.ip_forward = 0
 +
# echo 1 > /proc/sys/net/ipv4/ip_forward
 +
# cat /proc/sys/net/ipv4/ip_forward
 +
1
 +
</pre>
 +
 +
IPTables needs to be setup to do the actual routing between interfaces.
 +
<pre>
 +
iptables -A INPUT -i tap0 -j ACCEPT
 +
iptables -A INPUT -i br0 -j ACCEPT
 +
iptables -A FORWARD -i br0 -j ACCEPT
 
</pre>
 
</pre>

Latest revision as of 10:54, 9 May 2013


There are two ways to create tuntap interfaces. They can be created with ip or with tunctl (part of uml-utilities).

# ip tuntap del tap0 mode tap
# ip tuntap add tun0 mode tun
ip tuntap add tap0 mode tap
ip link set tap0 up
ip addr add 192.168.0.2/24 dev tap0
brctl addbr br0
ip link set br0 up
brctl addif br0 eth0
brctl addif br0 tap0

enable routing in Linux

The kernel needs to be told to forward IP packets.

# cat /proc/sys/net/ipv4/ip_forward
0
# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
# echo 1 > /proc/sys/net/ipv4/ip_forward
# cat /proc/sys/net/ipv4/ip_forward
1

IPTables needs to be setup to do the actual routing between interfaces.

iptables -A INPUT -i tap0 -j ACCEPT
iptables -A INPUT -i br0 -j ACCEPT
iptables -A FORWARD -i br0 -j ACCEPT