How to Modify Your hosts File Using Windows

Don’t have time to read our full article? Watch our walk-through video.

What is a hosts File Modification?

A hosts file modification is a simple tweak that is used to “trick” your computer into resolving to a specific IP. This is especially useful when developing your site on our server when your nameservers are not pointed to us yet. This is necessary when you are working with domain-name-dependent software (ie: Content Management System (CMS), such as Joomla! or WordPress).

How Does a hosts File Modification Work?

DNS vs. hosts File Modification info-graphic depicting the path of routing a domain to an IP from different devices after performing a hosts file modification on your computer.

The image (to the right) depicts the process of resolving a domain to an IP address using various devices. In the image, the hosts file on “Your Computer” has been modified with the following code:

86.75.30.9 example.com
86.75.30.9 www.example.com

Since the hosts file was only modified on “Your Computer“, only that device will resolve the domain: example.com to the IP address: 86.75.30.9.

Other devices, that do not have the hosts file modified, will resolve to the IP address: 172.16.0.0, found in the DNS zone–present in the name servers that the domain is pointed to.

 

How to Modify Your hosts File

Follow the sections below to learn how to perform a hosts file modification.

Run Notepad as administrator

To modify your hosts file, you will need to first run Notepad (or any other text editor available to you on the same computer) as administrator. This is because the hosts file is a system file and cannot be modified without elevated privileges. Note: If you are running Windows XP or lower, you won’t need to run it as administrator as this functionality only exists in Vista and above. Locate Notepad within your Start menu. If it is not already there, you can type “notepad” into the search box to show it. Then, right-click on it and click on “Run as administrator”.

Open Your hosts File

After you have Notepad up and running as administrator, you can then locate your hosts file and open it. While not all Windows versions store it in the same place, it is typically located within c:\windows\system32\drivers\etc and the filename is: hosts. If you do not see it there, other possibilities are as follows:

  • Windows 95/98/Me c:\windows
  • Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc
  • Windows XP Home/Vista/Windows 7 c:\windows\system32\drivers\etc
  • Windows 8 c:\windows\system32\drivers\etc
  • Windows 10 c:\windows\system32\drivers\etc

Now, you need to open your hosts file. With Notepad already open, click on “File”, then “Open…”. As the hosts file is not a standard .txt file that Notepad will look for by default, you will need to change the drop-down in the bottom right that says “Text Documents” to select “All Files”. Finally, navigate to the location of your hosts file and double-click on it to open the file using Notepad.

Find the IP Address Associated with Your Account

  1. Log into cPanel
  2. To the right, you should see a column of stats describing your account. Look for Server Information and click on that link.
    cPanel main

  3. Scroll down to where you see “Shared IP address”. If you have a dedicated IP, it will say “Dedicated IP” instead. This is the information that you will need for your hosts file mod.
    Server information

Edit Your hosts File

Now that you have the correct file open, it’s time to modify your hosts file. Within your hosts file, you should see something similar to the following:

# Copyright (c) 1993-1999 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. 
# Each entry should be kept on an individual line.
# The IP address should be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one space.
# Additionally, comments (such as these) may be inserted on individual lines
# or following the machine name denoted by a '#' symbol.
# For example:
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost

Using the information you have gathered you will add some lines to your hosts file. They will look something like this:

202.133.229.123 my-wordpress-site.com
202.133.229.123 www.my-wordpress-site.com

After making the change, click on “File”, then “Save”. You have now made your hosts file modification.

Additional Windows 8/10 Necessary Steps

Configuring Defender in Windows 8 to Modify Your hosts file

If you are using Windows 8, Windows Defender is running by default and it prevents you from being able to modify your hosts file. You will need to allow this file to be edited by going into Windows Defender and performing the following steps:

  1. Navigate to Windows Defender by hovering over the right corner to bring up the navigation bar. Click on the icon that appears to be a magnifying glass to start a search. Type in “Windows Defender”, click on the icon that appears. It will be labeled “Windows Defender.” Click on this icon and the application will launch.
  2. When Windows Defender opens, click on the tab labeled Settings.
  3. Next, type in the location of the hosts file based on the location of the Windows installation. Here’s the default path: c:\windows\system32\drivers\etc\hosts
  4. Click on the Add button and you’ll see it added to the list beneath the file locations.
  5. Click on Save Changes in the bottom right and then close Windows Defender.
  6. The next step will be actually editing the file. As per the instructions above, you will need to edit the file as an Administrator. Hover over the right side again, and then search for “Notepad”. Open it as an administrator.
  7. Open the file as per your HOSTS file path.
  8. Make your edits, and click on SAVE by clicking on “File” to bring up the menu. This completes the HOSTS file edit in Windows 8.

Working with Windows 10 to Change Your Hosts File

When you are working with Windows 10, the main concern you will need to address before you begin is being able to modify your hosts file. You will need Administrator access in order to make the change. If you have any questions concerning administrator access please see Microsoft’s definition of an Administrator for Local accounts or speak with a local Windows administrator. In Microsoft’s documentation, local accounts means “on your computer.” Follow the steps below to quickly and easily make changes to the hosts file.

  1. Log in as your Administrator User
  2. Right-click on the Windows icon in the toolbar.
    text

  3. A pop-up menu will appear. Look for Powershell (Administrator) then click on this option.
    text

  4. You will see a Window notification pop-up asking if you wish to allow permission for the application to make a change. Click on Yes to continue.
    text

  5. When the prompt appears, type in Notepad. Since you are launching Notepad from the Powershell Administrator, it will launch the application with the appropriate administrator permissions.
    text

  6. In the Notepad menu, click on File, then click on Open. You will need to navigate to the folder that contains the hosts file. This is the typical path: c:\Windows\System32\drivers\etc.
  7. If you do not have show hidden files enabled in your Windows File preferences, you will not see any files. However, type in Hosts, then hit enter. Notice that the file does not have an extension – it’s just “hosts.” This will bring up the Hosts file. Since the Hosts file is a system file, it will be hidden unless you set your Windows file preferences to show hidden files.
    text

  8. At this point, you will see the hosts file. As per the instructions above you will need to have the IP address of the server where you trying to point the URL. Make sure that you follow the example provided and put a space between the IP address and the domain name that you wish to use.
    text

  9. Click on File, then click on SAVE in order to save any changes that you may have made to the file.

As a precaution close the Notepad window and then re-load the hosts file per the beginning steps and double-check to see that your changes have been applied.

How do I know that it worked?

The easiest way to see that it worked is to just go to your domain. Does it show your new site as it should on our servers? If there were no changes to your site from when you moved it, you might need to run a ping test to ensure that it shows the correct IP.

Flushing Your DNS Cache

After you modify your hosts file, if your computer has cached your DNS, you will need to clear it. Luckily, we have an article that can teach you how to do just that:

How do I clear my local DNS cache?

Learn more about DNS server management with our Managed VPS Hosting Product Guide.

Upgrade to VPS Hosting for Peak Performance

Upgrade to InMotion VPS Hosting today for top-notch performance, security, and flexibility, and save up to $2,493 – a faster, stronger hosting solution is just a click away!

check markDedicated Resources check markNVMe SSD Storage check markHigh-Availability check markIronclad Security check markPremium Support

VPS Hosting Plans

AC
Arnel Custodio Content Writer I

As a writer for InMotion Hosting, Arnel has always aimed to share helpful information and provide knowledge that will help solve problems and aid in achieving goals. He's also been active with WordPress local community groups and events since 2004.

More Articles by Arnel

74 thoughts on “How to Modify Your hosts File Using Windows

  1. I have modified host file like 127.0.0.1 example.com for vb.net project (For development purpose).
    When I am building my project in Visual Studio 2017 (Windows 7), The page showing error “This site can’t be reached example.com refused to connect ERR_CONNECTION_REFUSED”
    Can you please help me on this issue, How can I solve this issue.

    1. Your hosts file modification should look like:

      202.133.229.123 my-wordpress-site.com
      202.133.229.123 www.my-wordpress-site.com

      Where the IP address is the IP address of the server where you are hosting the website files and the domain you are using to build the website. I hope this helps. If you need further assistance, please reply back with more details regarding the precise steps you are taking.

  2. I have followed instructions for this but it doesn’t work…

     

    This is what I have saved in my hosts file:

     

    and this is what happens when I try to ping it:

    Reply

    1. The HOSTS modification only applies to the computer where the change has been applied. We would need to know how you are testing this in order to determine why it’s not working. Many developers use this and it is a function of the operating systems for computers. If you were to run a traceroute or ping the site, it would reflect how the outside world sees that URL – NOT how your computer sees the URL after the HOSTS change. I hope that helps to clarify the issue.

  3. There were no changes to the site, and when I   run a ping test there it shows the correct IP address. Thank you for this article. 

    1. We have a guide on how to do it on a MAC at the link below.

      https://www.inmotionhosting.com/support/website/how-to/how-to-edit-your-hosts-file-on-a-mac

  4. Thanks for your wonderful support DNS vs hosts file modification support that is very useful for the system and it resolves the particular IP. this is very good and I used this and it very useful.

  5. I have modified my own host file that is very useful for us. When I ping on my local computer it returns the correct IP address on the shared computer. your website Article is good and how I find my own IP.

  6. My computer did the same thing because even though I was an Administrator account, I didn’t open the program as an Administrator, but I was able to get around it by opening wordpad as admin before looking for the hosts file. Just type “wordpad” in the windows search box. Right click on the wordpad program or app icon and select “Run as Administrator”. Once in the wordpad program pull down the file menu, select open file, navigate to the proper directory (C:\Windows\System32\drivers\etc\hosts) in Windows 10. On the bottom right select to show all files instead of just wordpad files and double click on hosts to open. After you add the line(s) to the bottom of the hosts file, select “save” and you are done.

  7. I followed the instructions

    But when I go to save the updated hosts file it wont let me because it says it is read only.

    I am definitely run ning notepad as an administrator. I even tried to get rid of the read only status of the file, but it wont let me do that either.

    I have tried on multiple computers multiple times 

    ANYONE KNOW HOW TO RECTIFY THIS?

    1. Since you are advising that you are running Notepad as the Administrator, I recommend you use an alternative text editor. You can always use Window’s cmd application to open the file as the root/administrator user and modify the hosts file accordingly. Other than that, I recommend you contact Microsoft to advise why Notepad, running as Administrator, is unable to modify that file.

  8. I’m not able to save the hosts file on either of my computers despite having adin access. I’ll reach out to support to see if we can talk this through. 

  9. It’s not clear by the thread you linked to what the end solution was. Could you summarize it? 

    If I can’t get this issue solved in order to stage my sites offline while working on it, I won’t be able to use InMotion Hosting at all. 

    1. So is the issue you’re not able to edit your hosts file? Or is the issue you’re not sure on how to set up a development environment? We want to help you but we need more information.

  10. I followed the directions to modify the Hosts file on Windows 7, running as an administrator. I also cleared the DNS cache. But when I try to save the file I always receive the following error message: “The process cannot access the file because it is being used by another process.”

    I exited my browser and other open programs, tried again, and received the same error message.

    1. Looks like they answer how to solve that here:
      https://forums.techguy.org/threads/solved-the-process-cannot-access-the-file-because-it-is-being-used-by.1051872/

  11. Hi john Paul,

    thank you for the reply.

    123.456.789.012 example.com

    When i have added this to my host file browser redirected me to inmotion servers and i am able to access the wesite. but when i accessed  example.com/wp-admin it is taking me back to old server. It is showing the dashboard located on previous hosting.

     

    Thanks,

    Gaurav

  12. Hi,

    Article was very enlightning. 

    I was able to access the website on inmotion hosting by doing modifications on my Hosts file as

    123.456.789.012 example.com

    But the problem is I am using wordpress site and i need to access the dashboard of the website. its giving Error 400 : not found.

    123.456.789.012 example.com/wp-admin

    can you please suggest the solution on this.

    thanks

    Gaurav

  13. I edited the host file and I was able to view my website on through inmotion but after returning the host to the default configuration. I noticed I can access certain websites. example: www.innov8systemsng.com; www.fgasuleja.gov.ng

    Please help.

    1. The hosts file only changes the routing for the specific domains you enter into it. It will not affect any other sites.

  14. I could find the IP address associated with my cpanel account. I hope it is not the general shared IP address.

  15. i have update the hosts file but after soe time the hosts file is come on the deault condition. I am using Windows 7 Please tell me how can i update and save the hosts file.

    https://www.starscollege.edu.pk/

    1. Hello Hamzasheraz,

      The method to change the hosts file in the article above is correct. If you’re having problems with it, then you need to speak with a pc tech. Remember that any changes to the hosts file require that you have administrator access to the Windows files.

      If you have any further questions, please let us know.

      Kindest regards,
      Arnel C.

  16. After modifying the hosts files as described, when I try to access my domain, I receive a “Privacy Error” as shown below.  (I’m using Google Chrome):
    Your connection is not private
    Attackers might be trying to steal your information from rhymeswithmartini.blog (for example, passwords, messages, or credit cards).
     

    NET::ERR_CERT_COMMON_NAME_INVALID

    1. Hello Jasmine,

      Sorry for the confusion with the message from Google’s Chrome browser. If you have a website where passwords are being passed, google will flag the site in order to warn you that the site is not using an SSL connection. If you know you’re connecting to a particular server (which you designate in your hosts file), then you can ignore that message.

      If you have any further questions or comments, please let us know.

      Regards,
      Arnel C.

  17. This was a very helpful article and thank you for the video of baby steps on how to do this properly! I will bookmark this page for future reference.

    ~Jubilee

  18. An excellent advice!

    But what happens if the website has multiple pages, for example www.anexistingdomain.com/support or www.anexistingdomain.com/contact? Should i modify the hosts file further and include these too? like:

     

    123.456.789.012 www.anexistingdomain.com/contact

    123.456.789.012 www.anexistingdomain.com/support

     

    Thanks in advance!

    1. Well, it depends on how your website links are set up (like in the menu) but normally all you have to add is the Top Level Domain and it will cover the entire website. The exception which is rare, would be if you have used IP addresses for links within the pages.

  19. I owe a website. Ichanged my host from hostitsmart to basezap.

    Now only on my college wifi network, i am seeing my old hosting, rest everywhere i can see the proper new hosting.
    Please help

    1. First, I recommend removing any host file modifications related to your domain.

      If you recently made DNS changes (such as Nameserver, or ‘A record’) this could be a result of propagation.

      If it has been longer than 24 hours, you need to clear your local DNS cache.

      Thank you,
      John-Paul

  20. Hi All,

     

    Thanks for the information. I made the changes but as soon as i restart the system , the host file comes back to the original contents and deleting the changes made.

     

    Regards,

    Majid

    1. Hello Majid,

      As that is something on your local system, it is not something we can troubleshoot from here. You may want to keep a copy of the hosts file so you can replace it when you restart. This issue can be caused by security apps on the machine, so may want to set the hosts file to Read-Only after you change it to see if that helps.

      Kindest Regards,
      Scott M

  21. I have modified my hosts file.  When I ping on my local computer it returns the correct IP address on the shared computer.  However it displays the home page of luzoft.com

    I have done this with two different domains.  Luzoft.com keeps coming up.  any idea why?

  22. I Want to block all URL and want to allow only one uRL which i am using in both windows & Linux(Ubuntu OS)

    Kindly help me in this.

     Regards

    Rajasekar v

     

    1. Hello Sandeep,

      Check out this link on modifying the Windows 10 hosts file. You would need to modify it with the appropriate admin access in Windows.

      If you have any further questions or comments, please let us know.

      Regards,
      Arnel C.

    2. Hello Rajasekar v,

      I think you’re trying to block access via IP – you can’t really do that with URLs. You can block access to the website using .htaccess modifications. Check out this post concerning the topic.

      If you have any further questions or comments, please let us know.

      Regards,
      Arnel C.

  23. Hi

    i have update the hosts file but after soe time the hosts file is come on the deault condition. I am using Windows 10 Please tell me how can i update and save the hosts file.

  24. if u are unable to edit ur host file, simply copy the text from the host file and open another note pad with administrative privillage, paste the text and other text when u want, save the file by replacing the previous host file in c:\windows\system32\drivers\etc\hosts and u are done. 

    1. Hello Yuri,

      Thank you for contacting us. Your “hosts” file typically does not have a file extension, and is just named “hosts”.

      Thank you,
      John-Paul

  25. Thanks for reply but let’s be specific, If to access site the URL is https://192.145.237.216/~username/ then what the line in ‘hosts’ file should be to access it via https://amydomain.com  locally from my PC only?

    1. Hello Manly Electronics,

      You would put the following info into your Host File:

      192.145.237.216 amydomain.com

      Then you would visit amydomain.com and it will load https://192.145.237.216/~username/ automatically.

      Best Regards,
      TJ Edens

  26. The host file needs format: ‘IPaddress domain’ not ‘IP/somefolder/  domain’.  I do not see how it is going to work for users when their hosting is at something like at IP/~cpanelusername/. All instructions above and video example IP without a folder only.

    1. Hello Manly Electronics,

      You do not need to add a folder to the host file. Lets say for example I had a development environment on 192.168.1.1. I would put in the host file “192.168.1.1 domain.com www.domain.com”. This would allow me to go to domain.com/testing if I needed to. If you are using IP/~userna5 then you do not need to use a host file mod as it is only to trick your computer into thinking the domain has already resolved to another server.

      Best Regards,
      TJ Edens

  27. Website Migration Step 7
    The icon for the Original hosts file is clear file type displays “File.”
    Text file icon shows stripes and displays text document .
    Inmotion rep stated to save the new hosts file as txt, but all other file in Hosts folder display “file.” When I save the changed hosts file do I save as .txt or file?
    Thank you
    Richard Aldrich

    1. Hello Richard,

      Thanks for the question about the hosts file. Basically, the file is a text file, but should be saved as a file and NOT as a .txt file. It’s a system file that is not recognized if saved with the extension of .txt.

      I hope this helps to answer your question, please let us know if you require any further assistance.

      Regards,
      Arnel C.

  28. I attempted to do that Scott. But I can’t save the Host file after I’ve edited it.

    What format should the edited file be? I only have the option of saving as .TXT even when I run it as Admin.

  29. Hi,

    I just got your email that the transfer of my website is complete, but I have no idea if it worked or what’s the next step.

    When I try the temp URL, I get a site that doesn’t look like my site should (a version of a construction page that I did not use).

    When I type in the site’s URL I do see the construction page that I modified. 

    However, I don’t know what’s the next step. I’d appreciate some help now please. Thanks.

  30. I setup a joomla website on my windows server 2008.. now i wanted to view that outside local area network.

    the problem:

     

    I have this static ip address at home, whenever I input my home ip address at the office. It will forward me to my router which is dlink 600L.. which then asked my username & password.

     

    What I wanted is that, whenever I typed my static IP address, It will forward to my Joomla Webpage. 

    Thanks in advance for those who can help. I’m not good at this. Please Please help

    1. Hello Newbie,

      You will have to forward port 80 to your server which would have to be on the same network.

      Best Regards,
      TJ Edens

  31. I have transferred all my files from Yahoo to InMotion and placed all of them in the public_html folder in the cpanel. When I click the temporary URL the website does not come up just information saying that that it is activated but not showing, blah blah. My site is panicend.com. Am I doing something wrong? This is getting very frustrating. Thanks for any help!

    1. Hello Jeff,

      Thank you for your question. I tested your site on your Temp URL, and it seemed to be working successfully.

      Are you still having issues at this time?

      Thank you,
      John-Paul

  32. Hi to all

    please tell me that how can i block all website and allow only one wesite please tell me i am wating for your answers

    1. Hello Ali,

      Thanks for the question. You can actually use the same rules as you would use in blocking country IPs, except you would deny all and allow only the one IP address.

      <Limit GET HEAD POST>
      order allow, deny
      allow from 123.456.789
      deny from all
      </Limit>

      I hope this helps to answer your question, please let us know if you require any further assistance.

      Regards,
      Arnel C.

  33. Dear Ann,

    Thanks for your wonderful and swift support! I was able to get through. Actually i realised that I correctly edited the Host file, but in my browser forgot to type “www.”which was written in the host file.

     

    Look forward to your future support.

     

    Best regards,

    Mamie

  34. Thanks for enlightening us. I am working on a drupal site. To edit the host file, do I need to have a local server installed or not necessarily? Because I already edited the host file, but when i type the website address in the browser nothing loads.

    Also where in the host file should the IP address be inserted?

     

    Looking forward to your support

    1. Hello Mamie,

      Thanks for the question. You don’t need to have the local server installed to edit the HOSTS file. The IP address change should be done near the top with the other IP addresses. For example:

      # For example:
      #
      # 102.54.94.97 rhino.acme.com # source server
      # 38.25.63.10 x.acme.com # x client host

      127.0.0.1 localhost
      123.234.456.789 www.website.com

      You can insert the IP address and the corresponding URL right under the localhost entry. As per the example above. Remember that URL is very specific. So, if you put an entry of “123.234.456.789” and it corresponds with “www.website.com”, then ONLY when you type in “www.website.com” will that IP address apply. Developers often use this change so that they can see a website with the original URL, even if the rest of the world is seeing a different website coming from another IP address.

      I hope this helps to answer your question, please let us know if you require any further assistance.

      Regards,
      Arnel C.

  35. If i am in office and i user standard user account my IT department has block all socail media site from host file than How i detail host file without adminsatration account. 

    1. Hello Dipanjan,

      I think you’re asking if it’s possible to modify the HOSTS file without an administration account. Basically, you will not be able to make these changes without the proper access. You will need to speak with your IT department and get permission before making any HOSTS file changes.

      Kindest regards,
      Arnel C.

Was this article helpful? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X