Each operating system has a hosts file that allows you to overwrite IP addresses returned for domains/hosts from DNS server or assigning other names or aliases to IP address. Hosts files are widely supported and have been for name resolution prior to DNS servers, hosts files grew to massive sizes and had to be kept somewhat in sync. This comes in very handy if you want to preview your website on a new server after migration before updating your main domain DNS server records or simply lets you work on the website using a domain name that isn’t yet registered or using temporary URL’s. Changes to hosts file only affect the computer on which they are made.
Hosts file syntax is the same across all platforms. To modify your hosts file simply edit it like so
and save your changes. As a result of which any request made from that computer to any of those names will be sent to the server with IP address 220.127.116.11 regardless of what address is returned for domain.com or www.domain.com or server.domain.com or server by DNS server.
Hosts file editing instructions for specific operating systems
Windows 8 & 10
Press the Windows Key, in the search box type Notepad then right click on its icon in the search result and select Run as administrator.
When in Notepad click File - > open and hosts file located in C:\Windows\System32\Drivers\etc\hosts
Make your changes and click File - >Save for them to take effect.
Windows Vista & 7
Click Start -> All Programs -> Accessories then right-click on Notepad icon and select Run as administrator.
When in Notepad click File -> Open and select C:\Windows\System32\Drivers\etc\hosts.
Make your changes and don’t forget to save then File -> Save for them to take effect.
The hosts file is a system file thus requires root privileges to make changes. In a root terminal window using your preferred editor make your changes to /etc/hosts file much like so Save your changes for them to take immediate effect.
Open Applications -> Utilites -> Terminal in the terminal window edit /private/etc/hosts file like so Make your changes and don’t forget to save them. For changes to take effect DNS cache needs to be flushed with command