Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Facebook Twitter Instagram
Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Tech News Today
Home»Windows»How To Edit Hosts File on Windows 11

How To Edit Hosts File on Windows 11

Abhishek SilwalBy Abhishek SilwalJune 2, 2022
windows-11-hosts-file

A hosts file is a text document inside the %windir%\system32\drivers\etc folder. You can use it to resolve hostnames before the DNS. It maps the hostname to static IP addresses, which your browser directly loads without going through the DNS server.

Developers often use it to verify their web services before launching them in the public domain. But you can also use it for blocking malicious or offensive websites.

Table of Contents

  • How to Edit Hosts File in Windows 11
    • Edit Hosts File Using Text Editor
    • Edit Hosts File Using Command Prompt
  • Things You Can Do With the Hosts File
    • Block Websites Using Hosts File
    • Redirect Websites Using Hosts File
    • Bypass Network Credential Checks
  • Troubleshooting Host Files Not Working
    • Flush DNS Cache
    • Check Hosts File
    • Disable DNS over HTTPS (DoH) Encryption
    • Check Registry Configuration
    • Check Encoding
    • Reset Hosts File Permissions
    • Recreate Default Hosts File
    • Use Alternate TLD
    • Disable Proxies or Add Exception

How to Edit Hosts File in Windows 11

There are mainly two ways to edit the Hosts file. You can either use a text editor or the CLI.

First, backup the hosts file. Then, apply one of the methods we have provided below.

Edit Hosts File Using Text Editor

Since Hosts is a text file, the usual method of editing it is to use a text editor. You can use the notepad to edit it. Remember that you need a text editor and not a word processor like MS Word or Wordpad.

Follow the steps below to edit Hosts using the notepad:

  1. Press Win + R to open Run.
  2. Type notepad and press Ctrl + Shift + Enter to run it as administrator.
  3. Press Ctrl + O to open a file.
  4. Type %windir%\system32\drivers\etc on the address bar and press Enter.
  5. Set the drop-down box for the file type to All Files.
  6. Select hosts and click Open.

Now, add your IP and domain data to the end of the file while keeping the following facts in consideration:

  • The syntax is IP (Spacebar or Tab)Domain. For instance, 192.168.1.1 www.example.com.
    edit-hosts-file
  • Your system reads lines or line segments starting with # as comments.
  • You can add multiple host domains for the same IP. 
  • For instance, 192.168.1.1 www.example.com example.com example.test example2.com
  • You can’t use more than 150 characters or 8 hosts in a single line.
  • example.com, www.example.com, and m.example.com are all different, even if they all refer to the same website. So, set the static IP for all of them.

Then, press Ctrl + S to save the file.

Edit Hosts File Using Command Prompt

You can also use the Command Prompt to edit the Hosts file. Here are the necessary steps for the process:

  1. Open Run.
  2. Type cmd and press Ctrl + Shift + Enter to open it with admin permission.
  3. Enter echo “IP” “DOMAIN” >> %windir%\system32\drivers\etc\hosts while replacing “IP” and “DOMAIN”. It appends the “IP” “DOMAIN” line at the end of the hosts file.
  4. Check the previous method for more information on the host entries.
  5. Enter type %windir%\System32\drivers\etc\hosts to verify the modifications.
    edit-hosts-cmd
  6. You can also enter ping “DOMAIN” to check if it resolves to the IP you set.

Things You Can Do With the Hosts File

Some main uses of the hosts file are as follows:

Block Websites Using Hosts File

The most common use of the hosts file is to block certain websites. To do so, you must use an unreachable IP for the hosts. For instance, the localhost, which is the computer you’re using, has the IP 127.0.0.1. So resolving any domain to this address opens a “This site can’t be reached” page.

For example, if you add 127.0.0.1 www.google.com on the hosts file, entering www.google.com on a browser won’t load Google. You can use any other nonexistent IP address as well.

It is especially useful in blocking malware, ad tracker, and spam links. You can find the hosts for such links on the internet.

Redirect Websites Using Hosts File

You can also redirect any URL to a server with a dedicated IP. It doesn’t work if the server uses CDN or virtual hosts. It also fails if the security certificates of the two websites do not match. 

Here’s an example of the process. We are trying to open www.abc-example.com while entering www.xyz-example.com on a browser. 

  1. Open Command Prompt.
  2. Enter ping “DOMAIN”. For example, ping www.abc-example.com.
  3. It displays the IP address for the domain.
  4. On the hosts file, add “IP of abc-example” www.xyz-example.com.
  5. Save and exit.

Now entering www.xyz-example.com on a browser’s address bar will open www.abc-example.com.

Bypass Network Credential Checks

You can also bypass the check for network credentials on a server with static IP by editing the hosts file. This happens because the file forces a DNS resolution.

So, add the IP address and hostname on the hosts file to avoid the security box while accessing a remote server.

Troubleshooting Host Files Not Working

There are many potential reasons for your hosts file not working. So, we have provided similarly varied solutions for each cause. Apply them individually and check if they work.

Flush DNS Cache

The DNS cache may still contain the old hostname resolution data. So, flush the cache and enter the name on a browser again. It’s better to delete the NetBios cache as well. Follow the instructions below to delete both cache data:

  1. Open Command Prompt as admin.
  2. Enter the following commands:
    ipconfig /flushdns
    nbtstat -R

Check Hosts File

It is also possible that you haven’t entered the name resolution codes properly. First, check if the hosts file has an extension. On the file explorer, select View > Show and tick File name extensions. Make sure to remove its extension if it has any.

Then, edit the file in a text editor and perform the following:

  • Check the syntax.
  • Remove any trailing spaces. Also, make sure to use tabs or spaces but not both.
  • Ensure that you haven’t commented on the necessary section by using the # symbol.
  • Set the static IP for all URL forms, such as www.example.com, example.com, and m.example.com.
  • If there are more than 150 characters or 8 host entries on a line, divide them into multiple lines using the proper syntax.

Disable DNS over HTTPS (DoH) Encryption

With DNS over HTTPS encryption, your browser bypasses the hosts file on Windows 11. So, you need to disable this feature on your browsers to use the file. The methods for some browsers are as follows:

On Chrome

  1. Go to Settings > Privacy and security > Security.
  2. Toggle off Use Secure DNS.
    chrome-secure-dns

On Firefox

  1. Go to Settings > General and click Settings under Network Settings.
  2. Uncheck Enable DNS over HTTPS.

On Edge

  1. Go to Settings > Privacy, search, and services.
  2. Toggle off Use secure DNS to specify how to lookup the network address for websites.

If you want to use DoH Encryption, you can enable it directly for Windows 11. Doing so allows you to use this security feature together with the hosts file’s DNS resolution. Here’s what you need to do:

  1. Open Settings and go to Network & internet > Hardware properties.
  2. Look for DNS Server Assignment and click Edit next to it.
  3. Set the drop-down box to Manual and toggle On IPv4.
  4. Enter the DNS servers you want. We recommend using public servers such as:
    • Google – 8.8.8.8 and 8.8.4.4
    • Cloudflare – 1.1.1.1 and 1.0.0.1
  5. Set the DNS encryptions to Encrypted Only (DNS over HTTPS).
    windows-11-doh
  6. Click Save.
  7. Then, perform the same process for IPv6. The public servers are:
    • Google – 2001:4860:4860::8888 and 2001:4860:4860::8844
    • Cloudflare – 2606:4700:4700::64 and 2606:4700:4700::6400
  8. For some devices, you need to replace :: with :0:0:0:0: in the servers.

Check Registry Configuration

Your system uses a registry entry to check for the hosts file location. So, check this entry and ensure that it specifies the correct path. But before that, it’s better to back up your registry to account for any unexpected mistakes. Then,

  1. Open Run and enter regedit.
  2. Navigate to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
  3. Double-click on DataBasePath.
    databasepath-hosts-file
  4. Set the Value data to %SystemRoot%\System32\drivers\etc.

Check Encoding

The hosts file can only have ANSI or UTF-8 without BOM encoding. The methods to edit the file that we mentioned in this article do not change its default encoding. But if you created another text file to replace the original, you may have set another encoding format.

To check, open the host file in a notepad and select File > Save as. Then, ensure that Encoding is ANSI or UTF-8 (not with BOM).

If it’s not, use the steps in the next method to replace it with another hosts file, but with proper encoding.

Reset Hosts File Permissions

If there are problems with the hosts file’s permission settings, your browsers can’t access them. You can create another host file and replace it with the original one to reset their permissions.

  1. Open notepad and copy the contents of the hosts file.
  2. Click File > Save as.
  3. Set the Save as type to All files and the File name to hosts.
  4. Set Encoding to UTF-8 and click Save.
    save-as-hosts
  5. Copy (not move) the file to the %windir%\system32\drivers\etc folder and replace the file.
  6. Open the elevated Command Prompt and enter icacls %SystemRoot%\System32\drivers\etc\hosts.

Recreate Default Hosts File

Sometimes malware programs can also edit the hosts file without your consent. So, first, scan your PC with an antivirus. Then, recreate the file with default contents. Here’s how you can do so:

  1. Create a backup of your hosts file, just in case.
  2. Open notepad and enter the following:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column, followed by the corresponding hostname.
# The IP address and the hostname should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1       localhost
# ::1             localhost
  1. Save the file as hosts replace the original file using the steps from the previous method.
  2. Open the elevated Command Prompt and enter icacls %SystemRoot%\System32\drivers\etc\hosts.

Use Alternate TLD

Many users used to create virtual host domains with the .dev TLD. However, it is no longer possible as Google now owns this Top Level Domain. So, it’ll redirect it https://*.dev instead of http://*.dev.

So you need to use an alternative TLD such as .test for your domain.

Disable Proxies or Add Exception

Some proxies bypass the hosts file lookup. So, it’s better to disable them if you want to use the hosts file DNS resolution. To do so,

  1. Open Settings and go to Network & internet > Proxy server.
  2. Toggle off Automatically detect settings.
  3. Click Set up next to Use setup script.
    proxy-disable
  4. Toggle the switch to Off and click Save.
  5. Do the same for Manual proxy setup.

You can also add the exceptions for the manual proxy setup. Type the hostnames or IPs in the text box under Use the proxy server except for. Don’t forget to separate individual ones with a semicolon.

how-to
Abhishek Silwal
  • LinkedIn

Abhishek Silwal is an Electronics Engineer and a technical writer at TechNewsToday. He specializes in troubleshooting a wide range of computer-related issues. His educational background in Electronics Engineering has given him a solid foundation in understanding of computers. He is also proficient in several programming languages and has worked on various robotics projects. Even in his early days, he used to tinker with various computer components, both hardware, and software, to satiate his curiosity. This experience has given him a breadth of experience that goes beyond his educational qualification. Abhishek has been writing articles on dealing with varieties of technical issues and performing specific tasks, especially on a Windows machine. He strives to create comprehensive guides on fixing many system and hardware issues and help others solve their problems. You can contact him at abhisheksilwal@technewtoday.com

Related Posts

amd-software-not-opening

How to Fix AMD Software Not Opening

March 3, 2023
how to create a folder

7 Ways to Create a Folder on Windows

March 3, 2023
turn off automatic updates windows

How to Turn Off Automatic Updates on Windows

March 2, 2023
Memory-Compression

What is Memory Compression in Windows? Should You Enable or Disable It

March 1, 2023
dism-vs-sfc-vs-chdsk

DISM, SFC, CHKDSK: What’s the Difference

February 28, 2023
how-to-open-exe-file

4 Ways to Open EXE File

March 2, 2023
Add A Comment

Leave A Reply Cancel Reply

Latest Posts
Memory-Compression

What is Memory Compression in Windows? Should You Enable or Disable It

March 1, 2023
dism-vs-sfc-vs-chdsk

DISM, SFC, CHKDSK: What’s the Difference

February 28, 2023
bios-settings-for-gaming

Best BIOS Settings for Gaming

February 16, 2023
You may also like
how-to-clean-hp-printer-rollers

How to Clean HP Printer Rollers

March 3, 2023
keyboard input lag

9 Ways to Fix Keyboard Input Lag

March 3, 2023
keyboard key is stuck

How to Fix a Stuck Key on a Keyboard

March 3, 2023
Recommended
Cookie Clicker Garden Guide

Cookie Clicker Garden Guide to Unlocking Every Seed

September 26, 2021
monitor no signal

Computer Turns On But Monitor Says No Signal (9 Ways To Fix)

November 10, 2022
Facebook Twitter Pinterest
  • Home
  • About Us
  • Our Team
  • Editorial Guidelines
  • Privacy Policy
  • Affiliate Disclosure
© 2023 TechNewsToday, editor@technewstoday.com | Tech Central Pvt. Ltd.

Type above and press Enter to search. Press Esc to cancel.