What is the Mac Hosts file?
If a migration has been done and you want to check if the website is working correctly or simply want to see the website on a server where the DNS does not point, you will need to modify the hosts file on your Mac. This way the request will go where the hosts file points and not where the DNS takes it.
How to modify the hosts file on Mac?
Mac OS X has a tool called Terminal, which is the command console for other systems. We run this and type the following line
sudo nano /private/etc/hosts
It will ask for the root user's password, which usually coincides with the access password to the computer.
* NOTE: Keep in mind that while you type the password, it will not be displayed, not even the "*" symbol, and the cursor will move, just type it and press enter. This is managed this way for security reasons.
Hosts file on Mac:
What do we include in the hosts file?
We are not going to modify anything that is already in this file, we go to the last line and include the following one line below
First the IP of our server, our domain and then our domain with subdomains (www, webmail....)
example
123.123.132.123 myweb.com www.myweb.com
this way, even if the DNS of myweb.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