The name is a fence and within it you are nameless. Samuli Paronen
|DNS – Blog 1|
|Time to Read|
|Who should read this blog.?|
|If you are new to the DNS system then follow our DNS blog series. Our focus on this DNS series will equip you with hands-on knowledge and make it simple to understand. |
This is our first blog, In this blog, we will start with the basics of the DNS system and then will cover the hosts file configuration on different OS like Linux and Windows.
I remember the good old days when a phone book was an actual physical thing, it was fun to track down your friend’s phone numbers against their names.
The concept of naming is not new as humans are not good with numbers instead are good with the ordering of characters which forms a meaning.
We call it a Name. Every name kept has a story associated with it so it has its own memory.
But technology always preferred numbers.
So to plug technology into human life it has to understand the human language, the easiest solution was to have a name-to-number mapping, so the directory was born.
The directory supports very well with phone numbers which are why the same concept was borrowed for the internet too and DNS was born. DNS in a nutshell is a directory, an internet directory.
So the next question arises what does a DNS directory map to. Let’s find out.
When it comes to the internet how DNS works?
Well, the internet is a collection of systems that has a unique identifier called an IP address(just like phone no’s). And there can be two formats in the IP addresses
The ipv4 address has a 32-bit size and the IPv6 address has a 128-bit size.
In today’s internet, both formats are widely used. See a few examples of both formats below –
- Ipv4 address – 220.127.116.11
- Ipv6 address -2001:db8:3333:4444:5555:6666:7777:8888.
Why you might take a challenge to remember the Ipv4 address you’re certainly going to give up on IPv6 addresses.
Now assume you remember thousands of such IP addresses for each website you access on daily basis.
It would be a nightmare. Thank God we have a DNS system or also known as the domain name system.
DNS works the same way as the phone directory works. It assigns a name to an IP address. So you don’t need to remember the IP addresses of the website you visit on a daily basis.
So next time when you type www.Google.com in your web browser address field thank DNS for saving you to memorize the IP address of it and similarly for hundreds of websites you consume.
Where does the DNS system keep these records?
Now the answer could be very simple if you just want to keep a few records on your local machine’s hosts file, challenging when you have to maintain the records of an Organization on DNS servers, and very complex when you have to maintain the record of the entire internet(Public DNS Infrastructure). Let’s list them down.
- On Your Personal Computer – Scope Local User Machine
- On DNS servers for an organization – Scope all User machines/servers in an Organization (Private DNS zones)
- On highly distributed Public DNS Infrastructure in the case of the Internet – Scope mighty Internet(Public DNS Zone)
On Your Personal Computer
A hosts file is supported equally on Windows, Linux, and Mac machines. This file is always checked first a machine tries to resolve a host time. If there is an entry created in the hosts files that will be referred to determine the hostname to an IP address. You may use host files to create the website’s name to IP mapping on a local machine.
However, in most cases, this file is not used for name resolutions the major reason behind this is that internet websites keep changing their IP addresses so if you make an entry today in hosts file it may change tomorrow and may not work tomorrow.
Also, it is not feasible to create manual entries in the hosts file of millions of websites on the internet.
Let’s see how the hosts file looks on different operating systems and how can we modify them.
On Windows Machine
You may access the hosts file on the Windows system on the path –
Let’s open the hosts file to see how does it look like-
For modification, you may just add an entry as given below.
I added an entry for google.com with an IP address of 127.0.0.1
This IP address belongs to localhost.
Let’s see now what is DNS resolution of google.com is. I ping google.com and it resolves to 127.0.0.1.
Now if I access www.google.com in my browser it will show me the error page as it resolves to127.0.01 which is not the Google server IP.
You may block any website and only a technician can find what is wrong.
On Linux Machines
You may access the hosts file on the Linux machines on the path –
Let’s see what is inside the hosts file
Let’s browse google.com on linux command before modifying hosts file. We can do it using curl command. As we can see we are getting connected to google.com server 18.104.22.168 and getting the webpage loaded.
Let’s modify the hosts file by assigning local host IP 127.0.0.1 to google.com.
As we have now modified the hosts file lets browse the google webpage again.
As you can see google.com is resolving to localhost IP 127.0.0.1 and since the google page is not hosted on the local machine, we are seeing a connection failed response.
Use cases of the hosts file
The hosts file on a computer can be edited for various reasons, including:
- Blocking websites: By mapping a website’s hostname to a local IP address, you can block access to that website. For example, you can block ads by adding entries to your hosts file that map ad servers to the localhost IP address (127.0.0.1).
- Redirecting websites: Similarly, you can redirect a website from its original host to a different IP address. This can be useful for testing websites or applications in different environments.
- Overriding DNS resolution: The hosts file can be used to override DNS resolution, allowing you to manually specify the IP address for a hostname. This can be useful for troubleshooting or bypassing DNS-related issues.
- Bypassing censorship: In some countries, access to certain websites may be restricted by the government. By editing your hosts file to map the blocked website’s hostname to an IP address of a server located in a different country, you can bypass this censorship.
In this blog, we started with the DNS introduction then we explained how can we configure DNS records locally on a Linux or Windows Machine. We explained about hosts files and use cases of the hosts file.
But DNS is much more than the hosts file on local machines and in production, they are hardly touched rather It is the DNS servers where all the action takes place. In this DNS blog series, Next blog we will start with the types of DNS servers.