0

I've added some local domains to my /etc/hosts on Ubuntu. But it rewrites it every time I reboot OS.

How and where can I add constantly my 127.0.0.1 mydomain.local?

UPD

Before reboot I edit /etc/hosts:

127.0.0.1       localhost.localdomain   localhost  mydomain.local

After reboot

127.0.0.1       localhost.localdomain   localhost
JdeBP
  • 3,990
  • 18
  • 17
fl00r
  • 575
  • 2
  • 7
  • 20

3 Answers3

3

This is caused by a bug in Ubuntu NetworkManager and there is a workaround which is detailed in this document.

user9517
  • 115,471
  • 20
  • 215
  • 297
2

/etc/hosts should look like this:

127.0.0.1       hostname.domain.local hostname localhost

Also, put your hostname in /etc/hostname

If some other program (like networkmanager) keeps changing your hostfile, you could make it imutable.

chattr +i /etc/hosts
Bart De Vos
  • 17,911
  • 6
  • 63
  • 82
1

Probably is because of NetworkManager. Did you tried

sudo chattr +i /etc/hosts

after modifications ? If is still not working try to remove write attribute from /etc/hosts.

sudo chmod -w /etc/hosts

Regards

Sacx
  • 2,581
  • 16
  • 13