I've recently upgraded to 17.10. When I try to browse to a website, or ping a domain it fails saying the site cannot be resolved.
network-admin
shows the contents of /etc/resolv.conf
to be nameserver: 127.0.0.53
If I change that to 8.8.8.8 or 208.67.222.222 then everything works. Until I reboot.
Upon reboot or resume, the nameserver is reset to 127.0.0.53.
How do I permanently set the nameserver to something that works?
For systemd fans, if I run systemd-resolve --status
I get
Link 3 (wlo1)
Current Scopes: LLMNR/IPv4 LLMNR/IPv6
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
If I follow the advice at this question - DNS keeps resetting after reboot. Ubuntu 17.10 - DNS still fails to resolve.
You can install a package resolvconf, which will modify the way
/etc/resolv.conf
is built up at system boot.You can then create or modify a file
/etc/resolvconf/resolv.conf.d/tail
. If you put in this file a linenameserver 8.8.8.8
, this line will be added at the end of/run/resolvconf/resolv.conf
at boot./etc/resolv.conf
will now be a symbolic link to this file.Post Scriptum:
Almost two years after posting my answer I came across https://bugs.launchpad.net/ubuntu/+source/ppp/+bug/1778946 which explains exactly why merely installing
resolvconf
solved a dns problem I had at the time. I feel I have to share this here.According that bug report, after a pptp VPN goes down,
resolv.conf
is restored with the wrong access rights.ping ubuntu.com
does not work,sudo ping ubuntu.com
does. Installingresolvconf
solved it, because it takes overresolv.conf
, restoring it with correct rights. Changingsystemd-resolve
settings is no solution in this case, since the bug is inppp
. But an alternative, maybe simpler solution issudo chmod a+r /etc/resolv.conf
after VPN down. And this can be automated by putting an executable script in /etc/NetworkManager/dispatcher.d with contents:In all cases the contents of
resolv.conf
do not change. And, yes, I know pptp must be avoided because of security issues, but at the time I thought of it as a good excercise for an ubuntu newbie. I imagined it would work out of the box. Little did I know that it would give me a headache, as diagnosed so well by @intelfx.The correct solution would be to fix systemd-resolved instead of trying to cure migraine with a guillotine.
It is a nice tool, really, if used properly.
Judging by your
systemd-resolve --status
output......your network manager tool does not communicate per-interface DNS configuration to systemd-resolved.
Recent versions of NetworkManager will detect if
/etc/resolv.conf
is a symlink to a resolved-generated file (/run/systemd/resolve/*.conf
or/usr/lib/systemd/resolv.conf
) and if that's the case, communicate with resolved directly.Alternatively, recent versions of systemd-resolved try to be compatible with the historical resolvconf interface by installing a
resolvconf
binary that does the right thing.While either of these two solutions would be preferred, if you are looking for a quick and dirty fix, you can just configure systemd-resolved to use your DNS servers globally:
Then restart
systemd-resolved.service
or reboot.working within the
systemd
paradigm add a DNS to a link / deviceusing ubuntu 17.10+ add a
*.network
file:sudo nano /lib/systemd/network/100-somecustom.network
:100-somecustom.network ( 100 can be any number for priority, and it requires the
.network
file extension ):Then restart:
Also look into:
Then check:
From info page
info systemd.network
:Another approach disable the
DNSStubListener
for usage withdnsmasq
:sudo nano /etc/systemd/resolved.conf
:related:
I use Lubuntu & Kubuntu 18.04. I was able to overcome the DNS problem in 2 steps:
First step: Install
unbound
and set it to replacesystemd-resolved
as Grégoire C shows here.reboot
Open as root the file
/etc/NetworkManager/NetworkManager.conf
(
sudo leafpad /etc/NetworkManager/NetworkManager.conf
in Lubuntu 18.04 or in Kubuntu 18.04SUDO_EDITOR=kate sudoedit /etc/NetworkManager/NetworkManager.conf
)and below
[main]
put this line:reboot again
Second step: If after the reboot the problem is still not solved, as it was in my case, start the file manager as root, go to
/etc
, deleteresolv.conf
and create a newresolv.conf
. Leave it empty and reboot the OS. In my case after this reboot the problem disappeared.In Kubuntu 18.04 you can't start Dolphin as root, so you can first go to
/etc
and open the terminal from there, then typesudo su
and press Enter to use it as root and then deleteresolv.conf
with the commandrm resolv.conf
. Then you can create a new empty file on your desktop, name itresolv.conf
and open a terminal from there. Use thesudo su
command to enter the root mode for the terminal and then copy the newresolv.conf
from your desktop to/etc
with the commandcp resolv.conf /etc
.I have to add that I did not try to do the second step before installing
unbound
, so the next time I will do so, just to see if it will be enough or not.I'm using Ubuntu 18.04 LTS. I don't know how my OS came into this problem in a sudden while my DNS had been working well for months. Here is my solution:
Install resolvconf
$ sudo apt install resolvconf
Find the source of
/etc/resolv.conf
.$ ls -al /etc/resolv.conf
shows that/etc/resolv.conf
is a symbolic link of/run/resolvconf/resolv.conf
And I found that: This file
/run/resolvconf/resolv.conf
is composed of:$ cat /run/resolvconf/interface/systemd-resolved
showsnameserver 127.0.0.53
, which would be reset after reboot.Add DNS
It seems that
nameserver <my DNS>
needs to be in front ofnameserver 127.0.0.53
so that it could work.So I add
nameserver <my DNS>
at the end of/etc/resolvconf/resolv.conf.d/head
.Update resolvconf
$ sudo resolvconf -u
This is how I change my dns record on the interface configuration.
Change name server addresses, previously it was .4 then I changed it to .3:
Save the configuration and then apply the configuration:
After that restart the resolvectl service.
For notes: I did reboot the server, and changes that I made were still intact. I use the
resolvectl dns
command to verify the dns record.Had some issues with NordVPN so decided to add to this.
Findings:
NordVPN sets
/run/systemd/resolve/resolv.conf
DNS settings when connecting.NordVPN removes all DNS settings from
/run/systemd/resolve/resolv.conf
when disconnecting.This causes DNS server to no longer work (since there isn't one set).
The system needs a reboot to set it back to anything at all. A standard restart of the service (
sudo systemctl restart systemd-resolved.service
) does not work.The solution to work around this:
Head over to /etc/resolvconf/resolv.conf.d/
Add nameservers
Check following places for nameservers that could have been set:
Test which DNS servers are being used with:
Maybe a bit late, but I ran into this problem. I do have to admit that I have been manually configuring my network settings via cli before and not via the inbuilt networkmanager. I run ubuntu 18.04.
So after I disabled and then re-enabled systemd.resolved.service, this erratic behaviour of randomly losing my DNS configuration was solved for me.
after reboot:
I am a relatively fresh Linux user so there must be someone that can explain the hows and why's of why this would have worked for me, but it seemed worth to mention if it can help others.
In case you want to manage the file /etc/resolv.conf manually "man NetworkManager.conf" provides the answer.
In /etc/NetworkManager/NetworkManager.conf, section [main] add: dns=none
also make sure /etc/resolv.conf is a file, not a symlink. Your changes will survive system reboot.
Most answers are unfortunately wrong or unnecessary workarounds.
I think you just missed something pretty serious.
install nmap and then run nmap 127.0.0.1, then 127.0.0.53 They have different a list of services, something is definitely listening and hiding in another ip trying to look like localhost. Then the computer is pointing to this address rather than the actual dns server... and resolving... but I did not install any dns server...
I'm looking into what that is... localhost subnet is only supposed to have 127.0.0.1 if I remember correctly.
It sounds like a possible hack to get around firewalls. My firewall was on and rejecting incoming and outgoing, but my outgoing should have been to one ip. My actual dns to work...