So I understand that the hostname should (at least in Debian systems) be set in /etc/hostname
. To get the FQDN (through hostname -f
) the system finds the IP from the hostname through /etc/hosts
and then returns the first entry in the line.
So if the hostname is server1
and this is in /etc/hosts
:
192.0.2.1 server1.example.com server1
It will return server1.example.com
. So this is how it is desribed on many websites. But I was thinking: Why not assign the hostname to the loopback address? Like you do with localhost
:
127.0.0.1 server1.example.com server1 localhost
With this approach you don't have to know the external IP address. Also, applications that might use the FQDN will make the requests directly on the system instead of going through the network.
So, why not do it like this? Why are most examples on the internet using the external IP address?