Ahmet ALMAZ Doom Face

Ahmet ALMAZ

Full Stack Developer from Türkiye 🇹🇷

Set DNS Automatically Using OpenVPN

/ 2 min / 317 words / --- views

The idea for this article started after hearing twit.tvTWiT Security Now podcast , episode pca.stQuad Nine where twitter.comSteve Gibson and twitter.comLeo Laporte talk about what they described as a ‘very appealing and speedy new alternative DNS service, called www.quad9.netQuad9 .’

I wanted my DNS on all my devices to be set automatically without me having to re-configure it every time I join a new network.

As we all know, in iOS, you need to change your DNS records for each and every network. On Android, you need to change your IP settings first to static then write the IP manually. After that, you’d enter your preferred DNS for each and every network.

Well, shit. This is way too much work for something that should be quite easy and simple and more importantly, automatic. As in, set it and forget it.

If you use a VPN, as you should, then keep reading to learn How to Set DNS Automatically Using OpenVPN

What I did was take advantage of the fact that I use a VPN 1 with the OpenVPN app 2 and I configured my .ovpn file to uses a specific DNS every time it connects to the VPN network by adding the following line:

Terminal window
dhcp-option DNS X.X.X.X

Voilà. You’re good to go.

Test it, you should see that the DNS is now automatically being set to the one you added.

If you want to add something like Google DNS or OpenDNS which contains a primary and secondary DNS record, all you have to do is add that same line a second time with the second DNS record. Like this:

Terminal window
dhcp-option DNS X.X.X.X
dhcp-option DNS X.X.X.X

# Conclusion:

Now, no matter what DNS provider you use, whether it’s developers.google.comGoogle DNS , www.opendns.comOpenDNS or the brand new www.quad9.netQuad9 DNS by IBM or 1.1.1.11.1.1.1 DNS by Cloudflare, with this hack you’ll be able to Set DNS Automatically While Using OpenVPN and continue doing your things online.

# Footnotes

  1. I’ve been using torguard.netTorGuard for 2 years now without any issues.

  2. itunes.apple.comiOS and play.google.comAndroid