The host name
On Unix systems, the host name is kept in memory by the kernel: it is set
and get by the sethostname()
and gethostname()
functions and their command-line wrapper hostname(1)
. It can be
used by several programs, for instance by the mail server to determine what it
should use as its HELO name.
In fact, the host name has two forms: the short one and the fully qualified one. For instance, a host can have muscadet as its short name muscadet and muscadet.example.com as its fully qualified one. From these two forms, a third information can be deduced: the domain name, which is the full name without its first component.
The system host name can be set as either the short name or the fully qualified name. When the full name is used, the short one can be easily deduced, by keeping only its first component. When the short name is used, the full name must be determined by using a more complex heuristic that takes more time and can fail for several reasons.
Determining the short and the fully qualified host name
The command hostname(1)
is able to give both the short and the
full host name, and also the domain name that can be deduced from them:
- -s, --short
- Display the short host name. This is the host name cut at the first dot.
- -f, --fqdn, --long
- Display the FQDN (Fully Qualified Domain Name). A FQDN consists of a short host name and the DNS domain name.
- -d, --domain
- Display the name of the DNS domain.
Now, given that the kernel only maintains a single host name, this command and the corresponding functions are using heuristics to determine these two forms. I did not look to the code, but here is what I have deduced:
- if you have set your system host name to the fully qualified one, it deduces the short one by taking only its first component;
- if you have set your system host name to the short one, it deduces
the full one by resolving it to an IP address, then resolving it
back to a host name: this may use
/etc/hosts
, the DNS or a more exotic name system depending on your configuration.
The second option, when the kernel only knows the short host name, seems rather inferior, as it uses a more complex algorithm which takes more time (if it uses the DNS, it can use much more time than a fully local query) and can fail for several reasons.
Setting the host name
With Debian, the host name is stored in the file /etc/hostname
and set at boot time by the hostname.sh
init script. The local
hosts table /etc/hosts
also contains it, in both forms, for a
loopback IPv4 address 127.0.1.1. It is asked at installation time: the most
common practice is to give the short host name; you are then asked for the
domain name. But you have the option to give the fully qualified domain name,
which has the effect to skip the domain name question.
Using a fully qualified system host name
I used to define short system host names, and I switched to fully qualified
ones about a year ago. I saw no drawback, but I did see benefits. Postfix, by
default, uses the system host name to determine its variables
myhostname
and mydomain
that are used for stuff like
the HELO name and the mail domain name. Well, with a short system host name, it
fails, and you get default myhostname = muscadet.localdomain
and
mydomain = localdomain
, so you have to set them explicitly in its
configuration file, thus duplicating information. Whereas with a fully
qualified system host name, it just works, and you can rely on the default
values, that will stay in sync if you have to change you host name.
To sum up, it is perfectly possible to use a fully qualified name as the system host name, even though it does not seem to be a common practice. In fact, according to my experience, it is even advisable, as it eases the configuration of programs that rely on the host name, such as mail servers.
Edit: As noticed by Javi, the hostname(1)
manpage ends by saying without explaination that /etc/hostname
should contain the short host name and not the full one. There may by some drawbacks by doing so but I was not able not identify them.
15 comments
thursday 19 may 2011 à 21:43 Javi said : #1
thursday 19 may 2011 à 22:11 Tanguy said : #2
friday 20 may 2011 à 00:45 Ryukage said : #3
friday 20 may 2011 à 00:51 M said : #4
friday 20 may 2011 à 01:45 sime said : #5
friday 20 may 2011 à 05:21 jerry said : #6
friday 20 may 2011 à 08:07 Vincent Bernat said : #7
friday 20 may 2011 à 08:42 Tanguy said : #8
friday 20 may 2011 à 08:52 Jon said : #9
friday 20 may 2011 à 10:18 Javi said : #10
friday 20 may 2011 à 18:38 Albert said : #11
friday 20 may 2011 à 18:40 Bruce said : #12
saturday 21 may 2011 à 00:30 Fernando said : #13
saturday 21 may 2011 à 07:09 Vincent Bernat said : #14
saturday 21 may 2011 à 15:06 mirabilos said : #15