Windows guy learns linux hosts files

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

Now if you went into your host file and put an entry like…
    Google.com    204.79.197.200
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]”

image

Hit Ctrl+O to save the file and then Ctrl+X to exit.

Now if you go to “http://google.com” (not http://www.google.com because we did not create an entry for that) you should see something like this…

image

Boom, all done.  Now you’re a hosts file expert.  Make sure to delete that line if you want to use Google again normally.

One thought on “Windows guy learns linux hosts files”

Leave a Reply

Your email address will not be published. Required fields are marked *


× 4 = sixteen

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>