How to edit the Hosts file in windows 11

Worapon Asavanik
4 min readMar 19, 2024

--

This Article Describes:
1.Overview
2.The advantage point
3.Hosts file configuration
4.Related use cases(Restrict access to a website, Access local private V-Sphere)

1.Overview

Why do we need to modify the Hosts file? Often, this approach is used to verify whether the server is prepared for production or not. It’s also employed when we need to transition the server to a new one.

(***Note: The hosts file has the highest priority; it ignores DNS server requests. It combines the first section, which is the IP address, with the second section, being the domain name.)

2.The advantage point

  • Testing Server Readiness for Production
  • Migrating to a New Server
  • Development and Testing
  • Bypassing DNS Changes
  • Blocking Unwanted Sites

3.Hosts file configuration

First, you need to navigate to this path, which is similar for many Windows systems.

C:\Windows\System32\drivers\etc

After that, open the hosts file with admin permissions.

You will see the following information about the hosts file.

By changing 1.1.1.1 to the IP server you are using, and replacing domain.com with your domain name.

1.1.1.1 domain.com (first section is IP Address, second section is domain name)

Now, open the Command Prompt to execute the ping command.

ping 1.1.1.1
ping domain.com

As a result, we can now ping domain.com using the IP address 1.1.1.1

4.Related use cases

First, in case we wish to block a specific website, for example www.facebook.com, first we ping www.facebook.com and the result is 157.240.8.35 and pingable.

after that we edit the hosts file.

2.2.2.2 www.facebook.com (first section is IP Address, second section is domain name)

Then, open the Command Prompt to execute the ping command.

ping www.facebook.com

The result is timed out, and we cannot access www.facebook.com anymore.

Second, in case is to access a local private vSphere
Once I tried to access the local vSphere using the URL http://<host_ip>, as shown in the following picture.

after I clicked on LAUNCH VSPHERE CLIENT button.

the result will shown that I cannot access with the error : DNS_PROBE_FINISHED_NXDOMAIN
(***this error indicates that the domain name you are trying to access does not exist in the DNS system you are using. This means there is no DNS data available for that domain name, preventing DNS from converting the domain name into an IP address.
In my case, the domain name has not been registered.)
So we can access by adding the line below in the hosts file.

<your_host_ip_you_want_to_access> <domain_name>

The domain_name always in the following picture.

After adding the line you now can access the local private vSphere.

Third use case, and this is really important! testing the web server or name server to ensure they are fully operational and ready before we point DNS to our new IP address. If we switch the DNS right away and the system encounters an issue, our service could go down (which would be a disaster, haha). For example: Let’s say my server is initially hosted on Server A, and I want to move it to Server B. I would first replicate the server from A to B. Then, on my local machine, I would modify the hosts file to point the DNS for the same domain (e.g., www.A.com) to the IP address of Server B — the new IP where I’ve set up the server. Meanwhile, Server A would still be operational for everyone on the internet as usual. If I can successfully ping the domain www.A.com and access it via the browser, then this indicates that Server B is ready for production. At that point, I can confidently point the DNS to Server B.

Before I say goodbye, every clap will be a great motivation for me ^-^.
bye bye

--

--