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/etc/hosts
and for Windows
C:\Windows\System32\Drivers\etc\hosts
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 to127.0.0.1 localhost
where
127.0.0.1
is the IP Address andlocalhost
is the Hostname, which means thatlocalhost
will point to127.0.0.1
IP Address. - 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 this198.46.81.165 best2know.info
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)
you can check if the changes are working or not by going to the browser and typing the hostname or by using ping command in Command Prompt, like
ping best2know.info
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.
recently I moved all my websites to inMotion Hosting and after moving files and changing name servers, I had to view whether the website is working properly or not?
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.
198.46.81.165 best2know.info
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.
127.0.0.1 example.com
Do you know some more uses of hosts file, share it with us by using comments