0

First, I know how to declare FQDN but, I just want to know are they the same thing:

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:

127.0.0.1 localhost.localdomain localhost

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

127.0.0.1 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?

Edit:

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.

  • 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, 127.0.0.1 localhost ->> is for IPv4 127.0.1.1 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
4

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:

  • 198.51.100.10 host.example.com host is correct, as it has the FQDN (only without .) first
  • 127.0.0.1 localhost.localdomain localhost would be closest to that form
  • 127.0.0.1 localhost localhost.localdomain does the same, no any practical difference
  • 127.0.0.1 localhost would probably be just as sufficient.
| improve this answer | |
  • 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
  • Actually I like this answer because of the 2nd and third line and mostly the 3rd line said that it has no difference. That straight away answered my question. The manual didn't state about this form.. not sure if this is through testing.. and the person who marked this question. "already found answer" also need to re-read the content of the question not the title. TQ so much again even this is so old – MaXi32 Jul 3 at 7:54

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