Ways to edit Hosts file and redirect sites on PC

What it means on Windows to edit the hosts file: to change a domain name, block, create shortcuts or redirect a website

On many guides we hear about hosts file on Windows as a tool that we can use to block sites or to block unwanted content, without knowing exactly what it is and what we can really do with it.

In the following guide we will show you how to edit the Hosts file and how to redirect sitesso as to be able to block them without having to use a dedicated program or extension, directing unwanted sites or content towards the empty page (i.e. the localhostwhich we have already discussed in the past).

READ ALSO -> How to block some sites on PC

1) What is the hosts file

The Windows hosts file is a system file that allows you to define which domain names (websites) specific IP addresses are linked to. This concept of “name resolution” may be difficult for some to understand, so it is worth giving a brief explanation.

Each website is inside a computer reachable from an IP address; to navigate on a site, however, it was not convenient to write a typical IP address, because it would have been difficult to remember. For this reason an association has been created between these numerical addresses and a word, type sitobello.comthat is called domain.

Telephone directories that maintain associations between IPs and domains are called dns servers and are an important component of Internet browsing, since they are the central addressing system (as also seen in the guides on how to use new DNS on PC And how to change dns on phone).

The Windows hosts file stores associations between IP addresses and domains locally, so as to avoid having to always contact the DNS to receive the correct association. However, by manually changing the association between IP and domain we can change the address of a site and block navigation on itperforming a forced redirect.

2) How to view the hosts file

To edit the Windows Hosts file all we have to do is press WIN+E on the keyboard, click on the address bar and enter the following path:


The window for selecting the notepad to use will open: for the purpose we can use the one integrated in Windows or rely on a manager of notes and special files such as Notepad++.

Alternatively we can open this path by pressing WIN+R and typing the same path seen above. If you don’t see it, open the app File Explorer Windows from the Start menu, press on This PC and let’s get to the path:


From here, just right-click on the hosts file, select open with and indicate Notepad or any other compatible app.

3) How to edit the hosts file

By changing the IP addresses associated with sites we can change the redirection or block the content altogether, which will no longer be displayed; any changes made to the hosts file take effect immediately after saving the file so there is no need to reboot the system. If you add multiple entries to the hosts file, make sure that each is on its own line and that there is no pound sign in front of it (otherwise they have no effect).

To make the space long, you must press the Tab key. If you have installed programs like Spybot, you will see many lines already added starting with; those are all dangerous sites that are blocked for safety locally.

4) Block in website with hosts file

To block a websitejust add a line similar to the following, at the end of the hosts file: is the IP address of the computer you are using (localhost): if you associate the domain with the IP address of this computer, it is obvious that it will not exist and the connection will immediately fail blocking the upload of the website.

There is no way to visit that site except by removing that line from the hosts file. This usage was already explained in the past in the how-to article Prevent your browser from opening and browsing virus sites from the hosts file.

Using a program like spybot (one of the best anti-spayware and malware programs) we can create a list of domains to block for security reasons.

Another trick that can come in handy is to redirect a website by changing its domain name. With the same principle as before, it is possible to define a rule so that, if you type in the browser, the Google site opens instead.

To do this you need to know the IP address of the target site which can be easily found using the Ping command in the command prompt. From the Start menu, type cmd in the search box or in Runopen the prompt, write ping and press Enter.

The result will be a response from which is the IP address to use in this example. In the hosts file you can then write:

This line tells your computer to connect to Google’s IP address when you visit

5) Create website shortcuts

With the hosts file, always adding a trivial line to the text file, you can also create shortcuts to get to a site. For example, it is possible to associate the “n” with or the g with

In this way, just by writing and pressing enter on the address bar of the browser, any browser, you navigate on You can create links with multiple multiple letters, such as tweet to get to or simply Facebook to get to (thus eliminating the extension .com, .net, .it etc.).

To create shortcuts to websites, just add a line like: ( is the ip of, found using the Ping command as in point 2).

6) Assign local domain names

If you are using a local server the hosts file it is convenient in offices but also at home it can be useful to reach the router configuration panel. So if, for example, the internal address of the router was the hosts file you can add a line that says: router

On the browser, just write the word router in the address bar to open the configuration panel.

7) Restore hosts file

To reset all the changes madejust delete the lines added at the end of the file and save it, making it clean again.

We do not recommend deleting it, as it is a system file: deleting the content inside is enough to get all the custom redirects cleaned.

If the hosts file has been affected by a virus we can keep it clean using a change cleanup program like AdwCleaneras also seen in the guide on free programs to clean PC from viruses and malware.


Now we know exactly what the hosts file is and how it can be useful to edit this file whenever we want block sites for minorsblock sites that show too much content and make them unreachable.

To quickly edit the Hosts file we can also use a program like Hostsmana small free tool that allows you to edit the hosts file in a more intuitive way and that includes some lists of domains to block for security reasons.

To learn more we can read our guides on how to block malicious sites from hosts file come on how to detect suspicious activity on your PC.


Professional writer with a passion for technology and all things related to personal computing. With years of experience in the field, William has honed his craft as an expert in writing about how to use PCs, laptops, mobile devices, and staying up-to-date with technological updates.

Related Articles

Leave a Reply

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

Back to top button