Normally when we setup a new server we set the hostname:
- On Redhat systems (Fedora, CentOS, etc.,) the hostname is set in /etc/sysconfig/network like this:
- On Debian systems (Ubuntu, Knoppix, Xandros) the hostname is set in /etc/hostname (a simple text file with only the hostname of the server in it.)
During the boot process the system startup scripts will read the hostname and set it in the system. It will then be possible to query the hostname:
Software (such as sendmail,) will get the hostname in a slightly different way. In some cases this variation does not work:
$ hostname --fqdn
Name or service not known
The documentation for the hostname command hints at the problem. It explains that:
The FQDN of the system is the name that the resolver(3) returns for the host name.
Technically: The FQDN is the name gethostbyname(2) returns for the host name returned by gethostname(2).
If we read the above literally the solution is simple: Go into /etc/hosts and add the host name along with the external IP for the server:
Sadly, this may not work as expected. It seems to me that the system is trying to find the short host name. Add it like this:
18.104.22.168 myhost.name.tld myhost
This worked for me Amazon EC2 where the external IP of the server does not appear on any of the local network devices.