4

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, the interfaces 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.

5 Answers5

2

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
  • In /etc/resolv.conf is a warning message, and I quote DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN – boggy Apr 02 '18 at 20:20
  • 1
    As @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 Apr 04 '18 at 04:33
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
zx485
  • 2,426
Asser Yehia
  • 121
  • 3
  • Thanks 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 – user965586 May 14 '20 at 06:27
0

Maybe try my answer to this question (DNS set to systemd's 127.0.0.53 - how to change permanently?). It involves installing the package resolvconf and how you can use it to add something permanent to resolv.conf.
Lines that need to be at the start of resolv.conf can be put in file /etc/resolvconf/resolv.conf.d/head.

oscar1919
  • 1,707
  • Tried your answer...it broke my ability to load pages and I had to reconfigure resolvconf. I can now see a nameserver 1.0.0.1 entry in /run/resolvconf/resolv.conf but I don't think this is working, testing via https://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 Apr 22 '18 at 16:27
0

https://help.ubuntu.com/16.04/ubuntu-help/net-wireless-edit-connection.html

Automatic (DHCP) Get information like the IP address and DNS server to use from a DHCP server. A DHCP server is a computer (or other device, like a router) connected to the network which decides which network settings your computer should have - when you first connect to the network, you will automatically be assigned the correct settings. Most networks use DHCP.

Automatic (DHCP) addresses only If you choose this setting, your computer will get its IP address from a DHCP server, but you will have to manually define other details (like which DNS server to use).

Use the network gui in the bar.

  • click "Edit Connections"
  • highlight the network interface you're using and click "Edit"
  • click the "IPv4 Settings" tab
  • change "Method" to "Automatic (DHCP) addresses only"
  • change "DNS servers" to 1.1.1.1 1.0.0.1 8.8.8.8 (space separated ip addys)
  • reboot computer

If you leave the "Method" on "Automatic (DHCP)", your computer will just use the DNS given by whatever DHCP server gave you your ip addy.

  • this 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 Sep 23 '18 at 12:18
  • It 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 ^_^ – Tuananhcwrs Jan 23 '21 at 05:55
0

All of the above are workarounds really. In Ubuntu 17.10 they changed to netplan to manage networks.

for desktop it is now netplan/networkmanager for server (headerless) it is now netplan/networkd

So basically anything you have edited in the past doesn't really work anymore. To make life more confusing it is all still there, and editing it can just add further layers of problem (that's experience talking). Once I just started working with only the netplan stuff, everything started to work again.

As far as I understand you now edit gui from within the gui (I don't use the gui), if you google ubuntu 18.04 static ip netplan networkd you will probably find what you are looking for. I have only just discovered most of this, and I am still not 100% sure how it all works, which is why I have not told you how I setup my network stuff. Bad advise only makes things worse.

My key info was found here: https://websiteforstudents.com/configure-static-ip-addresses-on-ubuntu-18-04-beta/

Hope this helps.

  • That'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 – user965586 May 13 '18 at 19:41
  • It 18.04 server I am using (upgraded from 17.10), I hope it helps. So far so good for me. – Netspud2K May 14 '18 at 03:20