Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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’m quite experienced managing Linux on standalone machines and in local networks.

Recently I’ve hired a VPS server running Linux and also a domain name and I have a few questions regarding the hostname and domainname commands.

Right now my domain name (e.g. is pointed to the IP address of my VPS (e.g. Additionally, my VPS has an assigned host name (e.g. virt1000) with the hosting company domain name ( Therefore, there are two ways I can SSH to my VPS:

$ ssh -l user
$ ssh -l user

I have changed the domain name to be from the command line and the host name to another one (e.g. mynicehost). Should I add to /etc/hosts/ and also set up the subdomain in the A records from my domain?

I’m asking for best practices, really. As it stands, everything kind of works (the domain takes you to the right web site, etc.).

Thanks in advance.

share|improve this question
Remove "virtual" from your question everywhere it appears. Do you now know the answer? – voretaq7 Apr 9 '13 at 19:09
No, to me it doesn’t make much of a difference. My intuition tells me that the most sensible thing is to assign the host name and the domain name with the hostname and domainname commands, set with in the /etc/hosts file, add the subdomain on the DNS and point the domain to this specific machine. But again, I don’t know if this is the usual way to do things or the most common. – Alf Apr 10 '13 at 6:19
Thank you for the elaboration. I didn’t know about the domainname thing and I’ve never had to deal with NIS (although I know what it is on a very shallow level). I’ll set a FQDN to my machine and an A record to redirect the unqualified domain name to that machine. I’ll leave /etc/hosts as it is and resolve the IP address only through the DNS. – Alf Apr 11 '13 at 8:03
And to clarify, there is absolutely no need to use the provider hostname you were assigned...Unless of course you wanted to. – David Houde Apr 11 '13 at 8:11
up vote 1 down vote accepted

You appear to have missed the point of my comment, so I'll elaborate in an answer:

Virtual machines are not special. They should be treated like any other physical host.
In other words, if it makes sense for you to set the hostname to for a physical machine you should do the same thing for a virtual machine.

The DNS and /etc/hosts question is a matter of personal preference.
Some people will tell you the local hostname should always be in /etc/hosts, others (like me) will say it should alway be in DNS (and generally not in /etc/hosts).

If you are sending mail from the system it is generally important that its hostname be resolvable in DNS (and that the forward A record match the reverse PTR record).

Note that the domainname command probably does not do what you think it does.
The domainname command is historically a NIS thing. If you don't know what NIS is count yourself among the lucky.

share|improve this answer

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.