OpenNetAdmin

Track. Automate. Configure.

Home About Features Community Develop
Download this project as a tar.gz file

Random facts and comments about unix hostname

Matt

16-09-2009 17:22:32

Below are some statements (fact or commentary) about *nix hostnames. I have ran into various situations where these things get very confusing and I wanted to write down some of these things for later reference. Hopefully they will be useful to others in some way.

* 'uname -n' is derived when setting the hostname using hostname command.
* programs using uname to get name could have problems. Depending on if you set your hostname as just the host or the FQDN causes this to be very inconsistent.
* programs should use either hostname -f or hostname -s to get short or long names
* for those commands to work you must be able to resolve your name, usually it will check /etc/hosts first then dns (can be changed using /etc/host.conf or /etc/nsswitch.conf etc)
* /etc/hostname is only used by /etc/init.d/hostname.sh (or similar bootup hostname scripts) to set the hostname on bootup.
* it seems for hostname -f/-s to work, it uses what is returned for hostname/uname -n to match the /etc/hosts or dns entry?
* /etc/hosts is formated as <IP> <FQDN> <Aliases/shortname>
* hostname -a only works with /etc/hostname. at least I'm not sure how it would find an alias in DNS? maybe a cname but it cant reverse that from the fqdn
* should hostname/uname -n return FQDN or host only? It really shouldnt matter either way, it would be your preference. I'd recommend FQDN as it is more descriptive all around. use hostname -f/-s to give detail as needed.

* a host name should not have dots in it. a domain name probably will. an fqdn will have dots in it and is the host name and the domain name together
* a host name is the first component of an FQDN up to the first dot reading from the left to the right. a domain is the remainder of the FQDN.
* in some configurations (say, dns configuration files) you might have a need to have "dotted host names". this does not change the meaning of what a host name is, just breaks down the FQDN a bit differently due to configuration formatting. ONA allows dotted hostnames, however I would recommend not using them if possible to keep the notion of host/domain consistent.

* many system installers such as the debian-installer(netcfg) will configure /etc/hosts, /etc/resolv.conf, /etc/hostname and possibly others for you. It can have an effect on how all of the above works depending on how it is implemented.