Simple tun program to write and read data to a tun adapter
Assumes the following:
- Local tun adapter address is
192.168.40.1
- Destination for traffic is
192.168.40.2
ip link set tun0 up
ip address add 192.168.40.1/32 dev tun0
ip route add 192.168.40.2/32 dev tun0
ip route del 192.168.40.2/32 dev tun0
ip link set tun0 down
Run sysctl -w net.ipv4.ip_forward=1
to temporarily enable routing
Edit /etc/sysctl.conf
with the line net.ipv4.ip_forward = 1
to make routing persistant across reboots
Run sysctl -w net.ipv4.ip_forward=0
to temporarily enable routing
Edit /etc/sysctl.conf
with the line net.ipv4.ip_forward = 0
to make routing persistant across reboots
Simply echos back the data received by the tun to the sender but swaps the IP src and dst.
ping 192.168.40.2
will result in a reply- It will keep up with a flood ping (
sudo ping -f 192.168.40.2
) but buffers slightly - Ping won't work for non-local pings due to the "dumb" echo handler. It doesn't switch the echo/reply types.
- It will keep up with a flood ping (
- netcat will work with UDP
- Set up one terminal running
nc -u -l 1234
- Set up another terminal running
nc -u 192.168.40.2 1234
- You can watch messages from the second terminal show up in the first
- Set up one terminal running
- netcat doesn't completely work with TCP because of the "dumb" echo handler
- Set up one terminal running
nc -l 1234
- Set up another terminal running
nc 192.168.40.2 1234
- You can watch messages from the second terminal show up in the first
- Sending a file does not work becuase of the "dumb" echo handler
- Set up one terminal running
- You can run wireshark on the TUN adapter to see the traffic
tcpdump
ortshark
will also work