Hosts File

Hosts File

Hosts File

  • A plain-text file used by an operating system to resolve hostnames to IP addresses
  • Used to define any hostname or domain name for use on the local system
  • Located in \%SystemRoot%\system32\drivers\etc\hosts
  • Each Sitecore web site hosted on the server should have a separate entry in the hosts file

Hosts File Structure

  • Contains lines of text that consist of an IP address in the first text field followed by one or more hostnames
  • Each field is separated by one or more white spaces (blanks or tab characters)
  • Comment lines are indicated by a hash character (#) in the first position of the line
  • Entirely blank lines in the file are ignored

Hosts File Uses

  • A Windows computer does not consult with DNS when it finds an entry in the hosts file
  • This is useful for connecting to servers that are in development and not ready for an Internet presence
  • The host file entry allows developers to assign a host header to the site for binding in IIS even though there are no DNS records for the site
  • Only those folks with the correct host name and ip address in their hosts file will be able to connect to the web application

Host File Caveats

  • Windows makes it hard to locate the hosts file
    • Use the View tab on Tool > Folder Options in the Windows Explorer to make the hosts file visible
    • Select "Show hidden files, folders, and drives"
    • Uncheck "Hide extensions for known file types"
    • Uncheck "Hide protected operating system files (Recommended)"
  • Windows makes it hard to manage the hosts file
    • Verify Windows did not add a txt or other file extension to the hosts file when you save it
    • If Windows won't let you access the hosts file, open the Windows Explorer as an administrator and try again
    • Consider running msconfig.exe to disable User Access Control (UAC) if access problems persist
    • If Windows won't let you save the hosts file over an existing hosts file, save it to the desktop, and then move it to the \drivers\etc folder
  • If you add a host file entry on your local computer, you also need to add a host file entry on the server with the 127.0.0.1 address
  • It is important to remove the host file entry on your local computer when a DNS Address or CNAME record is created for the server, unless you need to override the DNS record

Sources