This question already has an answer here:

I have 2 VPSs running using Centos 7. When I look up at the /etc/hosts file:

I found the entry of the host file for VPS 1 like this: localhost.localdomain localhost

But then the entry of host file for VPS 2 is like this: localhost localhost.localdomain

I'm not sure why the 2 entries are different. My question is, what is the correct syntax for declaring this Fully Qualified Domain Name in your host file? Are those 2 lines can be used and has the same purpose?


About the mark as duplicated answer, for explanation: The question asked there specifically about RHEL-based and Debian-based distros that have difference host setting but this question is about the same distro (CentOS 7) but has different host setting that might confuse some questioners to get the 'why' answer where the answer from the reference doesn't cover this.

marked as duplicate by Gerald Schneider, ewwhite, HBruijn Sep 11 '17 at 12:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • man hosts answers your question. – Gerald Schneider Sep 11 '17 at 5:56
  • unix/linux manuals are also easily found online nowadays. – Gerald Schneider Sep 11 '17 at 6:43
  • So from the example given, It stated that, localhost ->> is for IPv4 thishost.mydomain.org thishost -->> is for FQDN ::1 localhost ip6-localhost ip6-loopback -->> is for IPV6 – MaXi32 Sep 11 '17 at 6:47
  • But this still doesn't answer my question. – MaXi32 Sep 11 '17 at 6:48
  • if I put thishost thishost.mydomain.org are they the same thing? – MaXi32 Sep 11 '17 at 6:52

Even when your environment doesn't have man pages installed it doesn't mean you don't have access to them, either by installing them with yum install man-pages man or using online versions e.g. from man.he.net, man7.org. or linux.die.net.

The format is IP_address canonical_hostname [aliases...]. Therefore:

  • host.example.com host is correct, as it has the FQDN (only without .) first
  • localhost.localdomain localhost would be closest to that form
  • localhost localhost.localdomain does the same, no any practical difference
  • localhost would probably be just as sufficient.
  • Do you know what causes the entry to change in other VPS? They are the same distro (CentOS 7). Are those changes made by human or software? – MaXi32 Sep 12 '17 at 0:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.