guru
guru

Reputation: 11

writing data to linux tun interface

i have created a linux tun interface, set ipaddr, broadcast etc.. using open/ioctl apis. This is how the tun interface looks like,

TEST_TUN: mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 500 link/none inet 45.45.45.1/24 scope global TEST_TUN valid_lft forever preferred_lft forever

Any message written by a virtual host(binded on addr 45.45.45.1:udp=7070) is received by tun_fd(fd returned during tun device creation).

If tun_fd writes an msg ( IP(dst=45.45.45.1)+transport(udp_dst=7070)+payload) is not received on the virtual host. wireshark capture shows that the packet is being received on the kernel side, but virtual host doesnot received any packet.

what could be the reasons for kernel not forwarding the packet to virtual host ?

Upvotes: 0

Views: 1116

Answers (1)

Jarvis__-_-__
Jarvis__-_-__

Reputation: 242

Had turned your tun device in up state?

if not then you can simply do that via..

$sudo ifconfig tun0 up

and you also can do that via ioctle commands..

if your device is already in a up state then you linux destro must have forwarding on.. you can do this via..

#echo "1" > /proc/sys/net/ipv4/ip_forwarding

or

$sudo sysctl net.ipv4.ip_forward=1
$sudo sysctl -p

then it comes to routing rules..you must have to set routing rule so that all the traffic is captured via your virtual interface..

$sudo ip route 128/1 dev tun

this command will add a route in you kernel routing table and all the traffic will flow through your virtual interface..

If I understood you correctly then may be this will be helpful for you..

Upvotes: 1

Related Questions