Setting custom DNS servers on Linux can increase performance, security and even thwart some websites using Geo-blocking via DNS. There are two ways to accomplish this: via Network Manager GUI that is included in many Linux distros like Debian, Ubuntu and derivatives, or via resolv.conf (not directly, but via the head file) and I’ll show you how to do both in this guide.
FYI: The resolv.conf file is overwritten on each boot so we can’t edit this file directly, but we can edit one of the two files used to create the resolv.conf file, those being the head and base files located in /etc/resolvconf/resolv.conf.d/. We’ll be editing the head file in the second part of this guide so that each and every boot-up, resolv.conf gets written with our custom DNS servers at the top.
Before changing DNS servers you’ll also need to find a third-party DNS provider, there are plenty of good (and free) services available too. I personally recommend Google DNS which is what I use and have never had an issue. I will list here the most popular DNS providers:
- Primary IPv4: 8.8.8.8
- Secondary IPv4: 8.8.4.4
- Preferred IPv6: 2001:4860:4860::8888
- Alternate IPv6: 2001:4860:4860::8844
- OPENDNS
- Primary: 208.67.222.222
- Secondary: 208.67.220.220
- Preferred IPv6: 2620:0:ccc::2
- Alternate IPv6: 2620:0:ccd::2
- DNS.WATCH
- Primary: 84.200.69.80
- Secondary: 84.200.70.40
- LEVEL3
- Primary: 209.244.0.3
- Secondary: 209.244.0.4
- NORTON
- Primary: 199.85.126.10
- Secondary: 199.85.127.10
- COMMODO
- Primary: 8.26.56.26
- Secondary: 8.20.247.20
- VERISIGN
- Primary: 64.6.64.6
- Secondary: 64.6.65.6
- MORE SERVERS…
- See: Free and Public DNS Servers
- See: Public DNS Server List (extensive)
Watch the video above or follow the text guide below.
Set custom DNS servers on Linux with Network Manager
- Click on Network icon top-right of your screen, then click the Edit Connections

- Select your connection (may be wired or wireless), then click Edit button

- Click on IPv4 Settings tab, if Method is set to Automatic (DHCP) change it to Automatic (DHCP) addresses only, if Method is set to anything else, leave as is. Next enter your primary and secondary DNS server IP addresses separated by a comma, then click Save button

- (Optional) Click on IPv6 Settings tab, if Method is set to Automatic change it to Automatic, addresses only, if Method is set to anything else, leave as is. Next enter your primary and secondary DNS server IP addresses separated by a comma, then click Save button

- Finally click Close button to exit
- Ubuntu doesn’t cache DNS so we don’t need to flush it, but other distributions might. Just search for "[distro_name] flush DNS cache" to find instructions on how to do it
- All done!
Set custom DNS servers on Linux using resolv.conf
- Click the Search icon, type in "Terminal" then click the Terminal application

- Now type in the following command:
sudo nano /etc/resolvconf/resolv.conf.d/headand hit Enter
- Just after the comments, type
nameserver 8.8.8.8(or your desired primary DNS server IP address) then on the next line, typenameserver 8.8.4.4(or your desired secondary DNS server IP address). Now press Ctrl + O to save, then Ctrl + X to exit.
- At the command prompt, type
sudo resolvconf --enable-updatesand hit Enter
- Now type
sudo resolvconf -uand hit Enter then close the Terminal application
- Ubuntu doesn’t cache DNS so we don’t need to flush it, but other distributions might. Just search for "[distro_name] flush DNS cache" to find instructions on how to do it
- All done!
- Ubuntu (official)
- Ask Ubuntu (official Ubuntu Q & A)
- Debian (official)
- Debian Admin Handbook – Domain Name Servers (DNS)
- How To Flush Linux / UNIX DNS Cache
- Linux Network Manager at Wikipedia.org
- Linux Network Manager at Archlinux.org
Leave a comment