The hosts file is a local file on your computer or device that maps domain names to IP addresses.
So why we should be editing this file? It’s simple, you can use this file to test websites and servers without changing DNS domain records. Let’s say you need to test a website before going live (changing the domain records) and make sure all works great. The Hosts file will help you do that testing.
Where is the Hosts File Located?
Windows 10 – C:\Windows\System32\drivers\etc\hosts
Linux – /etc/hosts
Mac OS X – /private/etc/hosts
Editing the Hosts file in Windows
- Click the Windows button and type Notepad in the search bar.
- Right click on Notepad and then Run as Administrator.
- You’ll be asked, “Do you want to allow this app to make changes to your device?”. click Yes.
- In Notepad, choose File then Open.
- Navigate to C:\Windows\System32\drivers\etc\ then select on the hosts file.
- Add the IP address followed by the domain name at the end of the file. Save the file.
Example: 102.54.94.97 acme.com - Flush your DNS cache, Click the Windows button and search command prompt. And type: ipconfig /flushdns
And that is it. Next time you type on your browser: rhino.acme.com it will go to 102.54.94.97 (as an example), instead of the original DNS domain record. So you can test your new website or server.
Once you are done testing, don't forget to remove the hosts entry, save and flush your DNS cache (step 7).