Leaves unreachable entries in /etc/hosts when stopping network

Bug #632896 reported by Anders Kaseorg
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
NetworkManager
Fix Released
Medium
Fedora
Fix Released
Critical
network-manager (Ubuntu)
Fix Released
Medium
Unassigned
Maverick
Won't Fix
Undecided
Unassigned

Bug Description

Binary package hint: network-manager

NetworkManager modifies /etc/hosts to look like this:

18.111.118.108 balanced-tree # Added by NetworkManager
127.0.0.1 localhost.localdomain localhost
::1 balanced-tree localhost6.localdomain6 localhost6
127.0.1.1 balanced-tree

# 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

But when stopping the network, it does not undo these modifications. This leaves the system hostname pointing at a non-routable address, which breaks various applications.

Revision history for this message
In , Andrew (andrew-redhat-bugs) wrote :

Description of problem:
NetworkManager apparently adds an entry in /etc/hosts when it
gets an IP address. The problem is that it doesn't remove it
if the network connection is no longer present. This results in
an /etc/hosts that looks like :

x.x.x.x machinename # Added by NetworkManager
127.0.0.1 localhost.localdomain localhost
::1 machinename localhost6.localdomain6 localhost6

so that any lookups of machinename go to a non-accessible
address. The severity of the problem is that virtually no
gnome applications will function (in particular GDM, but also
gnome-panel, etc.) without being able to access machinename
(which should be 127.0.0.1), thus crippling the machine
until /etc/hosts is fixed or the network connection resumes.

Version-Release number of selected component (if applicable):
NetworkManager-0.8.1-4.git20100817.fc13.i686

How reproducible:
Always

Steps to Reproduce:
1. Boot system
2. Plug in network wire and get IP address (/etc/hosts should be modified)
3. Unplug network wire (/etc/hosts stays the same)
4. Restart X and notice GDM no longer works

Actual results:
Lookups to machinename go to unreaching IP address instead of 127.0.0.1,
GDM fails to function

Expected results:
/etc/hosts should be changed to put machinename back to 127.0.0.1 if no network is available

Additional info:
I ended up chattr +i /etc/hosts to keep it from being modified at all.
Why should the local machinename ever point to anything other than 127.0.0.1?

Anders Kaseorg (andersk)
tags: added: regression-potential
Changed in network-manager:
status: Unknown → New
Revision history for this message
In , Andrew (andrew-redhat-bugs) wrote :

Tested with new NetworkManager-0.8.1-6.git20100831.fc13.i686 and the same problem.

If the laptop boots and you login, NetworkManager gets an IP address for the wireless adapter, changes /etc/hosts. If you then reboot, the
change to /etc/hosts remains and GDM will not start since there is no
route to 'machinename' which in /etc/hosts points to the Wifi address that is not up yet.

Changed in network-manager:
importance: Unknown → Medium
Revision history for this message
In , Russ (russ-redhat-bugs) wrote :

WTF!!!

Why in the @#$% does NetworkManager add an entry to /etc/hosts anyway?

This is absolutely stupid and ridiculous behaviour.

I absolutely DO NOT want or need ANYTHING in the hosts file. We run local DNS, and I just wasted an HOUR of my time screwing around reconfiguring my HTTPD proxy ON ANOTHER MACHINE simply because NetworkManager changed my hosts file on THIS laptop a month ago and added an incorrect entry to /etc/hosts. So I thought it was a proxy problem ON ANOTHER MACHINE. . .

Since /etc/hosts was incorrect the laptop was unreachable to itself.

At this point I'm ready to just remove NetworkManager from this laptop before something else gets seriously screwed up ON ANOTHER MACHINE. I'd rather have to configure the wireless by hand than have this type of behaviour.

There is absolutely no need for ANYTHING in /etc/hosts except localhost.

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Hi,

Could you please specific exactly which extra entries are added, and aren't removed?

Thanks!

Revision history for this message
Anders Kaseorg (andersk) wrote :

Certainly.

1. Original copy of /etc/hosts before starting network-manager:

"""
127.0.0.1 localhost
127.0.1.1 balanced-tree

# 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
"""

2. /etc/hosts after starting network-manager, but before connecting to a network:

"""
127.0.0.1 balanced-tree localhost.localdomain localhost
::1 balanced-tree localhost6.localdomain6 localhost6
127.0.1.1 balanced-tree

# 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
"""

3. /etc/hosts after connecting to a network:

"""
18.111.118.108 balanced-tree # Added by NetworkManager
127.0.0.1 localhost.localdomain localhost
::1 balanced-tree localhost6.localdomain6 localhost6
127.0.1.1 balanced-tree

# 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
"""

4. /etc/hosts after disconnecting from the network:
(same as #3, where “18.111.118.108 balanced-tree” is now unreachable)

anders@balanced-tree:~$ ping `hostname`
connect: Network is unreachable

5. /etc/hosts after stopping network-manager:
(same as #3 and #4)

Revision history for this message
In , Russ (russ-redhat-bugs) wrote :

A quick Google search on this topic reveals this same behaviour in every distro. So the problem is definitely upstream.

It looks like you can permanently set the hostname in the NetworkManager conf file. Then it won't change. But how does that help people who rely solely on DHCP for that? (Here come the gasps from all the sysadmins. . .but it's job security;)

In our case, for example on my laptop, there are two DNS entries for it on the DHCP server. They are tied to the MAC addresses for eth0 and wlan0, and set the hostname according to the interface. So the hostname is either [HOSTNAME] or [HOSTNAME]-wlan0. We need it to be that way. But then NetworkManager causes problems with /etc/hosts.

For now I suppose we must use the hack in comment #1.

After reading all the bug reports it is evident that the described behaviour is utterly detested by just about everybody. So why is it there?

Changed in network-manager:
status: New → Incomplete
Changed in network-manager:
status: Incomplete → New
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Confirming since there is an upstream bug about this.

Changed in network-manager (Ubuntu):
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
In , Jaroslaw (jaroslaw-redhat-bugs) wrote :

I can confirm this issue. It's really annoying. It's impossible to suspend & resume laptop, because after resume session cannot be unlocked.
As a result I have to delete this line added by NM to /etc/hosts each time I want to shut down or suspend machine. This is a pure nonsens!

Revision history for this message
In , Laurent (laurent-redhat-bugs) wrote :

I don't see any troubles with the modification of /etc/hosts when I'm using GNOME programs. However, Sendmail, but maybe other programs, does a timeout so it takes a loooong time to just boot up.

The trick with "chattr +i" helps me to get a laptop (connected to wireless networks very often) that doesn't ask me to take a coffee when it boots up. Unfortunately, the hostname is so set to localhost.localdomain.

Revision history for this message
In , Andrew (andrew-redhat-bugs) wrote :

I've heard that this bug was caused by a workaround added
to NetworkManager to accomodate a bug in glibc when dealing
with IPv6 and localhost name resolution.

Laurent, I've further worked around the problem by setting
the hostname in /etc/Networking/dispatcher.d. Its not pretty
but adding an executable file in this directory containing :

#!/bin/sh
case "$2" in
 up)
  grep HOSTNAME /etc/sysconfig/network | cut -d= -f2 > /proc/sys/kernel/hostname
  ;;
 down)
  grep HOSTNAME /etc/sysconfig/network | cut -d= -f2 > /proc/sys/kernel/hostname
  ;;
esac

exit 0

works around NetworkManager setting the hostname to localhost.localdomain if it cannot write to /etc/hosts.

Revision history for this message
In , Dan (dan-redhat-bugs) wrote :

Upstream fixes:

82dd97c4b73ace6067fbe3fa92a3c7eb5a95e89b (master)
97de44c9a730fbb5a08d27e6899f7caffb015e66 (0.8.x)

Revision history for this message
In , Dan (dan-redhat-bugs) wrote :
Revision history for this message
Anders Kaseorg (andersk) wrote :

Here’s a tested debdiff with the patch from upstream. I’m also building a patched package in my PPA <https://launchpad.net/~anders-kaseorg/+archive/ppa>.

Revision history for this message
In , Andrew (andrew-redhat-bugs) wrote :

This build seems to fix the problem. Initial tests are
all positive. Thanks for your hard work fixing the issue.

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-7.git20100831.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/NetworkManager-0.8.1-7.git20100831.fc14

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-7.git20100831.fc13 has been submitted as an update for Fedora 13.
https://admin.fedoraproject.org/updates/NetworkManager-0.8.1-7.git20100831.fc13

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-7.git20100831.fc12 has been submitted as an update for Fedora 12.
https://admin.fedoraproject.org/updates/NetworkManager-0.8.1-7.git20100831.fc12

tags: added: patch
Anders Kaseorg (andersk)
tags: added: patch-accepted-upstream
Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-7.git20100831.fc14 has been pushed to the Fedora 14 testing repository. If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with
 su -c 'yum --enablerepo=updates-testing update NetworkManager'. You can provide feedback for this update here: https://admin.fedoraproject.org/updates/NetworkManager-0.8.1-7.git20100831.fc14

Changed in network-manager:
status: New → Fix Released
Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-8.git20100831.fc13 has been submitted as an update for Fedora 13.
https://admin.fedoraproject.org/updates/NetworkManager-0.8.1-8.git20100831.fc13

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-8.git20100831.fc14 has been submitted as an update for Fedora 14.
https://admin.fedoraproject.org/updates/NetworkManager-0.8.1-8.git20100831.fc14

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-8.git20100831.fc12 has been submitted as an update for Fedora 12.
https://admin.fedoraproject.org/updates/NetworkManager-0.8.1-8.git20100831.fc12

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-8.git20100831.fc14 has been pushed to the Fedora 14 stable repository. If problems still persist, please make note of it in this bug report.

Anders Kaseorg (andersk)
tags: added: regression-release
removed: regression-potential
Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-9.git20100831.fc12 has been submitted as an update for Fedora 12.
https://admin.fedoraproject.org/updates/NetworkManager-0.8.1-9.git20100831.fc12

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-8.git20100831.fc13 has been pushed to the Fedora 13 stable repository. If problems still persist, please make note of it in this bug report.

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Thanks for the patch Anders, preparing to upload it now...

Changed in network-manager (Ubuntu):
status: Confirmed → In Progress
assignee: nobody → Mathieu Trudel (mathieu-tl)
Revision history for this message
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: In Progress → Fix Released
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

At this point I think the Ubuntu Sponsors team can be unsubscribed.

Revision history for this message
In , Bojan (bojan-redhat-bugs) wrote :

Shouldn't the correct behaviour here be:

1. If network connected, set hostname to point to the actual IPs received from various connections. 127.0.0.1/::1 points to localhost only. For example:

127.0.0.1 localhost.locadomain localhost
::1 localhost6.localdomain6 localhost6
1.1.1.1 hostname.domain hostname
2.2.2.2 hostname.domain hostname

2. If network not connected, set hostname to point to 127.0.0.1/::1.

127.0.0.1 hostname.domain hostname localhost.locadomain localhost
::1 hostname.domain hostname localhost6.localdomain6 localhost6

No?

PS. This is useful when one pings itself, for instance. Correct IP replies. Also, if someone (e.g. a developer) configured a virtual host with the name of the box on the IP in question, there will be problems getting to it using the name from the box itself, because 127.0.0.1/::1 will be used instead of the real address.

Revision history for this message
In , Fedora (fedora-redhat-bugs) wrote :

NetworkManager-0.8.1-9.git20100831.fc12 has been pushed to the Fedora 12 stable repository. If problems still persist, please make note of it in this bug report.

Revision history for this message
In , Brian (brian-redhat-bugs) wrote :

I just applied this patch to a system to fix this problem and it does not appear to be fixed. NetworkManager still does not remove the host entry when the network changes.

Specifically:

My user has a host named zenith. His own hostname is in his hosts file.

143.232.109.41 zenith.arc.nasa.gov zenith

When he switches to wireless, network manager adds an entry:

198.123.51.105 zenith.arc.nasa.gov zenith # Added by NetworkManager

When he then plugs back into the wired network, NetworkManager fails to remove this address. This makes things break (specifically flexlm), since his hostname now resolves to an incorrect ip.

[root@zenith ~]# uname -r
2.6.34.6-47.fc13.x86_64
[root@zenith ~]# rpm -qa 'NetworkManager*'
NetworkManager-gnome-0.8.1-9.git20100831.fc13.x86_64
NetworkManager-glib-0.8.1-9.git20100831.fc13.x86_64
NetworkManager-0.8.1-9.git20100831.fc13.x86_64

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

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.

Revision history for this message
Anders Kaseorg (andersk) wrote :

Hi Mathieu, thanks for working on this. I finally got around to testing your package on a maverick system; it works for me and corrects this problem.

Changed in network-manager (Ubuntu):
assignee: Mathieu Trudel-Lapierre (mathieu-tl) → nobody
Revision history for this message
Martin Pitt (pitti) wrote :

Please go ahead and upload. Thanks!

Revision history for this message
Martin Pitt (pitti) wrote : Please test proposed package

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
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Verification probably succeeds for this fix but the package in proposed as a whole causes a regression as identified in bug 729091. Setting to verification-failed, I'll possibly package just this patch alone and work on the other fix separately.

tags: added: verification-failed
removed: verification-needed
Changed in network-manager (Ubuntu Maverick):
status: Fix Committed → In Progress
Revision history for this message
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
Changed in fedora:
importance: Unknown → Critical
status: Unknown → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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