I know that the hostname of the server should be listed in the /etc/hosts file. server1.example.com server1

Do I also need to list every domain hosted on the server within the /etc/hosts file as well in the same format?

  • 1
    AFAIK there's no such requirement at all as long as your DNS works. Only localhost (::1 localhost if you also use IPv6)must be there. Commented Jul 22, 2022 at 9:59
  • In your question, is and example IP address, or the address of a DNS server? should be use as an example IP address. It has been assigned this use. Commented Jul 22, 2022 at 10:21

1 Answer 1


All host names need to be registered with a DNS server, and will then be publicly visible (or visible in an organisation, depends where the DNS server is).


Added to the /etc/hosts file.

If you are developing a site, that is running on your own machine, then you would run it on a 127.?.?.? address, and add all names to /etc/hosts. E.g. vhostname1 vhostname2 webserver

Use /etc/hosts or DNS. /etc/hosts is the old way. It was used in the beginning, but did not scale, as the file needed to be copies to every machine. DNS is a replacement. However /etc/hosts is useful if you want to run a site on the local machine (e.g. when developing it), as then the name is only visible to that machine, and is quick and easy to change.

If using DNS. Set up a main name for the server with A (and AAAA) record. Then set up CNAME records for each of the site names, these should point to the main record (A / AAAA).

  • Good deal. My hostname is registered with DNS. There will be 3 domains on the server, do they need to be present in the /etc/hosts file?
    – Dwyer
    Commented Jul 22, 2022 at 11:41
  • What happened when you tested it? Commented Jul 22, 2022 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .