none
localhost and DNS vs hosts file

    Question

  • I just ran into a problem that I could not connect to MySQL on localhost. WHen changing localhost to 127.0.0.1, things worked. Than I fount that the etc\hosts file had the entry for localhost commented out.

     

    The comment in the hosts file read: "name resolution is handled within dns itself"

    Interestingly enough, a number of programs did not find this issue.

     

    But now my question is where/how do I check that this entry is correct in the DNS service and does anyone have any idea what I need to do (other than editing localhost in the hosts file) to make this work as was intended?

    Tuesday, September 21, 2010 6:43 PM

All replies

  • Editing the HOSTs file should be all that is needed to update ip to name resolution locally for a client system. If you need to flush out the local resolver cache, refer to ipconfig commands.

    http://technet.microsoft.com/en-us/library/cc781949%28WS.10%29.aspx

    In an environment where it's just the localhost client, the local DNS Client service handles the initial resolution

    http://technet.microsoft.com/en-us/library/cc775637%28WS.10%29.aspx

    • Proposed as answer by cschaar Tuesday, September 21, 2010 8:51 PM
    Tuesday, September 21, 2010 7:18 PM
  • Oh dear &deity, I should learn NOT to ask questions on these "social" forums. :(
    Tuesday, September 21, 2010 8:29 PM
  • You should give others a chance before you give up.

    I have not personally come accross the issue you described where the hosts file had the localhosts entry commented out, but the way that I have resolved to ensure that "localhosts" is resolved correctly in all cases, is by creating a host (A) record entry in your foward lookup zones called "localhost" and point it to 127.0.0.1.

    This will ensure that if anyone has purposely removed the localhost entry from the hosts file or if it has been commented for some reason, your DNS client will perform a lookup in the primary zone for a record called "localhost".  Of course, the OS will append the domain suffix, but it wont matter since it will find it in DNS and return the correct IP.  If you have more than one zone, I would create this record in each zone to ensure that all hosts are covered, no matter what domain suffix they are configured to use for DNS.

    I hope that this at least partially answered your question on what can be done to mitigate this issue without having to modify the local hosts file as you requested.

     

     


    Visit: anITKB.com, an IT Knowledge Base.
    Tuesday, September 21, 2010 11:49 PM