How to Modify Your hosts File Using Windows

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?

Thoughts on “How to Modify Your hosts File Using Windows

  • 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.

    • 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.

  • 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

    • 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.

  • 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. 

  • 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.

  • 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.

  • 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.

  • 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?

    • 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.

  • 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. 

  • 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. 

    • 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.

  • 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.

  • 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

  • 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

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

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

    • 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.

  • 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
    • 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.

  • 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

    • 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.

  • 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

    • 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

  • 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

    • 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

  • 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?

  • 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

     

    • 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.

    • 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.

  • 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.

  • 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. 

    • 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

  • 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.

    • 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 http://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

  • 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

    • 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.

  • 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.

  • 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.

  • 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

    • 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

  • 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!

    • 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

    • 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.

  • 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

  • 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

    • 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 http://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.

  • 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. 

    • 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.

Leave a Reply