In /etc/hostname, I have myname
.
In /etc/hosts, I have :
127.0.0.1 localhost.localdomain localhost myname
::1 localhost.localdomain localhost myname
I have a vague understanding of what really is a hostname and what it is used for.
These more precise questions could help me to understand it better:
-
What really is my hostname in the example above?
myname
or something else? If I had insteadmyname.domain.com
in/etc/hostname
, what would be my real hostname then? -
In the example, the command
hostname
returnsmyname
, whereas the commandhostname -f
returnslocalhost.localdomain
. I had in mind that/etc/hosts
was only a mapping between names and ip addresses. It seems to serve another function here. What is a fqdn and what is it used for? How is it retrieved? Why is itlocalhost.localdomain
? -
If I had instead
myname.domain.com
in/etc/hostname
,hostname -f
would returnmyname.domain.com
. Why? -
Why aren't fqdn ending with a dot in these files?
-
Are
hostname -d
anddnsmydomain
equivalent? -
In what context can I use my hostname (
myname
) and when do I have to use my fqdn (localhost.localdomain
)?
Best Answer
/etc/hostname
contains name of the machine, as known to applications that run locally./etc/hosts
and DNS associate names with IP addresses.myname
may be mapped to whichever IP address the machine can access itself, but mapping it to127.0.0.1
is unæsthetic./etc/hosts
, but/bin/hostname
serves another function with-f
./etc/hosts
can override the common sense. Edit it with caution and don’t leave garbage there after temporary patches and experiments..
TLD.
and ⋯.
TLD) are acceptable. The former is unambiguous, whereas the latter is ubiquitous.dnsmydomain
is, but unlikely. Seeking something in/etc/hosts
isn’t technically “DNS”.localhost.localdomain
) – for accessing the machine from outside. FQDN must be resolvable where it is used.