FacebookTwitterLinkedIn

How to Edit Hosts File on Windows 10?

What Is the Hosts File and How to Edit It on Windows 10

Hosts.txt is an operating system file that maps hostnames to IP addresses. In this article, we are going to show you where to find hosts file how to edit it.

edit hosts file

The hosts file is a plain text (.TXT) file. In modern operating systems, the hosts file is an alternative name resolution mechanism, often configurable as part of facilities such as the Name Service Switch as either the primary method or a fallback method.

The hosts file is one of several system facilities that assists in addressing network nodes in a computer network. It is a common part of an operating system's Internet Protocol (IP) implementation. It serves the function of translating human-friendly hostnames into numeric protocol addresses, called IP addresses, that identify and locate a host in an IP network.

With the hosts file you can change the IP address that you resolve a given domain name to. This change only affects your computer without affecting how the domain is resolved worldwide.

The hosts.txt file may sometimes be used by malicious software such as adware, computer viruses, trojan horses etc. These applications may use the Host file to redirect traffic from the intended destination to sites hosting malicious or unwanted content.

That is why some antivirus software may monitor changes to the hosts file, preventing malicious software from modifying it. So does Windows, and unless you use elevated permissions to edit the file, Windows will prevent you from saving it. Read the article below to find out how to edit the hosts.txt file.

Video Showing How to Edit the Hosts File on Windows 10:

Table of Contents:

Edit Hosts File Using Notepad

Notepad is a simple text editor for Microsoft Windows and a basic text-editing program which enables computer users to create documents. Notepad is a common text-only (plain text) editor. The resulting files - typically saved with the .txt extension - have no format tags or styles, making the program suitable for editing system files to use in a DOS environment and, occasionally, source code for later compilation or execution, usually through a command prompt.

To open Notepad, type "notepad" in Search and right-click on the "Notepad" result, select "Run as administrator" to run it using administrative privileges.

edit hosts file using notepad step 1

Now click "File" and select "Open...", then find this directory: "C:\Windows\System32\drivers\etc\hosts" and click "Open". Make sure that you selected "All Files" option above the "Open" button.

edit hosts file using notepad step 2

Make the changes and click "File" then select "Save".

edit hosts file using notepad step 3

To force the changes on your Windows system you will need to use "ipconfig /flushdns" in Command Prompt. Ipconfig is a command-line tool that displays the current configuration of the installed IP stack on a networked computer. Using tool, we can flush and reset the contents of the DNS client resolver cache and renew DHCP configuration.

The commands require an elevated Command Prompt opened with administrator privileges. Command Prompt is the input field in a text-based user interface screen, a command line interpreter application available in most Windows operating systems. It is used to execute entered commands. Most of those commands are used to automate tasks through scripts and batch files, perform advanced administrative functions, troubleshoot and solve certain kinds of Windows issues. To use Command Prompt, you must enter a valid command along with any optional parameters. Then it executes the command as entered and performs whatever task or function it's designed to perform in Windows. Some commands available in Windows require that you run them from an elevated Command Prompt. To open elevated Command Prompt, type "command prompt" in Search and right-click on the "Command Prompt" result. Choose "Run as administrator" to run it with administrative privileges.

edit hosts file using notepad step 4

When you select "Run as administrator", a User Account Control prompt will appear asking if you allow the Command Prompt to make changes to your computer. Click "Yes".

edit hosts file using notepad step 5

Now type the "ipconfig /flushdns" command and press Enter on your keyboard to execute it.

edit hosts file using notepad step 6

[Back to Table of Contents]

Prevent Hosts File From Hijacking

When you type in a URL in the address bar in your browser, it queries a DNS to try and resolve the domain name to an IP address. However the hosts file can be used to bypass this process as it checks the host file before querying the DNS. Hijack.host Malware is a suspicious program, being flagged as a potential computer virus of the Adware family, by a number of security databases. Adware is a type of malware easily recognizable by the numerous unwanted advertisements or ads for short it subjects the affected users to. If you want to prevent your hosts file from hijacking you need to "lock" it. Go to this directory again: "C:\Windows\System32\drivers\etc\hosts", right-click on hosts file and select "Properties" in the dropdown menu.

prevent hosts file from hijacking setp 1

In hosts Properties window check the "Read-only" box and click "Apply" to save the changes made.

prevent hosts file from hijacking setp 2

[Back to Table of Contents]

Block Websites

Repeat the steps mentioned in the "Edit Hosts File Using Notepad" topic and when you open the hosts file using Notepad, simply type this line: "127.0.0.1 www.blockthissite.com". Change "blockthissite" to any other site that you want to be blocked/prevented from accessing using your computer. Do not forget to click "File" and select "Save" when finished.

block websites

This means that you are telling Windows is that the website www.blockthissite.com should redirect to the IP address 127.0.0.1, which is just the loopback address on our local system. If you don't have a local website setup on your computer, you'll just get an error page in your web browser.

That's it, we hope that was helpful and now you know what is a hosts file, what it is used for, how to edit it and how to block websites on your computer and prevent hosts file from being hijacked.

[Back to Top]

▼ Show Discussion

About the author:

Rimvydas Iliavicius

Rimvydas is a researcher with over four years of experience in the cybersecurity industry. He attended Kaunas University of Technology and graduated with a Master's degree in Translation and Localization of Technical texts. His interests in computers and technology led him to become a versatile author in the IT industry. At PCrisk, he's responsible for writing in-depth how-to articles for Microsoft Windows. Contact Rimvydas Iliavicius.

Our guides are free. However, if you want to support us you can send us a donation.

About PCrisk

PCrisk is a cyber security portal, informing Internet users about the latest digital threats. Our content is provided by security experts and professional malware researchers. Read more about us.

Malware activity

Global malware activity level today:

Medium threat activity

Increased attack rate of infections detected within the last 24 hours.