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 184.108.40.206. If you go to http://220.127.116.11 you would see Google. http://www.Google.com is the same as http://18.104.22.168
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.