I've read that I should have nameserver 127.0.1.1
in my /etc/resolv.conf
file only if my machine has its own DNS server. Since it doesn't, having it causes problems. But no matter what I do I can not get rid of it!
Here are the things I've done so far:
- Adding
nameserver 192.168.1.3
to/etc/resolvconf/resolv.conf.d/base
file. (192.168.1.3 is our network's DNS). - Running:
sudo resolvconf --enable-updates
. - Running:
sudo resolvconf -u
. - Running:
sudo service network-manager restart
(just to make sure).
Yet when I open the /etc/resolv.conf
file it says: nameserver 127.0.1.1
! Does anyone have any idea what's wrong?
Please note that it's actually 127.0.1.1
! And I have no idea why it's not 127.0.0.1
!
Even when I update the /etc/resolv.conf
manually and change it to anything else, the sudo resolvconf -u
will revert it back to 127.0.1.1
! Where is this address coming from?
NetworkManager is the program which (via the resolvconf utility) inserts address
127.0.1.1
intoresolv.conf
. NM inserts that address if an only if it is configured to start an instance of the dnsmasq program to serve as a local forwarding nameserver. That dnsmasq instance listens for queries at address 127.0.1.1.If you do not want to use a local forwarding nameserver then configure NetworkManager not to start a dnsmasq instance and not to insert that address. In
/etc/NetworkManager/NetworkManager.conf
comment out the linedns=dnsmasq
and restart the NetworkManager service.
In this mode, NetworkManager updates
/etc/resolv.conf
(still via resolvconf) to include the nameserver addresses NetworkManager has for active connections.If you want to disable the resolvconf mechanism for updating resolv.conf and just use a static resolv.conf file, do the following.
It is possible that resolvconf is misconfigured. This is especially likely if you have been playing around with its configuration files without really understanding how resolvconf and NetworkManager work.
For background information, please read the resolvconf documentation and Stéphane Graber's blog post.
https://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/
First you should know that both Ubuntu Desktop and Ubuntu Server by default have resolvconf installed and activated. Resolvconf provides a framework for dynamically updating the /etc/resolv.conf file in an orderly and reversible way.
Second you should know that Ubuntu Desktop by default has NetworkManager installed and activated. By default NetworkManager starts an instance of dnsmasq to serve as a local forwarding nameserver. This NetworkManager-controlled dnsmasq instance listens for queries at 127.0.1.1. When NetworkManager starts the dnsmasq instance it tells resolvconf to insert the address
127.0.1.1
into resolv.conf. As mentioned in another answer, if you configure NetworkManager not to start a local forwarding nameserver instance then it will not start a local forwarding nameserver and will not tell resolvconf to insert the address127.0.1.1
into resolv.conf.This default configuration works properly, so unless your situation is special you should restore the default configuration.
To restore the default configuration, see to it that
#
character../run/resolvconf/resolv.conf
To achieve this, execute the following commands.
The original configuration of NetworkManager is to have
in /etc/NetworkManager/NetworkManager.conf. It is a reasonable choice to disable the NetworkManager-controlled local forwarding nameserver by commenting out the
dns=dnsmasq
line.After doing all this it is advisable to restart the machine in order to clear out stale nameserver information records.
In my case there was no
dns=dnsmasq
line in/etc/NetworkManager/NetworkManager.conf
file and/etc/resolv.conf
was still overwritten by Network Manager to have onlynameserver 127.0.1.1
The fix was to restore a symlink for proper updating:
Ubuntu 16.04 + Ubuntu 18.04 Server - Configure /etc/resolv.conf to persist after reboot
On an Ubuntu 16.04 server, there is no
/etc/NetworkManager/NetworkManager.conf
file.Executing the following command will show you that the
/etc/resolv.conf
file is linked to the/run/resolvconf/resolv.conf
file:sudo ls -la /etc/resolv.conf
Remove this file and regenerate it:
Now you will see that the link is no longer there and your static
/etc/resolv.conf
file is present.sudo ls -la /etc/resolv.conf
Now to configure resolvconf NOT to regenerate the default
/etc/resolv.conf
file so your static file persists after reboot, execute the following command:sudo dpkg-reconfigure resolvconf
ON the first screen, hit your tab button to select
NO
ON the second screen, press your tab key to select OK and hit enter.
Your
/etc/resolv.conf
file will persist after rebooting your server.Ubuntu 18.04 Server
If you add ips to your
/etc/netplan/50-cloud-init.yaml
file, more than likely you'll have to apply your new settings withnetplan apply
ornetplan --debug apply
. Doing this will recreate the/etc/resolve.conf
link back to../run/resolvconf/resolv.conf
. If this happens, simplyrm -f /etc/resolv.conf
and recreate it as outlined above.Now you need to
chattr
the file like so:chattr +i /etc/resolv.conf
Your
/etc/resolv.conf
file will persist after rebooting your server.If you need to edit the file, remember to reverse the
chattr
like so:chattr -i /etc/resolv.conf
Now you can edit the
/etc/resolve.cfg