How To Edit Hosts File On Windows 10?

What Is Hosts File And How To Easily Edit Hosts File On Windows 10

The computer file hosts is an operating system file that maps hostnames to IP addresses. It is a plain text file. Originally a file named HOSTS.TXT was manually maintained and made available via file sharing by Stanford Research Institute for the ARPANET membership, containing the hostnames and address of hosts as contributed for inclusion by member organizations. In modern operating systems, the hosts file remains an alternative name resolution mechanism, configurable often as part of facilities such as the Name Service Switch as either the primary method or as 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, and 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 own computer without affecting how the domain is resolved worldwide. This is particularly useful when you want to see how a website will look like when hosted on a different server without making any DNS changes to your domain.

The hosts file may sometimes be used by malicious software such as adware, computer viruses, or trojan horses etc. These applications may use it 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, you will be prevented from saving it.

In this article we are going to show you where to find hosts file how to edit it. Read the article below to find out how.

how to edit hosts file

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 Table of Contents]

Video Showing How To Edit Hosts File On Windows 10:

[Back to Top]

About the author:

Tomas Meskauskas

I am passionate about computer security and technology. I have an experience of 10 years working in various companies related to computer technical issue solving and Internet security. I have been working as an editor for pcrisk.com since 2010. Follow me on Twitter to stay informed about the latest tech news or online security threats. Contact Tomas Meskauskas.

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