The “hosts” file is used to configure domain names (hosts) from your computer directly and avoid the “domain resolution” process from a standard DNS query. With the hosts file, you can choose where (on what IP address) your domain resolves to.
Often used during migrations of websites, this tip is very convenient when you want to preview and diagnose your website on a different server without touching the DNS entries which were already configured.
Hence why the changes made on your computer’s hosts file are local to your machine and will not affect other computers or users.
Locate the hosts file
The “Hosts” file location varies, depending on which Operating system is installed on your personal computer:
- Windows 95/98/Me c:\windows\hosts
- Windows 8 c:\windows\system32\drivers\etc\hosts
- Windows 10 c:\windows\system32\drivers\etc\hosts
- Linux /etc/hostss
- Mac OS X /etc/hosts
How do I configure my Hosts file?
As an example If you want to your “domain.example” to resolve at address 184.108.40.206 you should open your “hosts” file with a text editor and add the following line:
220.127.116.11 domain.example www.domain.example
Once this line has been saved in your hosts file it will tell your computer to reach directly the page at 18.104.22.168 and avoid passing a typical “DNS resolve” query onto your internet service provider.
After having saved my “Hosts” file it does not work!
The changes are only taken into effect when all the caches are empty this includes the following: Web browser(s) or the Operating system’s own DNS cache for the changes made in your hosts file to take effect.
- Close all web browser windows
- Flush your DNS cache
Launch a CMD window with administrator privileges and type the following command at prompt:
For Mac launch the “terminal” from finder and type the following command at prompt: