How can a Linux server lose its hostname? This might be a loaded question, but there might be several answers. I just need to diagnose the problem I'm having, but I don't know where to start.
Perhaps you can help me figure out how Linux determines the output for this command? I'll accept that as an answer as well.
[root@xyz ~]# hostname -f
hostname: Unknown host
This issue was what allowed me to determine the hostname was missing:
https://stackoverflow.com/questions/6484275/what-causes-the-error-java-net-unknownhostexception
EDIT:
Per this comment, I've pasted the /etc/hosts file below. It doesn't look like the hostname is found in there. This is CentOS. D34DM347, what OS are you looking at the man pages in?
The man page for hostname indicates the -f option returns the FQDN,
usually defined in /etc/hosts linux.die.net/man/1/hostname – D34DM347
/etc/hosts:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Best Answer
I'm running CentOS7 and my hostname is written under all the ipv4 / ipv6 entries. Try adding a line at the bottom of /etc/hosts with
Also you can update (although I didn't have to for my servers)
/etc/sysconfig/network
You'll have to restart networking at least, generally I do a full reboot though.
or