Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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. foobar.com) is pointed to the IP address of my VPS (e.g. 1.23.45.67). Additionally, my VPS has an assigned host name (e.g. virt1000) with the hosting company domain name (hostingcompany.com). Therefore, there are two ways I can SSH to my VPS:

$ ssh -l user virt1000.hostingcompany.com
$ ssh -l user foobar.com

I have changed the domain name to be foobar.com from the command line and the host name to another one (e.g. mynicehost). Should I add mynicehost.foobar.com to /etc/hosts/ and also set up the subdomain mynicehost.foobar.com 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
1  
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 mynicehost.foobar.com with 1.23.45.67 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

1 Answer 1

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 mynicehost.foobar.com 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

 
discard

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.