Change DNS to Coudflare 1.1.1.1 on Ubuntu 17.10
Solution 1
You can change it from the cli.
- Edit resolv.conf:
sudo vi /etc/resolv.conf
- Add the new nameserver before any other server:
nameserver 1.1.1.1
- Save the file. See How to exit the Vim editor.
- Reload networking:
sudo service networking restart
Solution 2
Unfortunately setting /etc/resolv.conf
directly will not change the DNS permanently and everything will be overridden again after restart.You will have to install resolvconf in not already installed :
sudo apt update
sudo apt install resolvconf
Then check the status:
sudo systemctl status resolvconf.service
Now open the /etc/resolvconf/resolv.conf.d/head
configuration file and set the nameserver to cloudlfare:
sudo nano /etc/resolvconf/resolv.conf.d/head
Set nameserver 1.1.1.1
Finally, save your changes and restart the machine in order to take effect.
To validate after restart, check that the nameserver 1.1.1.1 is the first entry in /etc/resolv.conf
by
cat /etc/resolv.conf
Related videos on Youtube
user965586
Updated on September 18, 2022Comments
-
user965586 over 1 year
I'd like to take advantage of the recent Cloudflare 1.1.1.1 DNS service on my Ubuntu (17.10, will be on 18.04 LTS when it lands). I can not get the GUI instruction to work (changing the DNS using Network Manager) as the "Apply" button is always greyed out when a make the changes suggested by Cloudflare (it was never going to be that simple!).
So...I started looking into the other suggested option of editing
/etc/resolv.conf
. Having read about (and broke things!), I can see that/etc/resolv.conf
should not be edited manually. It currently looks like this:# This file is managed by man:systemd-resolved(8). Do not edit. # # 127.0.0.53 is the systemd-resolved stub resolver. # run "systemd-resolve --status" to see details about the actual nameservers. nameserver 127.0.0.53 search default
I think I should edit the
/etc/network/interfaces
file as noted in this answer. for me, theinterfaces
file looks like this:# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback
Given what I have read, should I just add a line to this file like this to account for the IPV4/6 addresses (using spaces to separate)?:
dns-nameservers 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001
and then reboot the system?
I'm asking first as I have already had to reconfigure resolv conf because I made changes that broke it. This is the first time I've done anything with DNS or even really understood why it would be good to make this change.
-
Organic Marble about 6 yearsDo you have a router? You could just change it there.
-
Thomas Ward about 6 yearsAre you using Network Manager or the kernel or
systemd
to manage your networtking?: -
user965586 about 6 yearsNo idea, how do I find out? I assumed that because the resolv.conf has the "systemd-resolved" warning/text it was that.
-
-
bogdan about 6 yearsIn /etc/resolv.conf is a warning message, and I quote
DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
-
user965586 about 6 yearsAs @bogdan says, you shouldn't edit this by hand. This is what I did mistakenly for time and it stop my ability to access the internet.
-
user965586 about 6 yearsTried your answer...it broke my ability to load pages and I had to reconfigure
resolvconf
. I can now see anameserver 1.0.0.1
entry in/run/resolvconf/resolv.conf
but I don't think this is working, testing via dnsleaktest.com with my VPN on I still see my ISP in the results. Perhaps I'll wait until 18.04 LTS and see if the GUI option is fixed. -
user965586 almost 6 yearsThat's very useful advice, I'll wait for 18.04 LTS to arrive as an update and come back to your link. I know I can update now, but I'll wait for the automatic updates
-
Netspud2K almost 6 yearsIt 18.04 server I am using (upgraded from 17.10), I hope it helps. So far so good for me.
-
user965586 over 5 yearsthis doesn't work for me. The GUI reports my DNS changes as you suggest but it makes no difference when I check. Also the option "Automatic (DHCP) addresses only" is only an option for the IPv6 Settings tab.
-
user965586 almost 4 yearsThanks for this, I'll give this a go. More than two years in this is still a live issue for me. I still get sporadic, what I think is, DNS issues. I'm now on 20.04 LTS if that makes any difference. Recently tried NextDNS on Ubuntu too, worked for a while then ran into issues so had to uninstall it, very strange
-
Tuananhcwrs over 3 yearsIt works for me somehow. After doing this (but I seperate IP by commas, not space. And that is true that only IPv6 has the "Automatic (DHCP) addresses only" so just take it) and running command "systemd-resolve --status | grep Current" I get the result is "Current DNS Server: 1.1.1.1". And I can connect to some sites at the mean time some not ^_^