Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I recently discovered the existence of Linux TUN/TAP interfaces and am still trying to understand them. I think I get the basic concept - pseudo devices are created which emulate a network interface and instead of passing data to hardware it is passed to a userspace program.

How would you direct an unrelated program to utilize this tunnel?

For example, before the tunnel is created my system only contains eth0 and lo, the normal ethernet interface (wired to my local network) and the loopback interface. After a program creates and configures a tunnel, I have a new interface gr0 which I gave an IP address that is on my local network, but not in use (so we are all on the same subnet). How would I make an unrelated program utilize this 'tunnel'? Say I had a simple Python message passing client/server app which utilizes a TCP connection, how could I configure it to use the tunnel?

I apologize if I am missing something basic, but as usual I have managed to confuse myself in the scheme of things. Again, all I want is to have a simple TCP program utilize this tunnel.

Thanks!

share|improve this question

1 Answer 1

up vote 5 down vote accepted

It's not always "tunnel". TUN/TAP is just specific NIC drivers. From point of view of network stack they acts as any other network interfaces: they can have IP addresses, can be point-to-point or broadcast interfaces. Routing rules also applies to them. But all traffic that gets written to one of that network interfaces goes to some userspace program for processing, and all data written by userspace program directly to /dev/tunX looks like incoming packets for network stack.

In usual tunneling setup server and client have TUN devices with assigned addresses. Routing tables configured on both of them directs needed traffic to this TUN devices. When packet get routed to tun0, kernel sends it to userspace program (client) that sends this packet to other program on remote machine (server) via, for example, TCP connection. On remote machine other program (server) recieves packet from client and writes it to it's own /dev/tunX device, "injecting" that packet into network stack. And tunneled packet gets processed as any other.

share|improve this answer
    
So the answer the (for my purposes) is to configure the routing table to direct traffic to these interfaces. That was the point that I am missing, but now I should be able to find a solution. Also, I appreciate the explanation as it clears things up. Thanks! –  Mr. Shickadance Mar 28 '11 at 19:33
1  
I ended up using "route add <TUN IP ADDR> dev gr0". This allowed me to redirect traffic through the new interface. Thanks again! –  Mr. Shickadance Mar 29 '11 at 12:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.