Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 mydomain.local?


Before reboot I edit /etc/hosts:       localhost.localdomain   localhost  mydomain.local

After reboot       localhost.localdomain   localhost
share|improve this question
up vote 2 down vote accepted

/etc/hosts should look like this:       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
share|improve this answer
yep it looks okey, but it will be rewrited automatically to default after rebooting, so all my edits will be removed – fl00r Mar 15 '11 at 9:04
Does it revert to 'localhost'? – Bart De Vos Mar 15 '11 at 9:09
it reverts localhost.localdomain localhost – fl00r Mar 15 '11 at 9:14
Actually putting mydomain.local to /etc/hostname helps. Now /etc/hosts still rewrites but it adds mydomain.local to ::1 ... line. Thanx! – fl00r Mar 15 '11 at 9:17

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

share|improve this answer

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


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.