Ubuntu hosts resets on boot

R7AF
R7AF used Ask the Experts™
on
I recently upgraded to Ubuntu 10.10 on my desktop. Since then, the hosts file resets on boot. How can I fix it to stay like it was before the upgrade? Now I have to edit it each time after a reboot.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Have you tried setting it as "read only"?
Top Expert 2007

Author

Commented:
I can manually set each file to "read", but before the upgrade I didn't have to do anything. I want to copy those files without having to change the permissions afterwards.
Commented:
This is most likely a bug caused by the distribution upgrade; please check out these threads:
http://ubuntuforums.org/showthread.php?t=1596603
http://ubuntuforums.org/showthread.php?t=1598628

As it looks, a bug report is already under way.
What must have happened here is that in 10.10 the way network-manager deals with host files was slightly changed; this works well on new installations but has not yet been sufficiently tested on systems with customized host files.

Whether or not you will be able to profit from a bug fix once it comes, I cannot say. But for the time being, your only chance seems to be one of the following workarounds:

1. set the hosts file to 'chmod 444', i.e. remove the write permissions;
2. try to locate the template that network manager uses for overwriting the existing host file (look for it in /etc/default or run a search), then modify this template to fit your needs;
3. create a tiny shell script, containing basically a copy command, that will run on bootup and overwrite /etc/hosts by your host file.


ps:
Unfortunately, there is no way to guarantee 100% success for the dist-upgrade feature; it works in most cases, thus is very convenient for the users, but since "there are no two identical linux systems in the world", it may also fail in some respect, especially on highly customized installations.
That is why I have long stopped following the speedy upgrade cycle of distros like Ubuntu and Fedora that release two new versions every year. If possible, I only upgrade like once every two years. But should I be forced to use the dist-upgrade feature, it's a rule of thumb to upgrade no earlier than 3-4 months after release, when they had time to remove bugs from the upgrade routines.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Commented:
Sorry, I just see that in two instances my formulations aren't clear enough:

"this works well on new installations but has not yet been sufficiently tested on upgrading systems with customized host files."

"If possible, I only upgrade like once every two years - by means of a fresh clean installation."
Maybe a possible workaround..

Create a sym link to a copy of hosts..
ln -s  /etc/hosts.good  /etc/hosts

Open in new window

Top Expert 2007
Commented:
Yeah well you know what happened this morning? It worked without any problem! I'm going to wait another day or so, see what happens.

Thanks for the tips! I know I probably upgraded a bit too soon. In the upgrade process I got a few questions whether to keep certain config files or not. I don't remember which ones exactly, but this was one of them, and I kept the old one. Looking back it would have been wiser to have it replaced with the new config file. In the future I'll replace them after having made a backup.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial