Pinterest Stumbleupon Whatsapp

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 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] 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 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] 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 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 (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, 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 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

Leave a Reply

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