Hello everybody,
I've set up OpenVPN on a Debian server and also on my Ubuntu machine, and now I'm trying to route all traffic (except DHCP) at client-side through the OpenVPN tunnel. I read a lot of guides (find a list of them in the bottom of this post), but none of them resolved the problem. If I use
redirect-gateway def1
in client.conf (or push it from server-side [server.conf] to the client), at client-side I cannot resolve domain names to IP addresses (basically DNS queries fail), but I can ping public (valid) IPs e.g. Google's DNS server (from my client machine).
Here is my server.conf:
proto udp
port 1194
dev tun
ca ca.crt
cert myserver.crt
key myserver.key
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
duplicate-cn
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
log openvpn.log
verb 3
And here's my client.conf:
client
dev tun
proto udp
remote x.x.x.x 1194
nobind
persist-key
persist-tun
mute-replay-warnings
ca ca.crt
cert client1.crt
key client1.key
ns-cert-type server
comp-lzo
verb 3
redirect-gateway def1 bypass-dns bypass-dhcp
On the server side, I also issued the following command (to NAT the incoming OpenVPN traffic):
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
NOTE:
If I use the following command at server side (redirecting DNS queries), the problem gets resolved (apparently), but how can I make sure that the traffic is going through the VPN link?
iptables -t nat -A PREROUTING -i tun+ -p udp --dport 53 -j DNAT --to-destination 8.8.8.8
(source:
http://stackoverflow.com/questions/2541161/redirect-gateway-def1)
Here is my log:
http://pastebin.com/czuAd1CW
and openvpn-status. log:
http://pastebin.com/ZWpJ6fEx
PS:
I read these guides and articles:
https://help.ubuntu.com/13.10/serverguide/openvpn.html
https://openvpn.net/index.php/open-source/documentation/howto.html#redirect
https://forums.openvpn.net/topic14682.html
http://allanmcrae.com/2013/09/routing-traffic-with-openvpn/
http://www.unix.com/ip-networking/133401-help-route-all-traffic-through-openvpn-road-warrior-surf-web-anonymously-safely.html
http://stackoverflow.com/questions/2541161/redirect-gateway-def1
http://ubuntuforums.org/showthread.php?t=1798849
https://wiki.debian.org/OpenVPN
https://www.digitalocean.com/community/articles/how-to-setup-and-configure-an-openvpn-server-on-debian-6