How to route traffic over the a tun0 device (IPSec VPN connection)

ipsecroutingtun

I've set up an IPSec VPN tunnel between my laptop and work. The tunnel gets established, but routing does not.

The relevant part of ifconfig is :

eth0      Link encap:Ethernet  HWaddr d4:be:d9:6f:a7:eb  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:20 Memory:f7d00000-f7d20000 

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:192.168.100.10  P-t-P:192.168.100.10  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 68:94:23:8e:82:0d  
          inet addr:192.168.1.73  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::6a94:23ff:fe8e:820d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20028 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15702 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:17288561 (17.2 MB)  TX bytes:2462845 (2.4 MB)

The relevant part of route -n is:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     9      0        0 wlan0

I'm using the IPSec/IKEv2 (strongswan) network manager plugin in Ubuntu to establish the connection.

Let's say I'd like all traffic to get routed over the tun0 device, how do I do that?

Best Answer

Take a look to this answer.. specially the part about the IPTABLES rules... I think it should solve your problem:

OpenVPN not default gateway for all traffic