1

I've set up an OpenVPN connection with an external server.

tun0 is the interface which is used for this connection:

user@mypc:~$ ifconfig tun0
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.8.0.6  P-t-P:10.8.0.5  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:100 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

In server side, the corresponding tun0 interface has the IP address 10.8.0.1. If I ping from one to another the packets are delivered successfully.

My routing table is shown below:

user@mypc:~$ ip r s 
default via 192.168.1.1 dev wlan0  proto static 
10.8.0.1 via 10.8.0.5 dev tun0 
10.8.0.5 dev tun0  proto kernel  scope link  src 10.8.0.6 
169.254.0.0/16 dev wlan0  scope link  metric 1000 
192.168.1.0/24 dev wlan0  proto kernel  scope link  src 192.168.1.4  metric 2 

My purpose is to connect to the internet via VPN. All traffic must pass first from the VPN server and then to the "outside world".

My question is: How can I make the whole external traffic pass only from the tun0 interface? Is it the default gateway that I have to change? or something else?

Thank you.

1 Answer 1

0

To be able to route all internet bound traffic through your VPN tunnel, you will need to change the default route to go through that VPN interface, which in your case is "10.8.0.5 dev tun0".

To do this you will need to type a command like this

ip route add default via 10.8.0.5

There may be some oddities with two default routes, and I am unsure as to the clean way to manage your default routes other than simply deleting and re-adding every time you want to set up your VPN connection again - depending on your client there may be settings for this or scripts you can put these commands in.

3
  • Thank you for your reply. When I proceed with the change you told me, I lose connectivity with 10.8.0.1, which is the IP of the VPN interface of my server, and I don't have external connectivity as well.
    – panos
    Apr 12, 2016 at 17:00
  • @user3213035 Isn't that what you want, all traffic to go through 10.8.0.5? No other external connectivity? Or do you mean you can't use the vpn at all...
    – Xen2050
    Apr 12, 2016 at 18:01
  • I mean that I can't use VPN at all. After the time my client connects to server, can't ping anywhere to the outside world...
    – panos
    Apr 17, 2016 at 8:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .