How To Edit Hosts File on Your System

So often you will need to edit the hosts file on your machine. Sometimes because of an attack  and others so that you can simply and freely control access to websites and network traffic.This file is available on each operating systems and useful for mapping domains with IP address without making any DNS entry.
Using hosts file we can use any test domain name like testdomain.com, www.testdomain.com configure on server and map with IP in hosts file.

Edit Hosts File on Linux:

On Linux operating systems this file is normally available at following location:

/etc/hosts

Now we will edit this file and make proper entry with hostname and ip address as follows:

nano /etc/hosts
127.0.0.1   localhost.localdomain   localhost
::1         localhost6.localdomain6 localhost6

192.168.1.100     testdomain.com
192.168.1.100     www.testdomain.com
10.10.0.11        site1.testdomain.com site2.testdomain.com

Save file and close it. 

Edit Hosts File on Windows:

On Windows operating systems this file is available with name “hosts” at following location:

C:\Windows\System32\drivers\etc\

Edit “hosts” file in notepad and make any entry like below at end of file.

127.0.0.1   localhost.localdomain   localhost
::1         localhost6.localdomain6 localhost6

192.168.1.100     testdomain
192.168.1.100     www.testdomain.com
10.10.0.11        site1.testdomain.com site2.testdomain.com

Save file. Now you have done mapping between domain name and IP locally on your system.