Today we are going to edit hosts file on our Operating System (Windows, Mac and Linux). In each and every Operating system a host file exists, which is used for mapping an IP address to a Hostname, which is somewhat similar to a DNS server, so I like to call my Hosts file a local DNS server, because it overrides the DNS servers and points to the IP address we provided for the hostname.
What is hosts file ?
hosts file is a Plain Text file that is used by Operating Systems (Windows, Linux, Mac and etc) to map an IP address to an Hostname. It is mostly called hosts but in earlier versions of some Operating Systems it was also named as hosts.txt
How to edit hosts file?
- Go to the place where hosts file is placed i.e.
for Linux and Mac
and for Windows
for other Operating Systems refer here for locations to hosts file
- Open it in your favorite Text Editor (Notepad) and you will see something like this :
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost ::1 localhost
- Ignore the Comments (
#sign is used for comments in hosts file) and come down to
127.0.0.1is the IP Address and
localhostis the Hostname, which means that
localhostwill point to
- Now lets add a new Entry, go to a new line (by Pressing Enter) and type the IP Address and hostname.
for me it is this
The entry is pointing to the new server of Best 2 Know at inMotion Hosting, instead of the old one.
- Now just save the file (Ctrl+S)
I would recommend using
ping command for testing as you can also view which IP address it is the Hostname pointing to.
Now after learning How to edit hosts file, lets learn its uses.
What are the uses of hosts file ?
Well below are the 2 main reasons I use hosts file.
When I move my Websites to a different Web server or Company.
At that time Hosts file came into handy and I was able fix all problems before visitors came to the website. it was a simple line in hosts files, that solved the problem.
Blocking a Specific website or host
hosts file is also most popularly used to block access to specific site, like to avoid getting caught using a pirated softwares, some people block the Hostname of the Organization that made that software, So the serial key used to register it cannot be detected as a fake.
if you want to block a website, just make map it to
127.0.0.1 IP address i.e.
Do you know some more uses of hosts file, share it with us by using comments