WEB HOSTING SUPPORT NETWORK
     
 

Using your local hosts file

This tutorial will show you how to edit your local hosts file, so you can view and test a website without changing the DNS of the domain.

What is the hosts file?

The hosts file is a system file on your computer that maps hostnames to IP addresses. You can consider it your computer's local DNS. When you connect to a hostname, your computer checks for matching records in your hosts file. If no matches are found in your hosts file, your computer checks for records in the global DNS.

Editing your hosts file

To edit your hosts file, you will need to perform different actions depending on your operating system. You can find step-by-step instructions for the most widely used operating systems listed below:


Windows

  1. Press ⊞ Win+R on your keyboard to open the Run application.
  2. Input the following command in the Run application window:

    notepad %WinDir%\System32\drivers\etc\hosts

  3. Press Ctrl+⇧ Shift+↵ Enter to open your "hosts" file in Notepad with administrator privileges.
    Note: A pop-up window may appear asking you to confirm that you wish to grant administrator privileges to Notepad.
  4. To add a new mapping to your hosts file, add a new line at the end of the file in the following format:
    __IP_ADDRESS__ __HOSTNAME_1__ __HOSTNAME_2__You will need to replace the variables listed above as follows:
    • __IP_ADDRESS__ with the IP address for your hosting account. More information on how to find your hosting account's IP address/es is available in the "IP addresses and DNS service" article.
    • __HOSTNAME_1__ and __HOSTNAME_2__ with your website's hostnames (i.e. your-domain.com and www.your-domain.com).
    Note: You can insert a comment to the hosts file by adding a hashtag (#) character at the start of a new line or after a custom mapping followed by your comment.

    Example: If your hosting account's IP address is 123.123.123.123, and your domain is your-domain.com, you will need to add this line to your hosts file:
    123.123.123.123 your-domain.com www.your-domain.com
  5. Press Ctrl+S to save your changes to the hosts file.
  6. Clear the cache of your browser.
  7. Clear your local DNS cache.

macOS

  1. Go to "Finder" > "Applications" > "Utilities" > "Terminal" to open Terminal.
  2. Input the following command in Terminal:

    sudo nano /etc/hosts

  3. Press ↵ Enter to open your "hosts" file with the GNU nano text editor.
    Note: Editing the "hosts" file requires administrator privileges, so you will be asked to enter your Administrator password.
  4. To add a new mapping to your hosts file, add a new line at the end of the file in the following format:
    __IP_ADDRESS__ __HOSTNAME_1__ __HOSTNAME_2__You will need to replace the variables listed above as follows:
    • __IP_ADDRESS__ with the IP address for your hosting account. More information on how to find your hosting account's IP address/es is available in the "IP addresses and DNS service" article.
    • __HOSTNAME_1__ and __HOSTNAME_2__with your website's hostnames (i.e. your-domain.com and www.your-domain.com).
    Note: You can insert a comment to the hosts file by adding a hashtag (#) character at the start of a new line or after a custom mapping followed by your comment.

    Example:
    If your hosting account's IP address is 123.123.123.123, and your domain is your-domain.com, you will need to add this line to your hosts file:
    123.123.123.123 your-domain.com www.your-domain.com
  5. Press Ctrl+O to save your changes to the hosts file.
  6. Clear the cache of your browser.
  7. Clear your local DNS cache.

Linux

  1. Open a Terminal window. The default keyboard shortcut is Ctrl+Alt+T.
  2. Input the following command in Terminal:

    sudo nano /etc/hosts

  3. Press ↵ Enter to open your "hosts" file with the GNU nano text editor.
  4. To add a new mapping to your hosts file, add a new line at the end of the file in the following format:
    __IP_ADDRESS__ __HOSTNAME_1__ __HOSTNAME_2__You will need to replace the variables listed above as follows:
    • __IP_ADDRESS__ with the IP address for your hosting account. More information on how to find your hosting account's IP address/es is available in the "IP addresses and DNS service" article.
    • __HOSTNAME_1__ and __HOSTNAME_2__ with your website's hostnames (i.e. your-domain.com and www.your-domain.com).
    Note: You can insert a comment to the hosts file by adding a hashtag (#) character at the start of a new line or after a custom mapping followed by your comment.

    Example: If your hosting account's IP address is 123.123.123.123, and your domain is your-domain.com, you will need to add this line to your hosts file:
    123.123.123.123 your-domain.com www.your-domain.com
  5. Press Ctrl+O to save your changes to the hosts file.
  6. Clear the cache of your browser.
  7. Clear your local DNS cache.