Sample Hosts File:
127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6
For example if you are running a server on public network and configured a website on that server. Now to access website through domain name, you must be register a valid domain and point DNS records to that server. But using hosts file we can use any test domain name like example.com, www.example.com configure on server and map with ip in hosts file, Using this we can access site from server without any domain registration and pointing dns.
Edit Hosts File on Windows:
On Windows operating systems this file is available at following location with name “hosts”C:\Windows\System32\drivers\etc\
Navigate to above location in file explorer and 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 example.com 192.168.1.100 www.example.com 10.10.0.11 site1.example.com site2.example.com
Save file and close it. You have done mapping between domain name and IP locally on your system.
Edit Hosts File on Linux/Unix:
On Linux/Unix operating systems this file is generally available at following location/etc/hosts
Edit this file and make proper entry with hostname and ip address as below.
# vim /etc/hosts
127.0.0.1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 192.168.1.100 example.com 192.168.1.100 www.example.com 10.10.0.11 site1.example.com site2.example.com
Save file and close it. You have done mapping between domain name and IP locally on your system
No comments:
Post a Comment