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.
Best Answer
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 reversePTR
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.