Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed chef-client on a Linux node, and it seems to have successfully connected to my chef server. However, when I do: chef node list, it appears as "localhost".

Why doesn't chef pick up the proper name of the node? If I ask for more details, I see:

$ chef node show localhost
node Name:   localhost
Environment: _default
FQDN:        localhost
Run List:    
Platform:    ubuntu 11.10

It has a proper domain name set up. For example, if I do: hostname, it returns "mynodename", not "localhost".

How is chef determining the name of the node? And why does it have the proper name showing in FQDN?

EDIT: In response to cjc below, here's some of the output from ohai | grep host:

(Note: this node is running on EC2)

"fqdn": "localhost",
"hostname": "mynodename",
"public_hostname": "",
"local_hostname": "ip-...ec2.internal",
"hostname": "ip-...ec2.internal",

Also, hostname -s is giving the expected output:

$ hostname -s
share|improve this question
up vote 6 down vote accepted

The reason seems to be that ohai is running hostname --fqdn, which does give "localhost".

The root cause of the problem seems to be that I set the hostname as "mynodename" instead of "". If I do:

sudo hostname

Then it does the right thing when I do: hostname --fqdn

share|improve this answer

I have the same problem. It does seem to be the ohai thing. But it is a bit deeper. The best test is to see whether hostname --fqdn returns something reasonable.

It comes down to the hosts file. Setting hostname with sudo hostname my.fqdn won't work. Strictly speaking this should not be necessary because system names are distinct from domain names. But systems that do reverse lookup easily get confused. bottom line, in your etc/hosts file your fqdn should be the first entry after the ip address if that is what you want returned, e.g. myserver localhost # works, return fqdn localhost myserver # this will return localhost myserver localhost # this will return myserver

If you look in the default etc/hosts file you will see that ubuntu uses as well as that is because of situations like this. Having the host name on a separate ip address (which is still loopback valid) ensures a clean mapping between the system name and the domain name.

share|improve this answer

On Amazon AMI instances based on RHEL 5 and 6. In that case, look at:


I suspect the is configured as such with:


In that case, make the correction with:


On Debian-type Linux instances (such as Ubuntu), you would look at the following file for the hostname:


And make the change there.

share|improve this answer
This was an Ubuntu instance. – Lorin Hochstein Jan 24 '12 at 19:54
My mistake. Updated answer. – Rilindo Jan 24 '12 at 19:58

chef-client uses ohai when setting up the node. What do you get when you run ohai |grep host ?

Glancing through the ohai source in lib/ohai/plugins, for the linux provider, I see that it basically runs "hostname -s", so that's a bit mysterious, given your results.

Could the hostname have been set after chef-client ran?

share|improve this answer
No, hostname was definitely set before chef-client ran. Node was up and running with hostname set before chef-client was installed. – Lorin Hochstein Jan 24 '12 at 18:11

For me it seems to be a problem on /etc/hosts. My /etc/hosts file looks like      localhost myhostname

removing localhost in the /etc/hosts file resolves my problem. I don't need the localhost anyway.

share|improve this answer
That's backwards. You should instead remove myhostname from the localhost entry, and either give it its own entry, or rely on DNS for round-trip resolution of the hostname. – womble Sep 8 '15 at 9:21
Some software won't work properly if localhost can't be resolved. – Anthony Geoghegan Sep 8 '15 at 12:01
It was on separate entries until hostfile recipe combined them into 1. Using the first entry as host and the latter as alias. – user5271031 Sep 9 '15 at 16:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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