How to use the “hosts” file?

The hosts file is used to map hostnames to IP addresses. With the hosts file you can change the IP to which you resolve a certain domain name.

This is particularly useful when you wish to see how a website will look when hosted on a different server without having to wait for a DNS change to propagate, or avoiding any DNS changes at all.

The path to the hosts file, depending on the operating system you are using, is:

  • Windows - SystemRoot > system32 > drivers > etc > hosts (by default the system root is c:Windows, so if you are using Windows, your hosts file is most probably c:Windows/system32/drivers/etc/hosts)
  • Linux - /etc/hosts
  • Mac OS X - /private/etc/hosts

Now let's say that you wish to resolve your domain to IP In this case the entry you should add to your hosts file would be:

In Windows 7 you might have difficulties editing the hosts file due to the required access level. In order to edit the file navigate to Windows -> Start.  Search for Notepad, right-click on the corresponding icon and select Run as Administrator. This should launch notepad with elevated privileges. Next, open the hosts file from the File menu, edit and save it.

For the permission issue, try the following steps:

Take ownership of the hosts file and change the permission for it.

1. Right click on the hosts file and click Properties.
2. Switch to the Security tab and click on the Advanced button.
3. Navigate to the Owner tab and click Edit….
4. Highlight your user account or the Administrators group and click OK twice to quit the Advanced Security Settings dialog box.
5. On the Security tab under the Properties dialog box click Edit….
6. Highlight the Administrators group, check the box for Full control under Allow and click OK.

You may need to clear your cache before you can properly resolve the domain to the new IP.


  1. Reply August 7, 2015 / 20:38 Melinda GallagherSiteGround Team

    How do I change the host file on my chromebook?

    • Reply August 10, 2015 / 15:55 Ivan StefanovSiteGround Team

      You could edit hosts file on Chromebook by:

      1.) Editing the hosts file from a Developer Chromebook:

      sudo /usr/share/vboot/bin/ --remove_rootfs_verification --partitions 2

      2.) Using a proxy-extension which is pretty much the alternative of hosts file for Chromebook

      • Reply January 6, 2016 / 16:56 SeanSiteGround Team

        This doesnt work for myself. I can VIM and edit but when i quit and write it still says read only.

        • Reply January 7, 2016 / 08:15 Hristo PandjarovSiteGround Team

          Change its permissions using the chmod command 🙂

  2. Reply August 27, 2015 / 08:26 massimoSiteGround Team

    how do i change the host name in godaddy?

    • Reply September 1, 2015 / 07:49 Marina YordanovaSiteGround Team

      Hello Massimo, this article concerns the hosts file that is on your personal computer. If you want to change the name server of a domain name with GoDaddy, it would be best to contact their support directly for assistance.

  3. Reply February 8, 2016 / 23:06 JoySiteGround Team

    I entered /private/etc/hosts into my chrome browser on Mac. What comes up says: "Do not change this entry" and I can't figure out how to change it anyway. Can you please start me at the very beginning because I think I am missing something in your directions.

    • Reply February 9, 2016 / 09:49 Ivan YordanovSiteGround Team

      You can edit the hosts file using the Terminal by using some of the text editors for example:

      vim /private/etc/hosts


      nano /private/etc/hosts

      Alternatively, you can use the Finder's function Go To Folder and navigate to /private/etc/hosts (Finder -> Go -> Go To Folder) and then double-click on the file in order to open it with a text editor.

  4. Reply March 14, 2016 / 22:14 RobertSiteGround Team

    Please explain how to do this on linux

    • Reply March 16, 2016 / 14:30 Hristo PandjarovSiteGround Team

      The same way, just edit the /etc/hosts file 🙂

  5. Reply June 18, 2016 / 12:36 Diego GomieroSiteGround Team

    Just one more trick fow those having problems editing hosts on Windows.

    Copy the hosts file and paste it to your Desktop. Edit this Desktop version. Save it.

    Copy from Desktop and paste it back in original place.

  6. Reply August 26, 2016 / 23:14 Anthony BurciagaSiteGround Team

    Ok, so I am having an issue here. I do not want to access just the HTML files, I would like to view the website in it's entirety before redirecting the domains. I would also like to update a new theme to the site that is hosted on siteground. My issue is that I am unable to access the siteground hosted website because it seems like they are both using the same URL? Please help, ASAP. I am working on another individuals website and I am unable to get passed this issue.

    • Reply August 29, 2016 / 06:01 escalationsSiteGround Team

      This article explains in details how to make your local computer work as if the website is already pointed to a SiteGround server. This will allow you to test the website in its entirety on the new server since it will not open from the old one, but from the new IP address you have entered in your hosts file.

  7. Reply August 26, 2016 / 23:16 Anthony BurciagaSiteGround Team

    Also, I am on an Apple computer as well. Would it be easier to access the FTP folder through dream weaver or work off of a local host than upload all of the files?

    • Reply August 29, 2016 / 05:59 escalationsSiteGround Team

      Whichever is more convenient for you.

  8. Reply October 25, 2016 / 05:09 David HasseSiteGround Team

    How can I edit my wordpress website in offline by modifying the host file ? all i know is how to modify the host file !

    • Reply October 27, 2016 / 10:11 Ivan StefanovSiteGround Team

      David, in order to modify WordPress when you are offline, you should download the website locally on your machine and open it from there.

  9. Reply November 20, 2016 / 21:56 Sean AllenSiteGround Team

    Seems strange that it is not possible to have a preview url hosted from the cPanel/IP address in 2016. This feature is standard with all serious hosting providers.

    • Reply November 24, 2016 / 11:14 Ivan StefanovSiteGround Team

      Sean, there actually is an option to access your site through IP using cPanel mod_userdir option. You can do that by typing server IP_address/~username or by going to your User Area -> My Accounts -> Information & Settings -> Access Site by IP

  10. Reply December 15, 2016 / 16:06 LindaSiteGround Team

    What program does the file need to be associated with to perform the action - I'm getting an error message when I click on 'hosts'


    • Reply December 20, 2016 / 14:04 Ivan StefanovSiteGround Team

      Linda, the file should be edited with a text editor (in Unix-like systems and MACs you can open it with "vim" for example)

  11. Reply January 7, 2017 / 18:26 markSiteGround Team

    Way too confusing. I moved to site ground to get away from all the confusion.

    • Reply January 9, 2017 / 09:50 Ivan StefanovSiteGround Team

      Mark, if you do not like the "hosts" file procedure, I recommend you to use the website. It is an online hosts file converter and will allow you to preview your website from the IP address you want to, instead from the server where it is currently pointed.

  12. Reply January 18, 2017 / 15:16 Mary HillSiteGround Team

    I am lost. Where do I find this file? In my WordPress editor? How does changing the domain on my personal computer change things? This is so very, very confusing!

    • Reply January 18, 2017 / 19:41 escalationsSiteGround Team

      Yes changing a file on your personal computer will tell your computer to open a website at a specific location. The alternative to this is checking the website using a proxy service that simulates editing your hosts file such as:

* (Required)