Hostname funniness
Thomas Hood
jdthood at aglu.demon.nl
Wed Nov 17 08:39:49 CST 2004
On Wed, 2004-11-17 at 13:49, Lorenzo E. Danielsson wrote:
> Ubuntu (Hoary):
> % hostname
> my.hostname.net
> % hostname -s
> localhost
>
> Can somebody tell me where I went wrong? I'm running hostname from zsh
> on all three systems. I haven't begun damaging files in /etc/ yet
> either. I have pretty much a normal Warty install with a (partial) Hoary
> upgrade.
This has been discussed at some length on various Debian mailing lists.
You get this because when the resolver (used by the "hostname" command)
looks up your hostname ('my.hostname.net') it obtains a certain IP
address and the canonical hostname for that IP address is 'localhost'.
Your /etc/hosts probably looks something like this:
# IP-addr canonical-hostname alias
127.0.0.1 localhost my.hostname.net
In order to solve this problem I suggest modifying /etc/hosts so that it
looks like this:
127.0.0.1 localhost.localdomain localhost
127.0.1.1 my.hostname.net my
If your machine has a fixed network adapter with a fixed IP address then
use that instead of '127.0.1.1'.
Dennis Kaarsemaker wrote:
> My quess is that hostname (or the gethostname() function) reads the
> description from /etc/hostname
Not directly. The "hostname" command just calls the hostname() function
which gets the hostname from the kernel.
The kernel hostname is set at boot time by /etc/rcS.d/S40hostname.sh
which reads the string out of /etc/hostname.
--
Thomas Hood <jdthood at aglu.demon.nl>
More information about the ubuntu-devel
mailing list