I have a cloud server running Debian 7. My domain (www.domain.com and domain.com) both have an A record pointing to the static IP address of my cloud server.

On the cloud server itself, what should my /etc/hosts and /etc/hostname be set as?

I plan to have multiple servers, so I started labeling the servers as:


so that I know the location of each server.

Should the /etc/hosts look like:




And should the /etc/hostnames look like: web01-east

or web01-east.domain.com
| improve this question | | | | |

I have a clustered setup where I named my hosts in /etc/host as:    master.local
XX.XX.XX.XX    www.master.com    node01.master.local
YY.YY.YY.YY    node01.master.com    node02.master.local
ZZ.ZZ.ZZ.ZZ    node02.master.com

With this I have a mapping of their private IPs, using .local and their public facing IPs without it. The www.master.com is in DNS. The other public IPs are not in DNS. I use this setup on AWS EC2 instances today for my Nginx clusters and it works well. Adding a new node is then a mindless operation and a simple cluster configuration.

I use the public name (without local) as each server's hostname.

You can put pretty much anything you want in the hosts file. The names are local to that machine anyway. It's really how you want to manage it.

| improve this answer | | | | |

The /etc/hosts file has the entry of the server's hostname. If you wish to point a domain locally on that server you can add the entry of that domain as well.

Ideally it is a below/ localhost.localdomain localhost xx.xx.xx.xx server.yourdomain.com server

Replace xx.xx.xx.xx with your actual server IP.

| improve this answer | | | | |

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.