Find your hosts file
In windows your hosts file is located:
C:\WINDOWS\system32\drivers\etc\hosts
For windows you will need to open an editor as administrator to edit the file. Also you may need to disable your anti virus as it may prevent you from editing your hosts file. Just remember to enable the anti virus again as soon as you are done.
In linux your hosts file is located:
/etc/hosts
For linux you will need to use sudo to edit the hosts file.
Experiment with the hosts file
Add at the bottom of your hosts file:
127.0.0.1 moo
127.0.0.1 baa
127.0.0.1 moobaa
In your command line you can now ping these:
ping moo
ping baa
ping moobaa
Each one will show something similar to:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
Then remove the lines we just added to the hosts file, and ping them again.
You will receive an error message similar to:
Ping request could not find host baa. Please check the name and try again.
Practice some more
Lets practice using an existing IP like google. First lets find google’s IP:
ping google.com
The result will return 216.58.223.36.
In your hosts file add this line at the bottom:
216.58.223.36 googlefun
Now ping googlefun:
ping googlefun
You will see that you have now pinged the google IP address.
What can you do with the hosts file?
You can point a domain name to an ip. You may want to do to block your computer from communicating with a certain domain name or just have custom domain names set up for fun.