Edit Hosts File on Windows 10

Hosts file is an important system file which maps the host/site names with its IP addresses. Basically, it translates the hostname to IP and IP to hostname. In other Words, the hosts file is similar to using a phone book to find the matching phone number of a specific person’s name. Hosts file is a plain text file without any file extension. On Windows computer, We can edit hosts file on Windows 10 For custom domain redirects, block websites, or remove malicious entries set by malware. It functions like a local copy of a DNS server.

Edit hosts File on Windows 10

While Domain Name System – or DNS – is mostly used for this function (being a centralized and half-automatically managed name resolution system), the HOSTS file can be used as a local name resolution mechanism, and when used in conjunction with other name resolution mechanisms such as DNS, the HOSTS file takes precedence over them.

Location of the Hosts File

In Microsoft operating systems, the HOSTS file is located in the following location:

C:\Windows\System32\Drivers\etc

Host File Location

How To Edit Hosts file

Some Times we need to edit the Hosts file, For Different purposes like custom domain redirection, block certain websites, or remove malicious entries set by malware. We can modify the host files using Notepad but, As This is a system file we cant modify this with normal user account, We need administrator rights. For this we need to open Notepad As ( Admin )

Click on the Start menu, Type notepad From Search Results right-click on Notepad and select Run As Administrator. Here on notepad click on file, Select open and Browse for the following path : C:\Windows\System32\Drivers\etc

Here Select All Files from the drop-down menu and double click on hosts file.

open Host files

This will open Host files As Shown Bellow image. Here you can custom Redirect domain names, Block Certain websites ( Domain ) or remove malicious entries set by malware.

Windows Host File Edit

Note: To modify the hosts file, you need to add two entries, including the IP address of the remote host or application to a the friendly address you want to use. for ex: Type the IP address of the remote host or localhost followed by the domain or computer name you want to use to reach the device or application. Then Click on File, and select Save.

How the Hosts File Works

The Host File contains lines of text that are made of IP addresses followed by one or more host names or fully qualified domain names (FQDNs). Each field is separated by white space (blanks or tabulation characters).

For example, if you wanted to use the HOSTS file to translate a hostname of a computer called “FTPserver” into the IP address of 192.168.1.100, Then We need to Add Bellow line:

192.168.1.100  FTPServer

The HOSTS file can also translate Fully Qualified Domain Names (or FQDNs) of computers, such as ones used on the Internet.

For example, if you wanted to add a manual line to translate an FQDN of a computer called “webserver.domain.com” into the IP address of 11.06.23.100 you would add this line:

11.06.23.100 webserver.domain.com

When you ping it, your computer will resolve the name to the correct IP address:

Redirect a Website Using Host File

You Can Redirect Any Website to Another website by modifying the Host file. For Ex: you want your To Redirect YouTube.com to Twitter.com Means when you open Youtube.com on your web browser it automatically redirects to twitter.com.

For this first we need the Twitter’s IP address. we can Get this by using the ping command. Open command prompt by click on Start type cmd and hit the enter key. Now type ping twitter.com -t you will see the twitter.com  numeric IP address.

get twitter IP

Now on Host file Add the Twitter IP Space and The Domain Name

104.244.42.193 youtube.com

Block Websites using Host file

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

Create Website Shortcuts using Host file

You can also modify host file 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:

104.244.42.193 t

Create Website Shortcuts using Host file

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

Block website using Hosts file

If you want to block your computer from accessing certain websites, you can use the loopback address (127.0.0.1) followed by the domain name (e.g., 127.0.0.1  website.com)

simply add the following entry on Host file and save.

127.0.0.1   blocksite.com

Ex : 127.0.0.1 facebook.com

127.0.0.1 youtube.com

Block Websites using Host file

Remove malicious entries set by malware

Also Sometimes Due to Virus / Malware infection you may notice certain Websites not open on your computer. This is Because malware automatically edits your Host file and make Different entries for Domain Redirection (Ex: Any domain Name automatically Redirect to specific Website ) or Block some websites.

Simply open Host file on Notepad and Clear Other entries set by Malware adware. And left the default entries as shown bellow host file.

Default host file entries

Lock Hosts file to prevent hijacking

As sometimes malware/ Adware redirect web address by altering your host files. A good latest updated antivirus can prevent this hijack but if you want to add another layer of security then the second option is to lock the hosts file so no other program or user except you can rewrite to it without unlocking it.

To prevent Host file hijacks, you may navigate to it, right-click on it, select Properties and make it a Read-only file. This will lock down your Hosts file and prevent anyone or any malware from writing to it.

Lock Hosts file to prevent hijacking

That’s All About edit hosts file on Windows 10. Note that after making any modification on Host files Restart windows to take effect the changes you have done. I hope now you can easily Modify, Edit hosts file on Windows 10 to Custom Domain Redirection, Block Different Websites etc. Feel any Difficulty while edit host files discuss on comments below.

Robeg
I am Robeg founder of this blog. My qualification. completed Bachelor of Arts (BA) and Microsoft Certified Professional (MCP). With a strong background in computer applications love write articles on Microsoft Windows (11, 10, etc.) Cybersecurity, WordPress and more.