What is the Hosts file in Windows?
If a migration has been done and you want to check if the website is working correctly or simply want to view the website on a server where the DNS is not pointing, the hosts file on your computer must be modified.
Where is the hosts file located in Windows?
To modify this file, we need to know its location.
The location of the hosts file in Windows 8, Windows 7, Windows Vista, Windows XP is:
C:/Windows/System32/drivers/etc/hosts
How to modify the hosts file in Windows?
Depending on the version of our operating system, we will need to log in as an administrator or not (required from Windows Vista onwards).
If you do not need to log in as an administrator, you just need to edit the file from a notepad.
For the latest versions of the Microsoft operating system:
We must log in to the system as an administrator user.
Then we can go to the location previously indicated "C:/Windows/System32/drivers/etc/hosts" and modify the hosts file and save it.
Hosts file in Windows:
In this case, the website profesionalhosting.com will resolve to server 100.200.150.250
What do we include in the hosts file?
We are not going to modify anything that is already in this file, we are going to the last line and include the following one line below:
First, the IP of our server, our domain and then our domain with an alias (www, webmail....)
Example:
123.123.132.123 mywebsite.com www.mywebsite.com
This way, even if the DNS of mywebsite.com points to a server with an IP different from 123.123.123.123, when accessing the website from the computer with the modified hosts file, it will enter the server 123.123.123.132
Another example:
1.1.1.1 google.com www.google.com
2.2.2.2 webmail.google.com
If you include this in the hosts file on your computer and try to enter google.com, it will load the google.com website from the server 1.1.1.1
The subdomain webmail.com will try to load it from the server with IP 2.2.2.2