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.
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: 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.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.comYou 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:
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. 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:
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 On Firefox On Edge 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:
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,
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.
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:
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, 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.