Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Why do we need DNS?
2.1.
Domain
2.2.
How does DNS work?
2.3.
Categories of DNS servers
2.4.
Process of DNS lookup
2.5.
Types of DNS queries
3.
Frequently Asked Questions
3.1.
List all layers of the TCP/IP model?
3.2.
Which are the protocols used in the Application layer?
3.3.
What is Half-duplex and Full-duplex mode?
3.4.
List most common network topologies?
4.
Conclusion
Last Updated: Mar 27, 2024

Domain Name System(DNS)

Author Anant Dhakad
0 upvote
Computer Networks

Introduction

DNS is a service that converts a host's name to an IP address. The Domain Name System (DNS) is a distributed database that is implemented as a hierarchy of name servers. It's an application layer protocol that allows clients and servers to send and receive messages.

Why do we need DNS?

There are two ways to identify a host. One by the hostname and another by an IP address. Routers prefer fixed-length, hierarchically structured IP addresses, while people prefer the more mnemonic hostname identification. Furthermore, because IP addresses are not static, a mapping is required to convert a domain name to an IP address. As a result, DNS is used to transform a website's domain name to a numerical IP address.

Domain

There are different categories of domains:

1. Generic domain: Examples of generic domains are ‘.com’(commercial), ‘.edu’(educational), ‘.org’(non-profit organization), ‘.mil’(military), ‘.net’(similar to commercial) etc.

2. Country domain: Examples of country domains are ‘.in’(India), ‘.us’(United States), ‘.uk’(United Kingdoms), ‘.au’(Australia), ‘.lk’(Srilanka) etc.

3. Inverse domain: Basically, it is IP to domain name mapping. 

How does DNS work?

Assume that a user's host application (such as a Web browser or a mail reader) needs to convert a hostname to an IP address. The application will use DNS on the client-side to provide the hostname to be translated. (On various UNIX-based platforms, an application uses the function call gethostbyname() to perform the translation.)The DNS on the user's host then takes control, and it sends a query message into the network. All DNS query and reply messages are sent to port 53 as UDP datagrams. DNS in the user's host receives a DNS reply message with the desired mapping after a delay ranging from milliseconds to seconds. This received mapping (IP address) is then passed to the invoking application.

Categories of DNS servers

When a webpage is loaded, four separate DNS servers are involved.

1. DNS recursor: The recursor can be compared to a librarian who is asked to locate a specific book in a library. This server is designed to handle requests sent directly from client machines via web browsers (and other similar applications).

The recursor then makes additional requests to satisfy the client's DNS query.

2. Root Nameserver: The root server is the first stage in converting (resolving) human-readable hostnames to IP addresses. It's similar to a library's index, which points to different book racks. It gives the address set of the concerned TLD servers.

3. TLD (Top-level domain) Nameserver: This server is responsible for classifying websites according to their type. It is the last part of the domain name. TLDs include ‘.com’, ‘.org’, and ‘.net’, among others. This server can be thought of as a particular shelf in a library. 

4. Authoritative Nameserver: This server can be compared to a dictionary on a bookshelf, where words can be translated. In a DNS query, the authoritative server is the final stop. If the authoritative server contains the requested record, it will return the requested hostname's IP address to the DNS recursor (who initiated the request).

Process of DNS lookup

DNS

                                                                                            ( Source )

1. When a user types 'example.com' into a web browser, the query is transmitted over the Internet and received by a DNS recursive resolver.
2. The DNS resolver then queries the root server 
3. The root server then sends the resolver the address of a Top-Level Domain (TLD) DNS server (such as '.com' or '.net'), which keeps the information for a specific domain. When we search for 'example.com,' we are sent to the '.com' TLD.
4. The DNS resolver then queries the ‘.com’ TLD.
5. The TLD server then returns the address of the domain’s authoritative server (Example: example.com)
6. Now the DNS resolver makes a request to the domain’s authoritative server.
7. Authoritative server returns the IP address of the requested hostname, to the DNS resolver.
8. Finally, the DNS resolver sends the requested IP address to the web browser.

The browser can request the web page after the 8 steps of the DNS lookup have returned the IP address for example.com.

Types of DNS queries

Three types of queries occur in a typical DNS lookup. An efficient DNS resolution process can result in a reduction of distance travelled and lookup delay, by using a combination of these queries.

Types of DNS queries are:

1. Recursive Query: A DNS client expects a DNS server (usually a DNS recursive resolver) to respond to a recursive query with either the requested record (IP address) or an error message if the resolver is unable to locate it. 

DNS queries

Fig: Recursive query in DNS

2. Iterative Query: In an iterative query, a DNS client allows a DNS server to offer the best possible answer. If the queried DNS server cannot find a match for the query name, it will return the address of a DNS server authoritative for a lower level of the domain namespace.

After that, the DNS client will query the referral address. This operation continues along the query chain with other DNS servers until an error or timeout occurs.

Iterativequery

Fig: Iterative query in DNS

3. Non-Recursive Query: This type of query occurs when the requested mapping is already stored in the cache memory. That is, when a DNS resolver queries a DNS server, it returns the desired mapping without further redirecting to some other server (because that mapping was already in the cache memory of the DNS server).

You can also read about mime protocol.

Frequently Asked Questions

List all layers of the TCP/IP model?

The layers in the OSI model are:
1. Physical layer

2. Data link layer

3. Network layer

4. Transport layer

5. Application layer

Which are the protocols used in the Application layer?

Several protocols are used in the Application layer which includes DNS, SMTP, POP, FTP, HTTP etc.

What is Half-duplex and Full-duplex mode?

Both the devices can act as a sender or receiver in half-duplex mode. But at a time, only one device can transmit data over the link.

Full-duplex mode is bi-directional, i.e., both devices can send or receive data simultaneously.

List most common network topologies?

The most common network topologies are:
1. Mesh topology

2. Bus topology

3. Star topology

4. Ring topology

Conclusion

Cheers if you reached here!! 

In this article, we discussed the DNS(Domain Name System), how it works, different steps involved in resolving a hostname into an IP address.

Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Live masterclass