How to set hostname if hosting multiple servers on the same machine

domain-name-systemhostnamenetworkingsubdomainvirtualhost

I'm learning about setting up my own web and mail servers, and I've been confused about this question for days, and articles online (including Server Fault) seems to be so inconsistent with their use of the term 'subdomain' and 'hostname'.

From my understanding:

  1. A host name uniquely identifies a computer in a network
  2. A domain and subdomain must have a DNS A record which points to one or more hosts

Let's say my web server is at 1.2.3.4, I have my host name set to development (confirmed by running hostname in bash shell), and I'm setting A records like so:

@   -> 1.2.3.4
www -> 1.2.3.4
mx  -> 1.2.3.4
mx  -> 9.8.7.6

Then I have the www and mx subdomains pointing to my web server whose hostname is development. The mx subdoman also points to two hosts (for redundancy).

Why do I need a hostname? My machine can already be identified using its IP address.

I read somewhere that says a hostname is important because it gets sent in some messages. But if my server is both a mail server, and a file server, and a database server, and etc, what should I set my hostname to be? I certainly don't want someone receiving my mail to see a from address of development. And a machine can only have one hostname right? Should I set my computer's hostname to abc.example.com or just abc?

Main Question

How to set hostname if hosting multiple servers on the same machine?

Best Answer

The hostname is a convenience for uniquely identifying the host on your network. It's an entirely internal name that can be anything you want. The hostname doesn't have to be related to any of its DNS names.

For example, your host named abc can have DNS records that point to it as www.example.com, mail.example.com, and so on.

If you run local DNS within your LAN, you can also give your host a local DNS name of abc or abc.localdomain, so you can type http://abc into your browser. Again that just helps you to identify the host within your LAN.

Related Topic