Edit Hosts File

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.

[cc lang=”apache”]
ip_address host_name
[/cc]

You can use [code]#[/code] to comment the line in hosts file.

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

[cc lang=”apache”]
127.0.0.1 local.com
[/cc]

So now after placing this in your hosts file, local.com will served form 127.0.0.1 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.

[cc lang=”apache”]
127.0.0.1:81 local.com
[/cc]

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.

[cc lang=”apache”]
127.0.0.1 google.com
[/cc]

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?

Shares:
  • crystal88_
    November 13, 2011 at 4:25 am

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

    Reply
    • CUEBIZ
      CUEBIZ
      November 29, 2011 at 7:22 pm

      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!

      Epic

      Reply
  • crystal88_
    December 20, 2019 at 2:52 pm

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

    Reply

Leave a Reply

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