IAE Academy

GATE CS

Application layer

DNS and HTTP

DNS turns names into IP addresses through a hierarchy of servers and caches, and HTTP is the stateless request-response protocol that carries web pages. This page covers who answers a DNS query, which record type gives what, HTTP messages, status codes, cookies and web caches, and how many RTTs a page with its objects takes under non-persistent, persistent and pipelined HTTP. It ends with the key facts of email (SMTP, POP3, IMAP) and FTP (separate control and data connections).

5 previous-year questions · 5 solved · 5 practice questions

DNS: the name hierarchy and the servers

The Domain Name System maps host names such as www.example.com to IP addresses. Names are read right to left: the root (an empty label), then a top-level domain (TLD) such as com or in, then a second-level domain such as example, then host labels. No single server holds all names; the database is distributed over a tree of servers.

Server type

What it knows

Typical role in a lookup

Root server

Addresses of the TLD servers

Replies with a referral to the TLD servers for the queried name

TLD server

Addresses of the authoritative servers of each domain under that TLD

Replies with a referral to the domain's authoritative servers

Authoritative server

The actual records of its own zone

Gives the final answer (the IP address)

Local (resolver) server

Nothing permanent; keeps a cache

Receives the host's query and does the work of resolving it

A zone is the part of the tree one organisation manages. The local resolver is configured on the host (or given by DHCP); the host sends every query to it. DNS messages normally travel over UDP, destination port 53. TCP port 53 is used when a response is too large for UDP or for zone transfers between servers.

Resolution: recursive, iterative and caching

In a recursive query the server asked takes over the job: it must return the final answer (or an error) and contacts other servers itself. In an iterative query the server asked returns either the answer or a referral (the name of a better server to ask), and the asker follows it. The usual setup is: the host sends a recursive query to its local resolver, and the resolver sends iterative queries to the root, the TLD and the authoritative server. Other combinations (for example fully recursive up the chain) are possible; read the question for which queries are recursive.

Resolution with empty caches (iterative from the resolver)

  1. Host asks its local resolver (recursive) for the A record of www.example.com.

  2. Resolver asks a root server; the root refers it to the com TLD servers.

  3. Resolver asks a com TLD server; it refers the resolver to the authoritative server of example.com.

  4. Resolver asks the authoritative server; it returns the A record with a TTL.

  5. Resolver caches the answer for the TTL and returns it to the host.

Caching: every server may keep records it has learnt. Each record carries a TTL (time to live, in seconds); the cache may use it only until the TTL expires, then it must discard it and ask again. Caching also keeps the referrals: the NS records of the com TLD servers are usually already cached, so the root is rarely contacted.

TIME FOR AN ITERATIVE RESOLUTION BY THE RESOLVER

R_host is the RTT from host to local resolver and R_i the RTT from the resolver to each server it queries in turn. Assumes processing time is negligible and each query and its reply is one UDP exchange costing one RTT (no losses or retransmissions). With a cached TLD referral, drop the root term; with a cached final answer, only R_host remains.

WORKED EXAMPLE

A host's local resolver has an empty cache. The RTT from host to resolver is 4 ms, resolver to root 60 ms, resolver to the TLD server 30 ms, resolver to the authoritative server 20 ms. The resolver uses iterative queries; processing is negligible. How long does the host wait for the A record? How long if the resolver already holds the TLD server's address?

Solution
  1. Empty cache: the resolver queries root, TLD and authoritative servers one after another.

  2. Total = 4 + 60 + 30 + 20 = 114 ms.

  3. With the TLD address cached the root query is skipped: 4 + 30 + 20 = 54 ms.

Answer: 114 ms with an empty cache and 54 ms with the TLD address cached.

DNS records and messages

A DNS record (resource record) holds four things: name, value, type and TTL. The types a GATE candidate should know are below.

Type

Name field

Value field

A

Host name

IPv4 address

AAAA

Host name

IPv6 address

NS

Domain (e.g. example.com)

Host name of an authoritative server for that domain

CNAME

Alias name

Canonical (real) host name

MX

Mail domain

Host name of the mail server (with a preference number; the lowest number is tried first)

PTR

IP address written in reverse under in-addr.arpa (IPv4)

Host name (reverse lookup)

Facts worth remembering

  1. A query and its reply use the same message format and the same 16-bit identification number, so the resolver can match them.

  2. A CNAME answer is followed by a further lookup of the canonical name to reach an address, unless the reply already contains the canonical name's address record.

  3. A referral from a root or TLD server carries NS records for the next servers, usually with their A records (glue) in the additional section.

  4. A mail server's name is found by an MX query, then its address by an A query.

  5. The answer from a cache is marked non-authoritative; only the zone's own servers give authoritative answers.

EXAM TIP

NS and MX values are host names, not IP addresses. A question asking which record gives the IP address of a mail server needs two steps: MX, then A.

HTTP: messages, methods, status codes, cookies and caches

HTTP/1.0, HTTP/1.1 and HTTP/2 run over TCP (default port 80; port 443 for HTTPS, which is HTTP over TLS). HTTP/3 runs over QUIC, which uses UDP. The client sends a request and the server returns a response. HTTP is stateless: the server keeps no memory of earlier requests from the same client.

Message structure

  1. Request: request line (method, URL, version), header lines, a blank line, optional entity body.

  2. Response: status line (version, status code, phrase), header lines, a blank line, optional entity body (the object).

Method

Use

GET

Fetch an object; no body in the request (form input, if any, goes in the URL as a query string)

HEAD

Like GET but the server returns only the headers

POST

Send data (such as form input) in the body

PUT

Upload or replace an object at the given URL

DELETE

Delete the object at the given URL

Code

Meaning

200

OK, the object follows

301

Moved permanently; new URL in the Location header

304

Not modified (reply to a conditional GET; no body)

400

Bad request, not understood by the server

404

Not found

505

HTTP version not supported

The first digit gives the class: 1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error. A conditional GET carries an If-Modified-Since header; if the cached copy is current the server answers 304 and sends no object.

Cookies let a stateless server recognise a user. The server's response carries a Set-Cookie header with an identifier; the browser stores it and returns it in a Cookie header on later requests to that site; the server keeps the details in a back-end database keyed by that identifier. The protocol stays stateless; the state lives in the cookie and the server's database.

A web cache (proxy server) sits between clients and origin servers. The browser sends its request to the cache; if the cache holds a fresh copy (a hit) it returns it, otherwise (a miss) it fetches the object from the origin server, stores a copy and returns it. The cache can check a stored copy with a conditional GET. A cache acts as a server to the client and as a client to the origin server.

AVERAGE ACCESS TIME WITH A WEB CACHE

h is the hit ratio (fraction of requests the cache answers), T_hit the time to get an object from the cache and T_miss the time to get it through the cache from the origin server. Assumes every request takes one of these two times.

HTTP connections and time to fetch a page

A page is a base HTML file plus referenced objects (images and so on). The cost is counted in round-trip times (RTT). Convention used here: TCP setup takes 1 RTT; after it the request goes out and the first bytes of the response return in 1 RTT; connection teardown and TCP slow start are ignored; transmission time of the objects and DNS time are negligible unless the question gives them (if a transmission time is given, add it each time that object is sent); the browser learns of the objects only after the base file arrives.

HTTP/1.0 uses non-persistent connections by default: the server closes the TCP connection after sending one object. HTTP/1.1 uses persistent connections by default: several objects travel over one connection, and requests may be pipelined.

Mode

How it works

RTTs for base + n objects

Non-persistent, serial

A new TCP connection for every object, one at a time

Non-persistent, parallel connections

Base file first; then objects fetched on up to connections at a time

Persistent, no pipelining

One connection kept open; next request only after the previous response

Persistent, with pipelining

One connection; all object requests sent back to back without waiting

NON-PERSISTENT, SERIAL

Each of the n+1 files costs 1 RTT for the handshake and 1 RTT for request and response.

NON-PERSISTENT, M PARALLEL CONNECTIONS

Base file fetched alone first; objects then go in batches of m. Assumes equal object times and negligible transmission time.

PERSISTENT WITHOUT PIPELINING

One handshake, one RTT for the base file, one RTT for each object.

PERSISTENT WITH PIPELINING

One handshake, one RTT for the base file, one RTT for all objects together (requests sent without waiting). Transmission time is ignored.

WORKED EXAMPLE

A page has one base file and 9 objects. RTT is 30 ms; transmission times and DNS are negligible. Find the total time for (a) non-persistent serial, (b) non-persistent with 4 parallel connections, (c) persistent without pipelining, (d) persistent with pipelining.

Solution
  1. (a) 2(9+1) = 20 RTT = 600 ms.

  2. (b) 2 + 2 ceil(9/4) = 2 + 2 3 = 8 RTT = 240 ms.

  3. (c) 9 + 2 = 11 RTT = 330 ms.

  4. (d) 3 RTT = 90 ms.

Answer: (a) 600 ms, (b) 240 ms, (c) 330 ms, (d) 90 ms.

EXAM TIP

If the question says the DNS lookup takes some time, add it once before the TCP handshake. If objects sit on a different server, a second handshake is needed for them (and possibly another DNS lookup for that server); read who hosts what.

Email and FTP

SMTP (TCP port 25) pushes mail from the sender's user agent to its mail server and from that server to the recipient's mail server. It is a push protocol, uses a persistent connection, and sends the message with a few commands (HELO, MAIL FROM, RCPT TO, DATA, QUIT). In classic SMTP the message body and headers are 7-bit ASCII text; other content is encoded (MIME). The recipient then pulls the mail from its own mail server with a mail access protocol.

Protocol

TCP port

Direction

Behaviour

SMTP

25

Push (sender to server, server to server)

Delivers mail to the destination mail server

POP3

110

Pull (server to client)

Authorisation, transaction, update phases; commonly downloads and then deletes mail from the server; keeps no folder state across sessions

IMAP

143

Pull (server to client)

Mail stays on the server in folders; the client can fetch parts of a message and create or move messages; keeps state across sessions

FTP (File Transfer Protocol) uses two kinds of TCP connection. The control connection (server port 21) carries commands and replies, stays open for the whole session, and is out of band. Each file transfer or directory listing uses a new data connection, closed when that transfer ends. In active mode the server opens it from its port 20 to a port the client named; in passive mode the client opens it to a port the server named. Because the control connection stays open, FTP keeps state about the user during a session (the logged-in user, the current directory), unlike HTTP.

EXAM TIP

For a session that transfers k files and makes no directory listings, the total number of TCP connections is 1 + k (one control connection and one data connection per file).

PREVIOUS-YEAR QUESTIONS

5 questions from the CS papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE CSE 2026 Set 1 · GATE CSE 2024 Set 1 · GATE CSE 2023 · GATE CSE 2022 · GATE CSE 2020

GATE 2026 CS1 Q.19

GATE 2026 · CS1Q.19 · 1 mark · MSQ

Which of the following statements is/are true with respect to the interaction of a web browser with a web server using HTTP 1.1?

  1. (A)

    HTTP 1.1 facilitates downloading multiple objects of the same webpage over the same TCP connection, if the objects are stored in the same server

  2. (B)

    HTTP 1.1 facilitates downloading multiple objects of the same webpage over the same TCP connection, even if they are stored in different servers

  3. (C)

    HTTP 1.1 facilitates sending a request for downloading one object without waiting for a previously requested object to be downloaded completely

  4. (D)

    HTTP 1.1 facilitates downloading multiple webpages on the same server to be downloaded over a single TCP connection

Answer and solution
See the question in the paper
GATE 2026 CS1 Q.19: answer and solution

GATE 2024 CS1 Q.16

GATE 2024 · CS1Q.16 · 1 mark · MCQ

A user starts browsing a webpage hosted at a remote server. The browser opens a single TCP connection to fetch the entire webpage from the server. The webpage consists of a top-level index page with multiple embedded image objects. Assume that all caches (e.g., DNS cache, browser cache) are all initially empty. The following packets leave the user's computer in some order.

(i) HTTP GET request for the index page
(ii) DNS request to resolve the web server's name to its IP address
(iii) HTTP GET request for an image object
(iv) TCP SYN to open a connection to the web server

Which one of the following is the CORRECT chronological order (earliest in time to latest) of the packets leaving the computer ?

  1. (A)

    (iv), (ii), (iii), (i)

  2. (B)

    (ii), (iv), (iii), (i)

  3. (C)

    (ii), (iv), (i), (iii)

  4. (D)

    (iv), (ii), (i), (iii)

Answer and solution
See the question in the paper
GATE 2024 CS1 Q.16: answer and solution

GATE 2023 CS Q.52

GATE 2023 · CSQ.52 · 2 marks · MSQ

Suppose in a web browser, you click on the www.gate-2023.in URL. The browser cache is empty. The IP address for this URL is not cached in your local host, so a DNS lookup is triggered (by the local DNS server deployed on your local host) over the 3-tier DNS hierarchy in an iterative mode. No resource records are cached anywhere across all DNS servers.

Let RTT denote the round trip time between your local host and DNS servers in the DNS hierarchy. The round trip time between the local host and the web server hosting www.gate-2023.in is also equal to RTT. The HTML file associated with the URL is small enough to have negligible transmission time and negligible rendering time by your web browser, which references 10 equally small objects on the same web server.

Which of the following statements is/are CORRECT about the minimum elapsed time between clicking on the URL and your browser fully rendering it?

  1. (A)

    7 RTTs, in case of non-persistent HTTP with 5 parallel TCP connections.

  2. (B)

    5 RTTs, in case of persistent HTTP with pipelining.

  3. (C)

    9 RTTs, in case of non-persistent HTTP with 5 parallel TCP connections.

  4. (D)

    6 RTTs, in case of persistent HTTP with pipelining.

Answer and solution
See the question in the paper
GATE 2023 CS Q.52: answer and solution

GATE 2022 CS Q.35

GATE 2022 · CSQ.35 · 1 mark · NAT

Consider the resolution of the domain name www.gate.org.in by a DNS resolver. Assume that no resource records are cached anywhere across the DNS servers and that iterative query mechanism is used in the resolution. The number of DNS query-response pairs involved in completely resolving the domain name is ______.

Answer and solution
See the question in the paper
GATE 2022 CS Q.35: answer and solution

GATE 2020 CS Q.25

GATE 2020 · CSQ.25 · 1 mark · NAT

Assume that you have made a request for a web page through your web browser to a web server. Initially the browser cache is empty. Further, the browser is configured to send HTTP requests in non-persistent mode. The web page contains text and five very small images. The minimum number of TCP connections required to display the web page completely in your browser is ________.

Answer and solution
See the question in the paper
GATE 2020 CS Q.25: answer and solution

PRACTICE

5 questions to test yourself

PRACTICE 11 mark · MCQ

A resolver must find the host that accepts mail for the domain corp.example. Which DNS record type does it request first?

  1. (A)

    A

  2. (B)

    NS

  3. (C)

    CNAME

  4. (D)

    MX

Answer and solution

Answer: (D)

  1. The mail server for a domain is named by an MX record.

  2. A gives only an address of a named host, NS names the authoritative DNS servers, CNAME gives an alias.

  3. After the MX answer an A query would give the mail server's address.

PRACTICE 22 marks · MSQ

Which of the following statements about HTTP are correct?

  1. (A)

    The HTTP protocol itself does not require the server to keep any information about a client's earlier requests.

  2. (B)

    A cookie is returned by the browser to the site in a Cookie header on later requests.

  3. (C)

    Status code 404 reports an error in the server's own processing.

  4. (D)

    A 304 response carries no object body.

Answer and solution

Answer: (A), (B), (D)

  1. A is true: HTTP is stateless; any state is kept outside the protocol (cookies and a server database).

  2. B is true: Set-Cookie from the server, then Cookie from the browser.

  3. C is false: 404 is in the 4xx client-error class and means the object was not found.

  4. D is true: 304 Not Modified answers a conditional GET without a body.

PRACTICE 32 marks · NAT

A web page has one base file and 8 objects. The client first needs a DNS lookup that takes 100 ms in total. HTTP then uses a persistent connection without pipelining. RTT to the web server is 50 ms; TCP setup takes 1 RTT, each request-response 1 RTT, transmission times are negligible. Find the total time in ms until the page is fully loaded.

Answer and solution

Answer:

  1. Persistent without pipelining: (n + 2) RTT = (8 + 2) = 10 RTT.

  2. 10 x 50 ms = 500 ms.

  3. Add the DNS time: 500 + 100 = 600 ms.

PRACTICE 42 marks · NAT

A page consists of one base file and 10 objects. The browser uses non-persistent HTTP: the base file is fetched first, then the objects are fetched using at most 3 parallel TCP connections. Each connection needs 1 RTT for setup and 1 RTT per request-response; RTT = 20 ms; transmission times and DNS are negligible. Find the total time in ms.

Answer and solution

Answer:

  1. Base file: 2 RTT = 40 ms.

  2. Objects: ceil(10/3) = 4 batches, each 2 RTT = 40 ms, so 160 ms.

  3. Total = 40 + 160 = 200 ms.

PRACTICE 51 mark · MCQ

A page has one base file and 12 objects; RTT is 40 ms. TCP setup takes 1 RTT and each request-response 1 RTT; transmission times and DNS time are negligible. With a persistent connection and full pipelining of the object requests, what is the time to load the page?

  1. (A)

    120 ms

  2. (B)

    560 ms

  3. (C)

    280 ms

  4. (D)

    1040 ms

Answer and solution

Answer: (A)

  1. Pipelined persistent HTTP: 1 RTT for TCP setup, 1 RTT for the base file, 1 RTT for all objects = 3 RTT.

  2. 3 x 40 ms = 120 ms.

  3. 560 ms is persistent without pipelining (14 RTT) and 1040 ms is non-persistent serial (26 RTT).

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE CS

DNS and HTTP

Preparing in Kolkata? IAE Academy's course for GATE CSE.