The hosts file in the Windows operating system is known to only a small fraction of users, yet it is quite useful. You need to modify the hosts file if you want to force Windows to assign a different IP address to a domain than the one provided by the DNS server. On our hosting, we commonly use this trick during website migrations. When migrating a website from one server to another, we insert the new IP address of the website into the hosts file, restart the browser, and can then check how the website behaves on the new server. Afterward, it's safe to update the IP address of the website on the DNS servers, ensuring the migration proceeds smoothly.
How to Do It
You can usually find the hosts file at: C:\Windows\System32\drivers\etc\
Don’t be surprised that the file doesn’t have an extension; simply open it with Notepad. Next, you need to add a line to the hosts file, for example:
178.238.41.70 mydomain.com
This tells the operating system to display content from the server at 178.238.41.70
for the domain mydomain.com
.
Reversing the Process
You can also use the hosts file to block websites by redirecting them to a nonsensical address, such as 127.0.0.1
(localhost):
127.0.0.1 facebook.com
This tells the operating system to display content from 127.0.0.1
for the domain facebook.com
. Since Facebook does not operate on this address, the user will see only a browser error message.