Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have a server with the public ip address of (for example). This server is running an openvpn server, plus a bunch of other stuff that is listening on the public ip network device ports.

What I want to do is once connecting to, route all future traffic to this IP via the VPN.

So for example if I curl it goes via the VPN connection.

I've tried adding a push route to my server.conf like so:

push "route"

and I even tried adding an exclusion route:

push "route net_gateway"

but I didn't seem to work. running sudo route -n still showed the route going via my home router:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 wlan0 UGH   0      0        0 tun0 UH    0      0        0 tun0 UGH   0      0        0 wlan0   U     9      0        0 wlan0

Any thoughts on how I can accomplish this? I figured the problem was likely the fact that I'm trying to route traffic to the vpn server itself, via the vpn server, and thus forming some sort of infinite loop, but that's just a guess.

share|improve this question

The routing table you displayed clearly does not route all traffic through the VPN, as shown by the very first line. In its present configuration, all it does is allow the client to have access to the LAN.

The command to route all client traffic through the OpenVPN, including all traffic to third parties (i.e., not the VPN server's LAN) is

  push "redirect-gateway def1"

which is to be added to the server configuration file (you will need to restart the OpenVPN program, for the change to take effect).

Also, since you have setup a routed OpenVPN, not a bridged one, you will need to activate NATting on the server:

  iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE

This assumes that the interface of the OpenVPN server on the Internet (i.e. the one with IP address is called eth0. Please adjust accordingly.

To check on your configuration, once a connection to the OpenVPN server has been established, issue the following command:

 wget -O - -o /dev/null

This will output your apparent IP address. If the output contains, you are done.

share|improve this answer

Your Answer


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.