1

I purchased a new domain, then set correctly the DNS records (A ...). The domain points to my server, then Apache VirtualHost intercepts the HTTP queries.

The question, is simple : do I have to add an entry in my /etc/host file for that new added domain ?

AFA Med
  • 447
  • 1
  • 5
  • 15

3 Answers3

5

The question, is simple : do I have to add an entry in my /etc/host file for that new added domain

No.

user9517
  • 114,104
  • 20
  • 206
  • 289
5

To expand on Iain's correct answer, in normal circumstances you rely on DNS and don't need anything in /etc/hosts and you certainly don't need to add each and every DNS entry and domain that points to your server to your hosts file.

Since localhost always points to 127.0.0.1 you don't need to use dns to resolve that static hostname and convention is to include localhost in your hosts file.

In the rare circumstance that DNS doesn't work (single user/rescue mode) it can be useful to have the hostname for your server in the hosts file, but that's no requirement. Note: your server has only one hostname but an infinite number of DNS entries can point to your server.

The only other reason to use the hosts file entries is to circumvent DNS, either to use hostnames not present in DNS or to override DNS

HBruijn
  • 72,524
  • 21
  • 127
  • 192
1

I would just like to add to HBruijn's answer by stating that editing your hosts file should be done only if the need for it arises. If you start hardcoding your ip in your hosts file, you risk forgetting about it and you'll find issues if you eventually change your ip in your dns. The hosts file has priority over everything in dns, so thread carefully.