
The hosts file is used to map hostnames (in other words domains) to IP addresses. With the hosts file you can change the IP address that you resolve a given domain name to. This change only affects your own computer without affecting how the domain is resolved worldwide. This is particularly useful when you wish to see how a website will look like when hosted on a different server without making any DNS changes to your domain.
The location of the hosts file, depending on the operating system that you are using, is:
- Windows, your hosts file is most probably: C:\Windows\System32\drivers\etc\hosts)
- Linux – /etc/hosts
- Mac OS X – /private/etc/hosts
To set this up, all you do is use a text editor and use admin privileges as needed to edit the file. From there, we use the following layout:
- <yourIpRedirect> <yourDomain.com> <www.yourDomain.com>
- 0.0.0.0 webfm.com www.webfm.com
- 127.0.0.1 webfm.com www.webfm.com
- 192.168.1.8 webfm.com www.webfm.com
- 172.217.5.4 webfm.com www.webfm.com
It’s worth noting that you can not add an IP port here and some names you give as the domain don’t always redirect if you’re going to a site than sinking it to your localhost address. Also, if you have a local server, simply append the port to the domain when accessing it. So, http//webfm.com; via the browser would look like:
- http://webfm.com:<portNumber>