When you open a website, the domain name such as 'www.google.com' gets resolved to an IP-address of the server serving the request. This IP address looks something like 192.168.1.1. This name-to-address resolution is performed by a Domain Name Server (DNS). So this is what happens when you type in a URL such as 'www.tech-simply.blogspot.com' in your browser:
I have tried to sum up the whole process in the graphic below. Click to expand the image.
- A request goes to the DNS server to resolve the domain name into the corresponding IP address.
- The DNS responds with the IP address to your computer (also known as a client).
A small hack: You can yourself find out the IP address of a host using the ping utility.
- The client makes another request, this time directly to the server for which you had entered the URL using the IP address that was provided by the DNS. If the destined server is up and running, and configured to respond, it sends a reply back to the requesting client.
Here is the catch...
Contacting the DNS for mapping the domain names to corresponding IP addresses from its look-up tables, and getting back the result takes some time. But what if my client(it can be a computer, phone, tablet or whatever) already has the IP address of the web server I am trying to connect to? This is done by saving the domain names corresponding to their IP addresses in the hosts file. We can directly make a request to the web server without the need for contacting the DNS first. This would save a few milliseconds, and a few kilobytes of data being transmitted on the network.
You may want to follow this simple step by step procedure to make changes to the host file.
- Find the IP address of the host using the ping command.
In the screenshot above, I am getting a 'Request timed out'. You are most likely to get a 'Reply from <IP Address> TTL <time in ns> ' Anyways we are not concerned about that as long as we get the IP address of the host.
- Make an entry of the domain name, and its corresponding IP address in the hosts file. (See screenshot below). You need to open the hosts file in an editor(Notepad is okay) in elevated mode(with administrative priveleges). If you aren't sure on how this is to be done, you may refer to this post.
- Save the file.