The hosts file is like a local DNS that takes priority over the real DNS.
The average person won’t understand what that means. In other terms, the hosts file is a local map of “domain name” to an “IP address”. For example, normally Google.com would resolve to something like 22.214.171.124. If you go to http://126.96.36.199 you would see Google. http://www.Google.com is the same as http://188.8.131.52
Now if you went into your host file and put an entry like…
Then Google would point to Bing instead.
If you set Google.com to point to 127.0.0.1 then in that case it would point to your local Apache server.
To create a map, we enter the URL and IP address in the hosts file that lives in the /etc directory. (ie. /etc/hosts)
To modify the file we will use a text editor called nano. It is much easier than some of the other options. The hosts file is protected so we need to run as SUDO. So get to a terminal (Ctrl+Alt+T in Ubuntu) and run the following command.
#sudo nano /etc/hosts
You then enter your root password and can then add the line.
127.0.0.1 [TAB] Google.com
[TAB] is the tab key, not actually the word “[TAB]”
Hit Ctrl+O to save the file and then Ctrl+X to exit.
Boom, all done. Now you’re a hosts file expert. Make sure to delete that line if you want to use Google again normally.