The idea for this article started after hearing TWiT Security Now podcast, episode Quad Nine where Steve Gibson and Leo Laporte talk about what they described as a ‘very appealing and speedy new alternative DNS service, called Quad9.’
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 VPN1 with the OpenVPN app2 and I configured my .ovpn file to uses a specific DNS every time it connects to the VPN network by adding the following line:
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:
dhcp-option DNS X.X.X.X dhcp-option DNS X.X.X.X
Now, no matter what DNS provider you use, whether it’s Google DNS3, OpenDNS4 or the brand new Quad9 DNS5 by IBM or 18.104.22.168 DNS6 by Cloudflare, with this “hack” you’ll be able to Set DNS Automatically While Using OpenVPN and continue doing your things online.