Short Or Long Hostname ?
Hi,
For the last ten years or so, I’ve defined the short hostname in
/etc/hostname and the FQDN in /etc/hosts. Now I wanted to double-check this information, which eventually led me to this page:
*
https://serverfault.com/questions/331936/setting-the-hostname-fqdn-or-short-name
Now I admit I’m even more confused than before.
Is there some reliable piece of information on this subject for CentOS ?
Cheers,
Niki
—
Microlinux – Solutions informatiques durables
7, place de l’église – 30730 Montpezat Site : https://www.microlinux.fr Mail : info@microlinux.fr Tél. : 04 66 63 10 32
Mob. : 06 51 80 12 12
6 thoughts on - Short Or Long Hostname ?
How I do it ( and always done it):
hostnamectl set-hostname foobar.localdomain
echo 127.0.0.1 foobar.localdomain foobar >> /etc/hosts echo ::1 foobar.localdomain foobar >> /etc/hosts
—
Sent from the Delta quadrant using Borg technology!
Nux!
http://www.nux.ro
—– Original Message —–
IMHO for those having proper DNS in place, the hostname should be set to the FQDN in whatever place it is supposed to be set. I quite feel there is something wrong if the only place where the FQDN is listed is the
/etc/hosts file.
I’m not very happy with how the issue was handled in Linux and the different distributions in the last decades. Not to mention the inconsistency in the relevant man pages.
I found the info mentioned in the FreeBSD man pages quite helpful even if it has to be “translated” to Linux. See the excerpt of the mentioned man pages below. If you believe this is heresy to be posted here, please don’t read it :-)
Regards, Simon
—-%>—————————–
Well, I am unhappy for about as long about /etc/hosts and how name resolution “should” happen which it doesn’t, namely, if
/etc/nsswitch.conf says
hosts: files dns
then ideally /etc/hosts should be used first, then nameservers. However
(and this is true both for Linux and FreeBSD), some commands never look into /etc/hosts (e.g., command host), whereas some do use /etc/hosts
(e.g., command ping).
Valeri
Well, in case of the host command it seems clear that it doesn’t look up
/etc/hosts as it is a “DNS lookup utility”, as the man page states, and not a general name resolution utility. I had to learn this, guess how.
But all in all it’s a bit of a mess, yes. Unfortunately I’m tempted to expect that systemd-resolved will even make it worse :-)
Regards, Simon
If you ever plan on using Kerberos, you want the host name to use FQDN, otherwise some krb5 stuff can break.
—
Jonathan Billings
It’s my impression that trying to resolve a host on a Linux system (and also other *nix like systems) is best done with the getent utility:
getent hosts
It shows what other programs see as well.
Regards, Simon