How Do I Change My Hosts File?

What Is a Hosts File?

The hosts file is used by your local computer's operating system to map hostnames to IP addresses. The hosts file is a plain text file, and is usually named hosts.

A typical hosts file will have one or more lines referencing your local computer (as 'localhost'). A hosts file can be edited to override your network settings and thus allow your local machine to view a website prior to the DNS changes propagating.

127.0.0.1 localhost
123.45.67.89 www.example.com
#98.76.54.32 www.anotherexample.com

Add the second line in this example to your hosts file, but:

  • Replace "123.45.67.89" with the server IP that HostGator provided you in your welcome email.
  • Replace "www.example.com" with your actual domain name.

You may comment out a line (to deactivate it) by prefacing it with a "#" (as in the third line above).

The following instructions are advanced steps for different operating systems.

Note: Please keep in mind that the normal wait time for propagation of nameservers is 48 hours. Remember to edit your hosts file after propagation has finished. This allows you to make sure that your network connection is performing as expected.

Windows

Windows users are able to edit their hosts file directly from their PC.

Windows 8

  1. Select the Start key and locate Notepad. (If you do not see it on your current Start page, type "Notepad" and press Enter).
  2. Right click on Notepad. You will see options appear on the bottom portion of the Start Page.
  3. Select Run as administrator.
  4. Browse to C:/Windows/System32/Drivers/etc and open the hosts file.
  5. Make the needed changes, as shown above, and close Notepad.
  6. Save when prompted.

Windows 7 or Vista

  1. Browse to Start > All Programs > Accessories.
  2. Right-click Notepad, and select Run as administrator.
  3. Click Continue on the UAC prompt.
  4. Click File > Open.
  5. Browse to C:/Windows/System32/Drivers/etc.
  6. Change the file filter drop-down box from Text Documents (*.txt) to All Files (*.*).
  7. Select hosts, and click Open.
  8. Make the needed changes, as shown above, and close Notepad.
  9. Save when prompted.

Windows XP and Lower

Note: Before reading these instructions, consider watching the video tutorial.
  1. If you are using Windows, use "Start," "Find" and "Files and Folders" to find a file in your windows directory (or WINNT\system32\drivers\etc) called hosts.
  2. Verify that the file is not "read only" by right-clicking it, and choosing Properties.
  3. Open the file for editing with Notepad. There should already be an entry for "localhost." Be sure to follow the same format when inserting the HostGator IP and the domain name.
On Windows98 and Windows95, the order may be hostname, IP address.

On Windows2000 and WindowsME, the order is IP address, hostname.
  1. Save this altered hosts file and close Notepad. Make sure Windows did not silently save the file as hosts.sam. The filename has to be hosts.
You may also need to reboot for the change to take effect. The next time you visit your domain, your browser will try to find the domain at the corresponding IP instead of looking up the IP through DNS.

Mac OS X

Follow the instructions below to edit your hosts file if you are running Mac OS X.

  1. Open the Terminal application. Start by typing Terminal on the Spotlight or by going to Applications > Utilities > Terminal.
  2. Open the hosts file by typing in the Terminal that you have just opened:
    sudo nano /private/etc/hosts

    Note: Some versions of Mac OS X will lock permissions on the hosts file (the file is marked as immutable). In the event this happens, use the following command instead: sudo chflags nouchg /private/etc/host
  3. Type your user password when prompted.
  4. The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 localhost). Simply append your new mappings underneath the default ones. You can navigate the file using the arrow keys.
    123.45.67.89 domain.com www.domain.com
    Replace "123.45.67.89" with the server IP that HostGator provided you in your welcome email. Replace domain.com with your actual domain name. Additional domains, subdomains or addon domains (such as www.domain.com) can be added at the end of the line, separated by spaces.
  5. When done editing the hosts file, press Control-o to save the file.
  6. Press Enter on the filename prompt, and Control-x to exit the editor.

UNIX

On Unix-based systems, you can find the hosts file at /etc/hosts. Most distributions of Unix will have terminal located in the same location.

To open the terminal:

  1. Go to Menu.
  2. Select Applications.
  3. Choose Accessories.
  4. Select Terminal.

 

To edit the hosts file:

Unix users can edit hosts files in the same process as Mac users. Please refer to steps 2 through 4 in the Mac section above.


DNS Flush

Once you have modified your hosts file, it is recommended that you flush your DNS so that the new changes can be implemented more swiftly. DNS flushing must be done using command line. Depending on your computer's OS, there will be different commands.

For more information on Flush DNS, please see the following related article: