3

We have a server with a CentOS distribution of Linux. It lost its hostname in the month somehow, since our last reboot. We ran an ETL (extract, transform, load) job last week, and part of that process stops JBoss before moving data to our database, and then restarts JBoss after that automatically. The restart failed.

I solved (with a hack) using this method:

https://stackoverflow.com/questions/6484275/what-causes-the-error-java-net-unknownhostexception/34094741#34094741

We didn't make any changes to the server in the last month (to any files), so I know /etc/hosts wouldn't have changed. I added that extra line (in the answer above), in the /etc/hosts file so JBoss could start.

Two questions:

How does the "hostname -f" command retrieve the hostname from the DNS, per this question? What is it checking on our DNS? Is there a term I should be using to communicate with our server team?

Where does `hostname` store the hostname that I've set?

How do most server administrators handle this, or avoid what happened to me? Do they always set something in the /etc/hosts file to avoid changes to the DNS?

Basically I'm trying to figure out what changed on our network (or DNS) which caused our hostname to go missing. See, the command prompt shows the hostname on the server when I log in. It's strange that I see it there, but not when I call "hostname -f". See "lvs-xyz" below.

[root@lvs-xyz ~]# hostname -f
hostname: Unknown host

If you can't answer all of my questions, I'm mainly looking for what the "norm" is to avoid losing a hostname for the administration of Linux. If I put it into /etc/hosts, then it seems like a hack because the command prompt could change if the kernal value changes, and then it would be different from /etc/hosts if that were to happen.

EDIT:

[root@lvs-xyz sysconfig]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
NETWORK=144.92.154.0
IPADDR=144.92.154.48
NETMASK=255.255.255.192
  • Are you using dynamic DHCP so you get a new IP address each time it reboots? That's likely the problem. – mkomarinski Dec 10 '15 at 18:28
  • How can I check without rebooting? I can certainly schedule a downtime to find out. Feel free to answer in both use cases (with and without DHCP) if there is a difference. – MacGyver Dec 10 '15 at 18:40
  • 1
    You should be able to see something in /etc/sysconfig/network-scripts/ifcfg-eth0 and it'll say something like BOOTPROTO=dhcp. If it does, then you need to contact your networking team and either ask for a static DHCP address, or ask they assign you an address outside of the DHCP range and change it yourself. – mkomarinski Dec 10 '15 at 18:51
  • see edit for the value.. looks like its set to "none" – MacGyver Dec 10 '15 at 19:00
  • HOSTNAME=lvs-xyz ... I edited the last part (xyz) in this comment and this question because it has our organization name, but there are no dots. – MacGyver Dec 10 '15 at 19:08
2

You can specify it (loaded on reboot anyway) in /etc/sysconfig/network with a HOSTNAME= line (see the documentation here)

You should specify it as a fully qualified name there generally.

If the host doesn't have a name already, and you're using DHCP it will often pick its name up that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.