3

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?

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
dayuloli
  • 1,253
  • 2
  • 11
  • 19

3 Answers3

2

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.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47
  • 1
    But how come (if hostname has nothing to do with DNS records), one time I tried sending an email to myself from my server, and it arrived saying it's from `dayuloli@development`. `dayuloli` is my username on the server, and `development` is my machine's hostname – dayuloli Jan 29 '15 at 15:12
  • 2
    because the email used hostname - do a small experiment: Try to resolve the fqdn and then try to resolve the hostname only. – thanasisk Jan 29 '15 at 15:16
  • An example of why a unique identifier is needed is reverse DNS. RFCs state that `PTR` records should point at the unique canonical name of the device associated with a given IP address. A server could be providing numerous functions each with their own `A` record (www, mail, etc.), but those are all logical aliases. The uniquely identifying name for that device would be the hostname. – Andrew B Jan 29 '15 at 16:04
0

Hostname can be anything that you want and does not necessarily taken from the FQDN of your server like abc for abc.example.com though it is common to do that. It is not really a big deal except other server under example.com may easily recognized abc server.

However the issue may be if one want to set multiple FQDN for each server services hosted on the same machine as mentioned in the question like mail.example.com, db.example.com, web.example.com, ftp.example.com and dns.example.com which are all in the abc.example.com machine.

The reason may be are the server admin may not want the server services to communicate as abc.example.com and want, for example, mail.example.com to communicate on its own FQDN instead.

In furtherance to that, he or she, may want to secure each of the server services in their own FQDN, instead of just the server main FQDN abc.example.com.

If that is so, I think editing /etc/hosts and adding all the needed FQDN for the server services in the fixed ip line (whether 127.0.1.1 or 192.168.0.1 or static public ip) for the server may be the solution, for example:

abc.server.fixed.ip  abc.example.com  web.example.com  mail.example.com dns.example.com other-services.example.com abc-server-preferred-name
0

To answer your question - the hostname should be whatever is meaningful to you or your organisation.

Hostname

The hostname is used only by the host. It's used by the system and services as a default (human-readable?) identity when no context-specific identity has been specified.

It might be used in a log file; it's probabaly used on your shell to give you an indication of which host you're administering; as you've pointed out, the default domain name for your mail server is your hostname, but this will need to be configured.

DNS

In your situation DNS is used by anything on the internet, trying to find its way to your server. That's all - a name referring to an IP address. You have multiple records pointing to the same server which can be used by applications and services to decide what to do with requests, which website to display for example, or which mailbox to deliver an email to. You need to tell the serveices what the domain names should mean to them, but they don't really mean anything to the host itself.

It would be wrong to say that the two are unrelated because often there will be a DNS infrastructure that is managed internally (on a LAN or WAN), or a de-centralised name discovery method like NetBIOS or MDNS. In these cases, the hostname would be used to identify or register the host within that naming service. However, from what you describe of your environment they seem to have no relation at present.

john
  • 1,995
  • 2
  • 17
  • 30