What Is the Windows Host File? And 6 Surprising Ways to Use It

Chris Hoffman 21-09-2012

The Windows Hosts file allows you to define which domain names (websites) are linked to which IP addresses. It takes precedence over your DNS servers How To Change Your DNS Servers & Improve Internet Security Imagine this - you wake up one beautiful morning, pour yourself a cup of coffee, and then sit down at your computer to get started with your work for the day. Before you actually get... Read More , so your DNS servers may say is linked to a specific IP address, but you can have go anywhere you want. The Windows Hosts file can be used to block websites, redirect them, create shortcuts to websites, create your own local domains, and more.


We’ve previously covered using the Windows Hosts file to block websites without installing any other software on your computer How To Block Websites On Your PC Without Using Software [Windows] Any website you visit potentially tracks your browsing habits, loads annoying ads, or distributes malicious software. Most of the time, common sense and standard malware protection software can help you steer clear of the worst... Read More – it’s often used for quick website blocking Block Inappropriate Websites With OpenDNS's FamilyShield Service I think it’s safe to say that for as long as the Internet has been around, there have always been inappropriate websites - and I’m not just talking about adult entertainment! Think of all the... Read More by geeks in the know.

Editing the Windows Hosts File

To edit your Hosts file, you’ll need to open Notepad (or any other text editor you like, such as Notepad++ 3 Handy Built-In Notepad++ Features For Beginners [Windows] This summer, I’ve used Notepad++ for my internship quite a bit, so I can see why almost all developers and programmers I know actually prefer it, not to mention, the thousand of Notepad++ fans that... Read More ) as Administrator. To do so, click Start, type Notepad into the Start menu, right-click the Notepad shortcut and select Run as Administrator.

After you have, click File and Open in the Notepad window, then browse to the C:\Windows\System32\drivers\etc folder. Click the Text Files box at the bottom right corner of the window, select All Files, and double-click the hosts file.

windows hosts file

Changes you make to the hosts file will take effect immediately after you save the file – you don’t have to reboot. If you’re adding multiple entries to your hosts file, ensure each is on its own line.


Block a Website

To block a website, add a line like the following one to the bottom of the hosts file:

windows hosts

What this does is simple – is the IP address’ of your local computer. When you navigate to, your computer will try to connect to itself ( Your computer probably won’t find a web server running on itself, so the connection will fail immediately, effectively blocking the website from loading.

windows hosts


Redirect a Website

You can also use this trick to redirect a website to another website. For example, let’s say we want to redirect to – so when we type into our address bars, we’ll end up at Twitter.

First, we’ll need Twitter’s IP address. To find it, we can use the ping command The 8 Useful DOS Commands That You Should Memorize Windows 7 still features a command prompt window. so there's still a place for DOS commands. So for those of you that like the idea of typing in a few commands to avoid the hassle of... Read More in a Command Prompt window A Beginner's Guide To The Windows Command Line The command line lets you communicate directly with your computer and instruct it to perform various tasks. Read More (click Start, type Command Prompt, and press Enter to open one). Type ping into the command prompt window and you’ll see Twitter’s numerical IP address.

windows hosts

Now we can add the following line to our hosts file:


This line tells our computer to connect to Twitter’s IP address. Type and you’ll end up at Twitter!

Create Website Shortcuts

You can also use this trick to create “shortcuts” that quickly access websites from any program on your computer. For example, if you’re a Twitter addict How to Use Twitter Twitter can be overwhelming at first, but we're here to help you make sense of it. Here's a complete guide to using Twitter and understanding how it works. Read More , you can associate “t” with Twitter – type t in any web browser’s address bar and you’ll instantly end up at Twitter. You can also create shortcuts with multiple letters, such as twit. You don’t need a .com, .net, .org, or any other type of extension. However, you can’t use spaces.

To do this, just add the following line to the hosts file and save it: t

You can get the exact IP address you’ll need by using the ping command mentioned above.


Now you can type t into any program’s address bar and you’ll end up at

windows hosts file use

Assign Local Domain Names

You can also create local domain names for your computers. For example, if you have a local server that you use, you can name it server and quickly access it by typing server as the URL into any program. If you frequently access your router’s configuration page, you can associate the word router with your router’s IP address and type router into your web browser’s address bar to access your router.

Note that you’ll need the computer or router’s IP address before doing this. After you have it, enter a line like the following – the following line associates, an IP address commonly used by routers, with the domain name router: router

You can replace the IP address and domain name here with anything you like.

Test a Web Server That Uses Host Headers

If you’re running a web server How To Set Up An Apache Web Server In 3 Easy Steps Whatever the reason is, you may at some point want to get a web server going. Whether you want to give yourself remote access to certain pages or services, you want to get a community... Read More on your local network, you may want to make sure it’s working properly before exposing it live on the Internet. Some web servers run multiple websites at the same IP address – the website you get depends on the host name you’re accessing. In cases like this, it’s not helpful to simply access the web server at its local IP address – you need to access it at its website addresses.

For example, if you have a web server with the local IP address that hosts websites for and, you can add the following lines to your local computer’s hosts file:

After saving the file, try to access both and in your web browser – if everything is working properly, you should see the different websites. The server notices your headers specify or and serves the correct website. If this doesn’t work, you have some troubleshooting to do before deploying the server on the Internet!

windows hosts file use

Block Lists of Websites

Some people create their own lists of websites they want to block and publish them online. You can block these lists of websites by copying one of these lists into your hosts file.

Check out the following article for some recommended lists you can use, along with a graphical tool that makes downloading these hosts files to your computer and using them easy:

windows hosts file

If you want to revert any changes you’ve made, simply delete the lines you added to the bottom of the file, then save the file.

What do you use your Windows hosts file for? Leave a comment and share any tricks you have!

Image Credit: Network Cables via Shutterstock

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Abdulwahab
    October 1, 2016 at 12:03 pm

    Great article. what about using hosts file to redirect to specific site in the localhost!
    Example: I have many sites under localhost like

    in hosts file it says: localhost
    which will redirect me to root of localhost.
    Now I want to create a new redirect to site1, so when I type "site1" in browser it should go directly to "http://localhost/site1"

    Can it be done using hosts file?

  2. Sanga
    June 7, 2016 at 1:02 pm

    Thanks for this, very useful for me.

  3. Edgar
    February 3, 2016 at 12:41 pm

    I need help. I tried blocking from the host file in C:\Windows\System32\drivers\etc, and when i save the host file, or overwrite the existing file, it says "access denied".

    I already opened notepad as administrator and I followed your steps mentioned above, but my pc won't allow me to continue.

    Also, according to your link //
    should I block opencandy as "" or as what was mentioned in the link, "*"? Should it matter if I input the *. characters before or not?

    • J Guy
      July 8, 2016 at 4:22 pm

      If you put the, '*xxxxx' expression in it will likely not work. I do not think Microsofts hosts file uses a wildcard system. Once should be able to add the domain in like this, '' and it will register that. It should then perform the action you specified to any website render requests within the specified domain. As for the access denied issue. Are you on an administrative domain account? If not running as administrator will not work. Also it is worth mentioning that Google chrome does not use the local hosts file, so if you are trying to utilize this tool to block certain requests then someone can work around it pretty easy. There are solutions to this issue though...

    • Michael
      July 23, 2016 at 5:59 am

      In many installations, "hosts" is a read-only file. So, before you open your editor, right-click on the "hosts" file name, unclick "read only" and click "Apply". Edit your file, being sure to save it without the .txt extension when you are done. Then, click "read only" again and hit "OK".

  4. Anal Patel
    February 2, 2016 at 6:47 am

    we are using proxy servers, when proxy server on I can't block facebook form the host file.
    Is there any other way to block facebook using proxy server ?
    plz reply.

  5. thecarpy
    December 9, 2015 at 9:38 am #also works on one line, thought I would share

  6. Ethan
    March 23, 2015 at 9:55 pm

    @wschloss you should not need to enable anything it should "just work" if you reply with what you are trying to do and or whats in your hosts file now that is not working i may be able to help.

    • Anonymous
      July 13, 2015 at 3:32 pm

      Thanks, it was embarrassingly simple; Notepad++ was saving as a hosts.txt, not hosts. A tip for anyone who might care; I always add site references (sometimes several) in config, script, batch, etc files so i remember why and how I did something; like this:
      # Great explanation of use of hosts file
      # //
      # EOF Note file must end with

  7. James
    February 22, 2013 at 4:09 am

    I noticed that even when a website is blocked using the hosts file it is still possible to ping the site. Is there a technique to block even the ping?

    • wschloss
      March 16, 2013 at 11:52 pm

      My browsers (3) don't seem to be respecting my hosts file changes. I'm pretty sure I modified it correctly. Does a service need to be enabled or some such? Thanks.

  8. Andile
    November 8, 2012 at 4:24 pm

    You are a life saver bra. Thanx alot

  9. jafar
    November 6, 2012 at 8:51 am

    It has been done on my computer thanks . But how can i put the comments on blocked site's Ex : this site blocked by HR Admin like this . if you don't mind please explain to me

    • Chris Hoffman
      November 7, 2012 at 5:42 pm

      Just include a line with a # symbol in front of it. Any line with # in front of it is ignored.

      In other words, do something like this:

      #This site was blocked by HR

  10. Anonymous
    October 6, 2012 at 7:54 am

    I always forget my router IP. thanks!

  11. venkatachalam ravindran
    September 28, 2012 at 6:09 am

    Thanks for the article. Blocking websites, using shortcuts like 'router' are very useful. Somehow the local hosts file seems to have been ignored...

  12. Pawan Kj
    September 26, 2012 at 4:41 am

    Thank you! this one is useful. Feature to explore without having a software to be installed :)

  13. HLJonnalagadda
    September 25, 2012 at 3:41 pm

    Awesome. I didnt know the hosts file had such utility.

  14. nk
    September 24, 2012 at 7:20 am

    can you tell me how to unblock blocked sites

    • CO
      December 15, 2012 at 3:47 pm

      Hi nk,

      You can work around blocked websites by using a proxy site that is not
      on the blocked list.

      Once you can access a proxy website through which you can access the blocked site, then you will be able to access those blocked site but only through the proxy. The proxy could be in the form of a proxy website or a remote machine that you have access to.

  15. GrrGrrr
    September 23, 2012 at 6:48 pm

    I liked the idea of using shortcuts. it will save a lot of keystrokes

    • HLJonnalagadda
      September 25, 2012 at 3:42 pm

      Yeah very useful!

  16. Marko Resnik
    September 23, 2012 at 9:27 am

    Cool. Now I can un-block any website that is unavailable in my region. Thank you, Chris Hoffman!

    • Hamada
      September 23, 2012 at 7:23 pm

      Marko, i think you didn't get it. This is not to un-block site that is unavailable in your region, it will not even help ((.
      Read the article again carefully and you will understand.

    • Hamada
      September 23, 2012 at 7:23 pm

      Marko, i think you didn't get it. This is not to un-block site that is unavailable in your region, it will not even help ((.
      Read the article again carefully and you will understand.

      • Chris Hoffman
        September 29, 2012 at 12:06 pm

        Correct, unfortunately this won't unblock sites -- it will block them though.

    • CO
      December 15, 2012 at 3:49 pm

      Hi Marko,

      You can work around blocked websites by using a proxy site that is not
      on the blocked list.

      Once you can access a proxy website through which you can access the blocked site, then you will be able to access those blocked site but only through the proxy. The proxy could be in the form of a proxy website or a remote machine that you have access to.

  17. Vijaynand Mishra
    September 22, 2012 at 10:30 am


    • tony mike
      March 29, 2015 at 2:46 pm

      Great post thanks lot. | Fipe.Net

  18. Sebastian Hadinata
    September 22, 2012 at 2:18 am

    Great Article, nice tips on using host file as Website Shortcuts.