Domain – How does hostname relate to IP address on a server with multiple public IPs

domaindomain-name-systemhostnameip

My hosting provider set up an Ubuntu-based virtual private server for me with three public IPs. I want to assign hostnames to those IPs as follows (I'm be using Dyn as my DNS):

  • example.com -> IP_1
  • www.example.com -> IP_1
  • test.example.com -> IP_2
  • admin.example.com -> IP_3

www.example.com will be the production site. test.example.com will be the bleeding edge version of the site, used for testing, and admin.example.com will expose a number of site administration services (e.g. SSH, rsyncd). Both www and test will be locked down to port 80. Both test and admin will only accept traffic from certain IPs.

I'm a little confused about the difference between the hostnames DNS deals with, and the server's hostname (as seen when running `hostname' on the server's command line). Where does the server's hostname come into play?

My guess is that Apache 2 doesn't care what the hostname utility returns, because I can specify listening IP:PORT per VirtualHost. But, are they other services (or limitations) I should be aware of when connecting to my server via "foo.mydomain.com" if the machine's hostname is "randomname"?

Best Answer

Hostnames make it easy distinguish between servers. See RFC-1178 Choosing a Name for Your Computer for more details. For what you are doing the server's hostname doesn't really matter. In your case your host will be hosting serveral FQDN (Fully Qualified Domain Names) to enable services. You could add more using addtional DNS CNAME or A records.

As you have a small site ALL of these domains refer to a single host. Larger services like google.com have multiple IP addresses backed by multiple servers. In some cases the IP addresses may belong to load balancers in front of multiple servers.

For an Apache server you should use IP based virtual hosting. You can use Apache ACLs and/or a firewall to restrict access. I use both when I can.

If you add a mail server there are additional rules which should be applied. The FQDN for the mail server should be the same as the name the Server announces. In addition, the IP address should have a PTR record returning that FQDN.