Linux – Cannot route traffic through OpenVPN interface

iptableslinuxnetworkingopenvpnvpn

I have setup an OpenVPN server I want to connect to from my Mac at home. It was fairly painless and both the client and server are setup properly. The client can connect to the server just fine.

I am trying to route ALL my Internet traffic through the VPN when I'm connected to it. I did my homework and found that I need to use push "redirect-gateway def1" on the server. When I do so, I get "No route to host" when I curl any URL from the client. My SSH session with the server stays alive, however.

Here are my server and client config. What am I missing?

## SERVER
port 1194
proto udp
dev tun
ca /etc/openvpn/keys/ca.crt
cert /etc/openvpn/keys/server.crt
key /etc/openvpn/keys/server.key  # This file should be kept secret
dh /etc/openvpn/keys/dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
log-append  /var/log/openvpn.log
verb 3
;push "redirect-gateway def1"

## CLIENT
client
dev tun
proto udp
remote vpn.example.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert openvpn.crt
key openvpn.key
comp-lzo
verb 3

Best Answer

A friend just helped me with this.

Running the following 2 commands on the server worked:

echo  1 > /proc/sys/net/ipv4/ip_forward
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE

I hope it helps someone!