Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 259634 - net-misc/networkmanager-0.7.0 alters /etc/hosts and changes hostname
Summary: net-misc/networkmanager-0.7.0 alters /etc/hosts and changes hostname
Status: RESOLVED DUPLICATE of bug 176873
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Robert Piasek (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-19 20:29 UTC by Daniel Klaffenbach
Modified: 2010-02-28 06:59 UTC (History)
10 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch that fixes the bug (networkmanager-0.7.1-hostname.patch,11.94 KB, patch)
2009-06-02 12:32 UTC, Ambroz Bizjak
Details | Diff
patch that reads hostname from /etc/conf.d/hostname if no connection is avaible instead of using localhost.localdomain. (hostname-from-confd-hostname.patch,1.44 KB, text/plain)
2009-09-11 18:00 UTC, Paul
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Klaffenbach 2009-02-19 20:29:02 UTC
When NetworkManager 0.7.0 is launched it alters the information in /etc/hosts and changes the hostname (when it does not obtain an IP address).

It completely removes my custom line for 127.0.0.1 in /etc/hosts and changes it to:
127.0.0.1 localhost.localdomain localhost

It does not even honor the file permissions (if I set it to read only it still makes these modifications).

And it always changes the system's hostname to localhost. I have compiled networkmanager with dhclient use flag. My /etc/dhcp/dhclient.conf looks like this:
send host-name frodo;
supersede host-name frodo;

Still the hostname is changed.

Reproducible: Always




Portage 2.2_rc23 (default/linux/x86/2008.0, gcc-4.3.2, glibc-2.7-r2, 2.6.27.10 i686)
=================================================================
System uname: Linux-2.6.27.10-i686-Mobile_AMD_Sempron-tm-_3100+-with-glibc2.0
Timestamp of tree: Tue, 17 Feb 2009 16:00:01 +0000
distcc 3.0 i686-pc-linux-gnu [enabled]
app-shells/bash:     3.2_p39
dev-java/java-config: 1.3.7-r1, 2.1.6-r1
dev-lang/python:     2.4.4-r13, 2.5.2-r7
dev-python/pycrypto: 2.0.1-r6
dev-util/cmake:      2.6.2-r1
sys-apps/baselayout: 2.0.0
sys-apps/openrc:     0.3.0-r1
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.63
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.2
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.27-r2
ACCEPT_KEYWORDS="x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=k8-sse3 -mtune=k8 -O2 -pipe -fomit-frame-pointer -ftree-vectorize"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/4.2/env /usr/kde/4.2/share/config /usr/kde/4.2/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-march=k8-sse3 -mtune=k8 -O2 -pipe -fomit-frame-pointer -ftree-vectorize"
DISTDIR="/usr/portage/distfiles"
FEATURES="distcc distlocks fixpackages parallel-fetch preserve-libs protect-owned sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://distfiles.gentoo.org http://distro.ibiblio.org/pub/linux/distributions/gentoo"
LANG="de_DE.UTF-8"
LC_ALL="de_DE.UTF-8"
LDFLAGS="-Wl,-O1"
LINGUAS="de"
MAKEOPTS="-j8"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/layman/gnustep /usr/portage/local/layman/qting-edge /usr/portage/local/custom"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="3dnow 3dnowext X a52 aac aalib acl acpi alsa bash-completion berkdb bzip2 cairo cdr cli cracklib crypt cups custom-cxxflags daap dbus divx dri dvd dvdr dvdread dvi encode esd firefox flac fortran gdbm gif gimp glitz gtk2 hal htmlhandbook iconv ieee1394 imagemagick ipod isdnlog java jpeg jpg kde kdeprefix laptop ldap lm_sensors mad midi mmx mmxext mng mp3 mp4 mpeg mudflap ncurses networkmanager nfs nls nptl nptlonly nsplugin ogg opengl openldap openmp pam pcre pda pdf perl png pppd python qt4 quicktime raster readline reflection samba scanner session skins spell spl sse sse2 sse3 ssl ssse3 startup-notification svg sysfs tcpd tiff unicode usb vcd vorbis webdav wifi win32codecs x86 xcomposite xorg xscreensaver xulrunner xv xvid zlib" ALSA_CARDS="atiixp" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="de" USERLAND="GNU" VIDEO_CARDS="ati radeon"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 emerald 2009-02-20 08:06:33 UTC
You should not remove the localhost line in /etc/hosts, only add additional 
ones. localhost lookup to 127.0.0.1 is important for system funnctionality.
Comment 2 Daniel Klaffenbach 2009-02-20 08:44:45 UTC
(In reply to comment #1)
> You should not remove the localhost line in /etc/hosts, only add additional 
> ones. localhost lookup to 127.0.0.1 is important for system funnctionality.
I know. I also left localhost in the line. It should read:
127.0.0.1 frodo.home.local frodo localhost

But NM keeps changing that.
Comment 3 Luigi 'Comio' Mantellini 2009-03-01 11:33:52 UTC
Same issue here.
Any idea to solve it?

luigi
Comment 4 Robert Piasek (RETIRED) gentoo-dev 2009-03-01 13:55:35 UTC
Well it's not a bug, but a design decision.

NetworkManager takes total ownership over your networking. If you're not using DHCP you should define system-wide connection with static IP address. That way your IP and hostname will always be preserved.

Also you shouldn't add your host alias to 127.0.0.1, but to default IP address.
Comment 5 Daniel Klaffenbach 2009-03-01 16:04:12 UTC
(In reply to comment #4)
> Also you shouldn't add your host alias to 127.0.0.1, but to default IP address.
But what if there is no default IP address? I only use DHCP. My IP address keeps changing all the time. Assigning an alias for 127.0.0.1 is a pretty normal thing.
And the fact that NM touches /etc/hosts (even if it is set to read-only) is not a good thing.
Comment 6 Ward Poelmans 2009-04-20 13:25:34 UTC
There is a patch to let Networkmanager read /etc/hostname from ubuntu:
https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/276253

That would fix the issue.

Comment 7 Ambroz Bizjak 2009-06-02 12:32:57 UTC
Created attachment 193285 [details, diff]
Patch that fixes the bug

Hi, I've created a patch that removes all code related to changing the hostname and altering /etc/hosts. Tested and works fine.
Removing the hostname-changing behaviour from NetworkManager is the only correct fix, as it is simply stupid and horribly broken (breaks X sessions, overrides system-configured hostname with meaningless one).
Comment 8 Robert Piasek (RETIRED) gentoo-dev 2009-06-02 15:55:24 UTC
Removing the code is NOT a proper solution.

Currently NetworkManager doesn't support native Gentoo configuration, so we're using "default" keyfile plugin. There are two ways to fix the issue:

1) since we're using keyfile plugin, we need to define hostname in keyfile plugin:
add 'hostname' in a [keyfile] section in /etc/NetworkManager/nm-system-settings.conf

[main]
plugins=keyfile

[keyfile]
hostname=my.persistent.hostname

2) write Gentoo plugin, which will handle gentoo configuration


I start working on (2), but it might take a while before I produce something worth commitng to NM base code.
Comment 9 Ambroz Bizjak 2009-06-02 18:47:56 UTC
Robert:
I do not understand why you think removing the code is not correct. It is known that changing the hostname breaks X which is totally unacceptable. Obviously the solution is to simply NOT change the hostname. You on the other hand are trying to ensure it gets "changed" to its original value. Why?
Even if it wouldn't break X and probably more apps, why would anybody really want to have the hostname assigned dynamically?

Also, the keyfile solution doesn't work. Take a look at the code - if there is no network connection, the hostname will ALWAYS be changed to "localhost.localdomain", no matter the config. This is also broken.
Suppose a user boots his laptop with no network connection, so the X session starts up when the hostname was "localhost.localdomain". Then the user plugs the network cable in, and suddely all apps fail to start because the hostname changes to the correct value.
Comment 10 Robert Buchholz (RETIRED) gentoo-dev 2009-06-03 10:01:01 UTC
(In reply to comment #9)
> Robert:
> I do not understand why you think removing the code is not correct. It is known
> that changing the hostname breaks X which is totally unacceptable. Obviously
> the solution is to simply NOT change the hostname.

Changing the hostname is intended behaviour according to RFC 2132, section 3.14. Do not claim what it is in any way not correct. If you do not want the hostname to be changed, your DHCP server should not assign a host name. Alternatively, you can choose to ignore the value locally which is what this bug is about. Assigning a hostname via DHCP makes as much sense as assigning an IP address, domain name or NTP server and is what DHCP is there for.
Comment 11 Robert Buchholz (RETIRED) gentoo-dev 2009-06-03 10:02:28 UTC
(In reply to comment #10)
> Do not claim what it is in any way not correct.

Read: Do not claim what is and is not correct.
Comment 12 Robert Piasek (RETIRED) gentoo-dev 2009-06-03 13:40:57 UTC
The simple idea with localhost.localdomain is, that NM checks for hostname (nm-system-settings). nm-system-settings checks which plugins are enabled and based on that assigns proper hostname based on your distro configuration. If hostname is not defined - it will automatically assign localhost.localdomain.

The problem with Gentoo is, that we don't have native plugin which would be able to parse our configs, hence it can't recognise your hostname. It will automatically determinate it, once the connection is established, but that on the other hand breaks X.

For now you can try the solution mentioned above.
Comment 13 Ward Poelmans 2009-06-03 13:59:51 UTC
(In reply to comment #8)

> 2) write Gentoo plugin, which will handle gentoo configuration
> 
> 
> I start working on (2), but it might take a while before I produce something
> worth commitng to NM base code.

Can we help in anyway with that?

Ward 

Comment 14 Ricardo Salveti 2009-06-22 01:07:29 UTC
(In reply to comment #13)
> (In reply to comment #8)
> 
> > 2) write Gentoo plugin, which will handle gentoo configuration
> > 
> > 
> > I start working on (2), but it might take a while before I produce something
> > worth commitng to NM base code.
> 
> Can we help in anyway with that?

Yeah, how is the state of your current Gentoo plugin? If it's not ready, how can we help with that?

This bug is quite annoying.

Thanks,

Ricardo 
Comment 15 Robert Piasek (RETIRED) gentoo-dev 2009-06-22 19:39:43 UTC
Hey,

(In reply to comment #14)
> 
> Yeah, how is the state of your current Gentoo plugin? If it's not ready, how
> can we help with that?
> 
The status is nowhere near complete I'm afraid. I've been busy with other stuff recently, so I didn't have time to work on it. If you want to help you might want to have a look on other plugins (fedora, suse, debian) and write a base we can build on. Your programming stills are far superior comparing to mine (it's an assumption based on your email address :))

Rob
Comment 16 Paul 2009-09-11 18:00:34 UTC
Created attachment 203809 [details]
patch that reads hostname from /etc/conf.d/hostname if no connection is avaible instead of using localhost.localdomain. 

It's the same thing the ubuntu folks did on theyr Networkmanager.
Comment 17 Paul 2009-09-11 18:05:11 UTC
Comment on attachment 203809 [details]
patch that reads hostname from /etc/conf.d/hostname if no connection is avaible instead of using localhost.localdomain. 

An 127.0.0.1 alias to localhost is still in the /etc/hosts. And sry about my C-code, maybe some can parse the /etc/conf.d/hostname claenly and get the hostname out of it. It's exactly the same thing, the ubuntu folks did.
Comment 18 Pacho Ramos gentoo-dev 2010-02-22 19:22:10 UTC
Isn't this a dupe of bug 176873 ?
Comment 19 Nirbheek Chauhan (RETIRED) gentoo-dev 2010-02-28 06:59:03 UTC
Fixed in 0.8 (altering of /etc/hosts is WONTFIX)

*** This bug has been marked as a duplicate of bug 176873 ***