What is proper relationship between /etc/hosts and DNS A records for a Linux server?
Posted
by
MountainX
on Server Fault
See other posts from Server Fault
or by MountainX
Published on 2012-06-22T06:00:04Z
Indexed on
2012/06/22
15:18 UTC
Read the original article
Hit count: 268
I have an Ubuntu server. It is going to be a web server with a URI of www.example.com. I have a DNS A record pointing www.example.com to the server's IP address.
Let's say I pick "trinity" as the hostname for this server.
I want to set up the DNS records correctly. I need reverse DNS to www.example.com, so a CNAME for www.example.com doesn't seem appropriate. Here's my question:
Is it considered best practice to set up two DNS records (which in my case would likely be two A records), one for www.example.com and one for trinity.example.com, both pointing to this server's IP address? (Or, even if it is not accepted as a best practice, is it a good idea?)
If so, would the following be a proper /etc/hosts file?
$ cat /etc/hosts
127.0.1.1 trinity.local trinity
99.100.101.102 trinity.example.com trinity www.example.com
This server is a Linode and Linode's docs seem to imply that the above approach is best (if I am reading them correctly). Here's the relevant section. I bolded the line that seems to apply here.
Update /etc/hosts
Next, edit your /etc/hosts file to resemble the following example, replacing "plato" with your chosen hostname, "example.com" with your system's domain name, and "12.34.56.78" with your system's IP address. As with the hostname, the domain name part of your FQDN does not necesarily need to have any relationship to websites or other services hosted on the server (although it may if you wish). As an example, you might host "www.something.com" on your server, but the system's FQDN might be "mars.somethingelse.com."
File:/etc/hosts
127.0.0.1 localhost.localdomain localhost 12.34.56.78 plato.example.com plato
The value you assign as your system's FQDN should have an "A" record in DNS pointing to your Linode's IP address. For more information on configuring DNS, please see our guide on configuring DNS with the Linode Manager.
© Server Fault or respective owner