Configuring hosts file on CentOS

Discussion in 'Installation/Configuration' started by Hisense, Jul 19, 2020.

  1. Hisense

    Hisense New Member

    Hi there,
    I have a simple question about the /etc/hosts file on CentOS7.
    I have never worked with CentOS yet, I just have used Debian or Ubuntu since now. I want to give CentOS a chance now :)
    On Debian or Ubuntu I have in all my /etc/hosts an entry which is:

    127.0.1.1 primary.myserver.com primary

    On my CentOS Server I don't have the 127.0.1.1 entry. Do I need to set it or is this not important for CentOS? I have in this hosts file my external IP with my hostname. 127.0.0.1 resolves to localhost.

    Thanks a lot
     
  2. branov

    branov Member

    You have to understand first what is the hosts file purpose. When you are doing any DNS request (translating domain name to IP address), your system is looking firstly into hosts file and then to DNS name servers. Hosts file is your local domain to ip map.

    Entry for localhost with IP 127.0.0.1 should always be hosts file part. On the other hand, I am not sure about 127.0.1.1 primary.myserver.com primary :) Do you really want to resolve primary.myserver.com to 127.0.0.1 address?

    Its common to have in hosts file hostname with its external IP address, so this is perfectly fine.
     
  3. Hisense

    Hisense New Member

    Hi branov,

    thanks a lot for your reply, yeah I don't actually know, I have never seen the entry of 127.0.1.1 in a host file on other OS'es than Debian/Ubuntu. Everything I create a Ubuntu or Debian server, I have this entry in my hosts file. But when I create a CentOS I don't have this entry in it. So I was a little bit surprised about it and thought maybe I need to put it as well inside of the CentOS hosts.

    Thanks a lot for your answer
     
  4. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    ahrasis likes this.

Share This Page