Use nss-myhostname to provide default IP address of UNIX hostname
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
netcfg (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
Currently the installer creates this /etc/hosts for a machine named 'foo':
127.0.0.1 localhost
127.0.1.1 foo
If foo is connected to a LAN with domain name 'bar.com' then it's generally the case that 'foo.bar.com' resolves to the machine's external IP address. But 'foo' continues to resolve to 127.0.1.1 because nsswitch.conf contains
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
where 'files' is given first. Hence "ping foo" pings 127.0.1.1 but "host foo" returns the external IP address.
To eliminate this inconsistency the line
127.0.1.1 foo
could be eliminated from /etc/hosts and the "myhostname" NSS provider (suitably modified so that it returns 127.0.1.1 for the UNIX hostname) added to nsswitch.conf at the end of the "hosts" line. That way, 127.0.1.1 is still returned for the name 'foo' but only if other methods of name resolution have failed to resolve the name 'foo'.
The Myhostname NSS provider is another fine product brought to you by supercoder Lennart Poettering.
I see that nss-myhostname has been packaged for Debian as libnss-myhostname. It's in universe.
$ apt-cache madison libnss-myhostname myhostname | 0.3-4 | http:// nl.archive. ubuntu. com/ubuntu/ quantal/universe amd64 Packages
libnss-
It has already been patched so that it returns 127.0.1.1 rather than 127.0.0.2.
I see also that in version 0.3, nss-myhostname was enhanced such that
* it returns an external IP address if the machine has one, falling back to 127.0.1.1 if it doesn't;
* and so, in nsswitch.conf on the "hosts:" line, 'myhostname' can be listed right after 'files' so that dns doesn't have to be tried first.
I forgot to mention that this report arose out of discussion at bug #234543 which also hearkens back to Debian bug report #267321. But these are far from the only discussions about this issue.