Redirect-gateway def1

I have OpenVPN installed on my server, and I can connect to it just fine, as well as browse the web, etc. from the client window. If I set the following parameter in the client setup, I can no longer view the website through the domain name:

redirect-gateway def1 

On the server, I ran the following command:

 iptables -t nat -s 10.8.0.0/24 -A POSTROUTING -j SNAT --to myserverIP 

but that didn’t change anything.

Can someone help suggest something?

+7
openvpn
source share
2 answers

Most likely, this is due to the fact that your DNS server is not located on your local subnet, and you are redefining the default gateway, so DNS queries are routed through a VPN connection. I can think of two fixes:

  • Specify the DNS server in your VPN configuration that is accessible through the VPN.
  • Add a specific route on the client to the network where the DNS server is located, since the default route is redefined by redirect-gateway .
+6
source share

Another option is to add the iptables rule to the PREROUTING table, so that all traffic coming from vpn directed to port 53 / udp is redirected to the DNS that you use on the server:

 iptables -t nat -A PREROUTING -i tun+ -p udp --dport 53 -j DNAT --to-destination 8.8.8.8 

The advantages of this option are that in Linux clients you do not need to deal with complex update-resolv-conf scripts, and in general you redefine but do not destroy the original default name server.

+7
source share

All Articles