Edit Hosts File

  • Avinash
  • 2
  • Nov 11, 2011
  • Tutorial

This post is going to show about editing the hosts file. So first of all what is hosts file?

What is Hosts File?

Hosts file is simple file which maps the host name and IP address. But this mapping is applicable for that machine only.

Where Can I Find This File?

Location of this file can be vary based on the operating system. You can find full list of all OS with location of hosts files on each OS at this link.

How to Edit Hosts File?

You can edit the hosts file using any text editor but you will need administrator right for that.

You need to map ip address and host name as per below method.

ip_address host_name
  ip_address host_name

You can use # to comment the line in hosts file.

Here is the real example of mapping the host name and ip address local.com local.com

So now after placing this in your hosts file, local.com will served form means from local. It will load local site instead of actual site.

You can not specify port based IP address in hosts file. So below code will not work. local.com local.com

Note: You can not specify port based IP address in hosts file.

Off Topic

Once I had a great fun with this file. I have placed below code in hosts file of my friend’s machine. google.com google.com

So now whenever he types google.com in browser it will just load the local file of apache’s root. Really it was a great fun.

Have you done any fun like this with this file?

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • http://erosbence.blogspot.om crystal88_

    once a friend of mine mapped facebook.com to he couldn’t find any other way to not to check fb in every 5 mins :)))

    • CUEBIZ

      We re-designed the Google search page with balloons and a colleagues face once. Pointed the domain on the office DNS to point to the dev server.

      It was a colleagues birthday you see, they were all fooled and actually believed we’d been in touch with Google to pull a favour!