Ubuntu

Aliases in /etc/hosts overwritten

Reported by David Megginson on 2010-10-13
136
This bug affects 27 people
Affects Status Importance Assigned to Milestone
network-manager (Ubuntu)
Low
Unassigned
Maverick
Undecided
Unassigned

Bug Description

Binary package hint: network-manager

---
WORKAROUND:
You can use aliases against another loopback address in the 127.x.y.z range, such as 127.1.1.z. Addresses within 127.0.y.z are rewritten by NM.
---
SRU JUSTIFICATION:
In its current state NetworkManager overwrites static entries placed in /etc/hosts, users requiring such aliases for Apache servers or whatnot cannot add them (except using the workaround above). This constitutes a regression from the Lucid release, as well as somewhat of an issue for upgrades.

This has been addressed in natty by cherry-picking a patch from the upstream stable git branch which corrects the issue: looking for entries not matching the known hostname and skipping them.

Regression potential is medium/low: users with the patch, in the event it was to break, would lose alias entries, or possibly the hosts entry for the interface's IP. However, standard loopback/localhost entries remain and are ignored.

TEST CASES:
1) Add a custom entry to /etc/hosts sending to the loopback address. e.g.

127.0.0.1 toto123

2) Click on nm-applet, then the already-establish connection to have it re-negotiated.

In the current version in maverick, network-manager removed the entry. With the patch applied, the entry is left intact.

---

I develop several web sites on my laptop, and each one is a different virtual host through Apache. Until Lucid, I was able to alias these hosts in /etc/hosts, like this

  127.0.0.1 localhost localhost.localdomain myhost1.localdomain myhost2.localdomain myhost3.localdomain

Starting with Maverick, however, NetworkManager overwrites the 127.0.0.1 line every time it initiates a new network connection, so these aliases are lost. It is fair to argue that aliasing 127.0.0.1 isn't ideal, but as far as I can find, NetworkManager doesn't offer any alternative for aliasing the bound IP address. For example, if I connect to WiFi, it adds a line like

  192.168.0.101 snape

There seems to be no way to get it to do

  192.168.0.101 snape myhost1.localdomain myhost2.localdomain myhost3.localdomain

NetworkManager should not overwrite the 127.0.0.1 line in /etc/hosts until there is an alternative method available for aliasing on the local machine, without setting up an entire local DNS server.

ProblemType: Bug
DistroRelease: Ubuntu 10.10
Package: network-manager 0.8.1+git.20100810t184654.ab580f4-0ubuntu2
ProcVersionSignature: Ubuntu 2.6.35-22.34-generic 2.6.35.4
Uname: Linux 2.6.35-22-generic x86_64
NonfreeKernelModules: fglrx wl
Architecture: amd64
CRDA: Error: [Errno 2] No such file or directory
Date: Wed Oct 13 08:22:07 2010
Gconf:

IfupdownConfig:
 auto lo
 iface lo inet loopback
InstallationMedia: Ubuntu 10.10 "Maverick Meerkat" - Release Candidate amd64 (20100928)
IpRoute:
 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.198 metric 1
 169.254.0.0/16 dev eth0 scope link metric 1000
 default via 192.168.0.1 dev eth0 proto static
Keyfiles: Error: [Errno 2] No such file or directory
ProcEnviron:
 PATH=(custom, user)
 LANG=en_CA.utf8
 SHELL=/bin/bash
RfKill:
 0: hp-wifi: Wireless LAN
  Soft blocked: no
  Hard blocked: no
SourcePackage: network-manager

Ralph Janke (txwikinger) on 2010-10-14
Changed in network-manager (Ubuntu):
status: New → Triaged
importance: Undecided → Low

Actually, there is a workaround, and that would be to use another 127.x.y.z address just for the aliases. Could you try setting up your aliases with say, 127.0.0.5 and letting us know whether it works fine for you (and doesn't get overwritten by NM).

This seems like a very valid use case though, and perhaps NetworkManager should be told to add hostname aliases as specified in a connection's settings. The issue you are reporting is an upstream one and it would be nice if somebody having it could send the bug to the developers of the software by following the instructions at https://wiki.ubuntu.com/Bugs/Upstream/GNOME. If you have done so, please tell us the number of the upstream bug (or the link), so we can add a bugwatch that will inform us about its status. Thanks in advance.

Great suggestion, Mathieu -- unfortunately, NM overwrote all the 127.0.0.n lines (not just 127.0.0.1), so back to the drawing board. I can't think of any way to do this without setting up a full DNS server just for my laptop. I'm betting there are a lot of other people doing web development who will discover the same problem.

This bit of NM behaviour was modified not because anything was wrong, but because someone wanted to enforce a rigid idea of how loopback is supposed to work, and erase anything in /etc/hosts that didn't match that idea. I hate solutions based on dogma instead of problem-solving.

Followup: while Networkmanager overwrote any 127.0.0.* address, I discovered that it will leave 127.1.1.* (etc.) alone, so I was able to add

  127.1.1.1 myhost1.localdomain
  127.1.1.2 myhost2.localdomain

etc. and not have it overwritten by NM. Thanks to Mathieu for the suggestion -- there *is* a workaround available now.

description: updated

There's a fix available upstream: http://cgit.freedesktop.org/NetworkManager/NetworkManager/patch/?id=ee9ce6027b3fc0cb4aa14442ef8b628b80b726eb

I'll try to get a package ready by end-of-day for testing in my PPA and in Natty, then we can consider updating this as a SRU.

Jean-Baptiste Lallement (jibel) wrote :

This bug looks close but if it's not completely the same. tell me and I'll open a new bug.

In my case eth0 is manually defined and N-M modifies the host in the following way
192.168.0.3 black # Added by NetworkManager
127.0.0.1 localhost.localdomain localhost
::1 black localhost6.localdomain6 localhost6

The last line is systematically added. That's problematic because this is a local dns based on DNSMasq which relies on /etc/hosts and resolving the name of the DNS must return its external IP not the IPv6 loopback address.
If I manually remove 'black' from the IPv6 line, it is readded sometime later.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package network-manager - 0.8.1+git.20100810t184654.ab580f4-0ubuntu3

---------------
network-manager (0.8.1+git.20100810t184654.ab580f4-0ubuntu3) natty; urgency=low

  [ Anders Kaseorg ]
  * Remove stale entries for the system hostname from /etc/hosts when
    bringing down interfaces. (LP: #632896)
    - Add debian/patches/lp632896_cleanup_etc_hosts.patch

  [ Mathieu Trudel-Lapierre ]
  * Don't overwrite aliases in /etc/hosts (LP: #659872)
    - add debian/patches/lp659872_dont_overwite_hosts_aliases_ee9ce60.patch
    - update debian/patches/series
 -- Mathieu Trudel-Lapierre <email address hidden> Tue, 19 Oct 2010 16:04:00 -0400

Changed in network-manager (Ubuntu):
status: Triaged → Fix Released

Jean-Baptiste,

To me it looks like a different issue specific to IPv6 after all. In reality, you probably shouldn't even have this new IPv6 entry in /etc/hosts if your system is set to Ignore for IPv6 in NM. Can you please open a bug for that and report the number here just so we can track this? I'll start writing a patch to bypass setting this alias when IPv6 is set to Ignore.

description: updated
Ahdong (ahdong-com) wrote :

I met the same problem today, So I added my own line after 127.0.1.1.

Mark Alan (malan) wrote :

Same problem here.
I am using a line starting with a 127.1.1.1 to keep my local host names.

Dave M G (martin-autotelic) wrote :

Hello. I started a thread some time ago on the Ubuntu forums about this issue:
http://ubuntuforums.org/showthread.php?t=1596603&page=2

Through responses on that thread, I eventually came here.

I have two computers, and on one this bug seems to no longer be an issue. However, on my other computer, my /etc/hosts file continues to be over written with every reboot.

So I am confused as to whether a fix/patch has been released or not.

I'm hoping a more consistent and logical solution will be offered instead of using different loopback addresses as a workaround.

Gray Bowman (gray-bowman) wrote :

I was just bitten by this, today, on a fully updated machine. I was able to use the 127.1.1.1 workaround, but would prefer a real fix.

Thanks!

StephanBeal (sgbeal) wrote :

Aaaarrrrgggg! i have a setup where i must alias 127.0.0.1 to external (real/existing) hostnames so that a clone of a customer website cannot reach the outside world. After a restart of my machine, NM hosed the aliases, which allowed my app to contact the production webserver, deleting live db data (which otherwise would have been deleted in my local copy of the db).

Aaarrrggghhh!

Dammit, i am SO pissed off at this. NetworkManager HAS NO BUSINESS DELETING MY ALIASES!!!

StephanBeal (sgbeal) wrote :

...and the 127.1.1.x remap is a painful workaround because i now have to go adjust all of my DB grants, which use 127.0.0.1.

StephanBeal (sgbeal) wrote :

PS: Network Mismanager version:

Version: 0.8.1+git.20100810t184654.ab580f4-0ubuntu2
on x86/64-bit.

Above a fixed version is listed:

20100810t184654.ab580f4

but the update process isn't giving it to me. Where can i get this?

StephanBeal,

Please be polite and remain calm; we appreciate the issues you're facing but can't help unless everyone remains respectful of everyone else.

You should already have the correct version in update-manager; as 0.8.1+git.20100810t184654.ab580f4-0ubuntu3. You can confirm this by checking the output of the following command:

dpkg -l network-manager | cat

To re-check for updates, you can do:

sudo apt-get update && update-manager

The update manager dialog will open and should contain the new network-manager if you aren't already at the latest version.

Hrm, oops, 0.8.1+git.20100810t184654.ab580f4-0ubuntu2 is actually the latest in Maverick, the fix is only in Natty.

Please try the following package from my PPA for testing prior to an upload to -proposed:

https://edge.launchpad.net/~mathieu-tl/+archive/nm

And the package is network-manager 0.8.1+git.20100810t184654.ab580f4-0ubuntu2.1~mtrudel1~preproposed ; it's the only NetworkManager package in that PPA for Maverick.

Note that this is for testing the patches available; we need to know whether it works properly or not, you can find out how exactly to test this from the bug description "TEST CASE" section.

Accepted network-manager into maverick-proposed, the package will build now and be available in a few hours. Please test and give feedback here. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you in advance!

Changed in network-manager (Ubuntu Maverick):
status: New → Fix Committed
tags: added: verification-needed

The current package appears to introduce a regression, as identified in bug 729091.

tags: added: regression-proposed

Marking this verification-failed since there has not been reports of the fix working yet, and bug 729091 specifically mentions a case where the fix causes a regression.

Setting back to In Progress: I'll need to look at whether the whole change set for not touching /etc/hosts can be backported to Maverick.

Changed in network-manager (Ubuntu Maverick):
status: Fix Committed → In Progress
tags: added: verification-failed
removed: verification-needed
chrisisbd (chris-isbd) wrote :

I think *any* rewriting of /etc/hosts by Network Manager (or anything else for that matter) is simply *wrong*.

I have a local DNS server on my LAN which provides everything needed, in particular it provides an FQDN for my system.

Thus my /etc/hosts is:-

127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

If Network Manager adds *anything* looking like a domain then it breaks my DNS and various things (like
apache2 and leafnode) complain about not being able to find a domain name for my system.

John Vincent (jonny-vincent) wrote :

Hi Mathieu,

My ignorance is fairly colossal, but I have the latest network-manager 0.8.1+git.20100810t184654.ab580f4-0ubuntu2 - and I've been struggling with this .local domain Avahi doesn't much care for, for a few weeks now.

My /etc/hosts is (and I have ip6 on Ignore):

192.168.1.3 ubuntu # Added by NetworkManager
127.0.0.1 localhost.localdomain localhost
::1 ubuntu localhost6.localdomain6 localhost6
127.0.1.1 ubuntu

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

---------

I also get this warning message from Avahi: "Avahi has detected a .local domain and is shutting down". And no one really seems to know much about it. My ISP swears it has nothing to do with them. Avahi say to check with my Network Administrator and he doesn't know squat cause that's me. I'd kind of like to get rid of it rather than follow the seemingly preferred tendency to "workaround" unknowns....

thanks for your work on this!

On Fri, Apr 15, 2011 at 3:06 AM, John Vincent <email address hidden> wrote:
[...]
> I also get this warning message from Avahi: "Avahi has detected a .local
> domain and is shutting down". And no one really seems to know much about
> it. My ISP swears it has nothing to do with them. Avahi say to check
> with my Network Administrator and he doesn't know squat cause that's me.
> I'd kind of like to get rid of it rather than follow the seemingly
> preferred tendency to "workaround" unknowns....

Might you have configuration that sets the domain as .local, either in
the configuration of your connections in NetworkManager, or in files
in /etc/ (like resolv.conf or domainname)?

NM doesn't touch that domain and IIRC knows about not doing anything
with it, since that would potentially cause issues. But it won't
override configs you put into connections claiming to know better ;)

The .local domain is a virtual domain created by avahi to dynamically
have different machines on the same subnet speak to each other. If
it's configured in files or other configuration on your system, the
name can't be used and Avahi would complain as so.

Since this is not directly relevant to this bug report, could you
please file a new bug against nm-applet, so we can work on this: you
can do so with the command "ubuntu-bug network-manager-gnome".

/ Matt

John Vincent (jonny-vincent) wrote :

> Since this is not directly relevant to this bug report, could you please file a new bug against nm-applet, so we can work on this:

1000 apologies, I got carried away at seeing a default /etc/hosts posted, and I'm an exuberant moron. I shall gleefully but gratefully impose upon your kindness by filing a new bug report, thank you!

> To me it looks like a different issue specific to IPv6 after all. In reality, you probably shouldn't even have this new IPv6 entry
> in /etc/hosts if your system is set to Ignore for IPv6 in NM. I'll start writing a patch to bypass setting this alias when IPv6
> is set to >Ignore.

No idea if being helpful, but wanting to be of help, I upgraded to 11.04 last night and I no longer have an IP6 added by the system into /etc/hosts when IP6 is set to Ignore. cheers!

Martin Pitt (pitti) wrote :

This has been in maverick-proposed for 100 days, and is verification-failed. I removed the proposed package now, as this doesn't seem to make much progress. Also, Maverick has lived with this bug for over a year, so there's not much point fixing it now IMHO.

Changed in network-manager (Ubuntu Maverick):
status: In Progress → Won't Fix
Alex Connell (alex-connell-uk) wrote :

Well clearly It's a bug and it's a nuisance, so why not fix it?

Why is the network manager rewriting this file all of a sudden?

Clint Byrum (clint-fewbar) wrote :

Alex, the policy on Stable Release Updates, https://wiki.ubuntu.com/StableReleaseUpdates , is pretty clear that fixes to core components, like network manager, are only appropriate if they are of a high impact. Thus far this one has been shown to be of low to moderate impact, and has a work around. That, coupled with the fact that the fix introduced regressions, means this isn't appropriate for release to updates.

tags: added: testcase
Alexandr Novel (normalex) wrote :

workarounds for 127.1.0.x or 127.1.1.x do not work in 12.04
still overwrites, chattr is better

Thomas Hood (jdthood) wrote :

In 12.04, NM does not touch /etc/hosts.

Alex Andrascu (s0-ofk2ce-id) wrote :

This also happens on 12.10.

Ge Yang (yangge1987) wrote :

Right, this also happens on 12.10. This basically means that one can not change host name properly.

mjpelmear (mjpelmear) wrote :

Just ran into this today after upgrading from 10.04 to 13.04.
What is the deal here? This is a major issue affecting web developers (and others).
I don't see why network-manager should be overwriting changes I make in /etc/hosts. (I could understand a block that it maintains within the file.)
What is the best way to proceed to get some forward motion on this?

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.