18.04 with latest updates.
I am trying to modify my /etc/hosts
file so I can access my local server via its hostname.
I make the change with sudo nano /etc/hosts
, and it sticks fine for the current session. However, after rebooting my system or suspending it, the file reverts itself back to the state it was in before I edited it.
I have attempted to edit using both the terminal in a graphical session as well as from a tty prompt on a fresh boot with no avail.
This has only started happening since a new router was installed in my homes network, however I cannot see why that would cause this issue.
$ ls -al /etc/hosts
-rw-r--r-- 1 root root 254 Jan 20 17:03 /etc/hosts
The file is overwritten by
systemd-resolved.service
, among other files:According to documentation for
/etc/systemd/resolved.conf
and the related post, you can edit/etc/systemd/resolved.conf
to have specific domain resolved by your local DNS sever (on Ubuntu you have dnsmasq, example), or addReadEtcHosts=
to let the service actually use the file.You can also disable the service. See How to disable systemd-resolved in Ubuntu?
According to a Fedora forum thread the issue could also relate to Network Manager service. For Ubuntu servers, cloud-init could also be the cause of the issue according to the bug report on launchpad