Module 7 · 14 marks · Network, transport & application
DNS & e-mail protocols
DNS is the Internet's distributed, hierarchical directory that turns names into addresses and mail servers. E-mail rides on it: SMTP pushes messages between servers, MIME packages attachments, and POP3 or IMAP let users pull mail. Ports, record types and protocol behaviour are frequent MCQs.
High-yield 70 minSyllabus: “DNS, email protocols”
Mark as
The idea in one minute
DNS works like finding a phone number in a huge organisation. You ask your office receptionist (local resolver). If she doesn't know, she asks head office (root), which says 'ask the .com department'; that department says 'ask example.com's own desk', which finally gives the number — and the receptionist remembers it for a while (caching). E-mail is the postal service built on top: your post office (SMTP) carries letters to the recipient's post office, which keeps them in a mailbox until the recipient collects them (POP3 or IMAP).
Key points — the night-before list
DNS is a distributed hierarchical database: root (13 named server identities a–m, many anycast copies) → TLDs (generic .com, country .in) → second-level domains → subdomains.
Recursive query: the server must return the final answer. Iterative query: the server returns a referral. Hosts ask resolvers recursively; resolvers query root, TLD and authoritative servers iteratively.
Records: A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail server, lower preference wins), NS, PTR (reverse, in-addr.arpa), SOA, TXT, SRV. Every record has a TTL for caching.
DNS uses UDP 53 for queries and TCP 53 for zone transfers and truncated replies; DNSSEC signs records; DoT (853) and DoH (443) encrypt queries.
E-mail agents: MUA (client), MTA (relay server), MDA (stores in mailbox), MAA (POP/IMAP server). SMTP pushes mail; POP3 and IMAP pull it.
SMTP: port 25 relay, 587 submission (STARTTLS), 465 implicit TLS; commands HELO/EHLO, MAIL FROM, RCPT TO, DATA, QUIT; replies 220, 250, 354, 221; 7-bit ASCII.
MIME adds MIME-Version, Content-Type and Content-Transfer-Encoding (base64: 3 bytes → 4 characters; quoted-printable) and multipart bodies.
POP3 110/995 (download, usually delete); IMAP 143/993 (folders on server, partial fetch, multi-device sync). SPF, DKIM, DMARC fight spoofing; PGP and S/MIME encrypt end to end.
01Why DNS exists and how the name space is organised
People remember names such as www.keralapsc.gov.in; IP needs addresses. In the early ARPANET a single file, HOSTS.TXT, listed every host and was copied to every computer — impossible to keep up to date as the network grew. Paul Mockapetris designed the Domain Name System in 1983 (today's standard is RFC 1034/1035, 1987): a distributed, hierarchical database in which no single server holds everything and each organisation manages its own part.
Names form an inverted tree. Each node has a label of up to 63 characters; a full domain name (up to 255 bytes) lists labels from the node up to the root, separated by dots. The unnamed root is written as a final dot: www.example.com. is a fully qualified domain name (FQDN).
Top-level domains (TLDs):generic — com, org, net, edu, gov, mil, int and hundreds of newer ones such as .info or .app; country-code — in, uk, jp …; and the infrastructure domain arpa used for reverse lookups.
Second-level domains are registered under a TLD (example.com, or gov.in under .in), and their owners create subdomains freely (mail.example.com, kshb.kerala.gov.in).
A domain is a whole subtree; a zone is the part of it that one set of servers is responsible for. A domain owner can delegate a subdomain to other servers, creating a separate zone (with NS records at the cut).
PSC favourite
'DNS acts as a … naming system' → a distributed hierarchical naming system. It is an application-layer service that other applications (web, e-mail) use before they can open a connection.
02Name servers, resolvers and how a lookup proceeds
Root servers: 13 named server identities, a.root-servers.net to m.root-servers.net, run by 12 organisations; together they are replicated by anycast at well over a thousand sites worldwide. They know only the servers of every TLD.
TLD servers: know the authoritative servers of every domain registered under their TLD (e.g. .com, .in).
Authoritative servers: hold the actual records of a zone. The primary (master) has the editable zone file; secondary (slave) servers copy it by zone transfer over TCP, checking the SOA serial number at each refresh interval. Both answers are authoritative (AA flag set).
Recursive (caching) resolvers: run by ISPs, companies or public services (such as 8.8.8.8 or 1.1.1.1). They do the legwork for clients and cache the results; their answers from cache are non-authoritative.
Stub resolver: the small library in every host (called by getaddrinfo or gethostbyname) that simply asks a configured recursive resolver.
Recursive query
'Give me the final answer, or an error'
The server contacts other servers on the client's behalf
Used from a host to its local resolver
Puts the work (and the cache) at the resolver
Iterative query
'Give me the best information you have'
The server answers or returns a referral (NS + glue addresses)
Used from the resolver to root, TLD and authoritative servers
Keeps busy root and TLD servers simple and stateless
Every record carries a TTL (time to live, in seconds). Resolvers cache both answers and referrals until the TTL expires, so a second lookup for the same name — or another name in the same domain — is answered without asking the root or TLD again. Negative answers ('no such name', NXDOMAIN) are cached too, for the SOA's negative-caching time. A short TTL lets an administrator move a service quickly; a long TTL reduces load.
Note
Follow a cold-cache lookup of www.example.com — recursive from the host, iterative from the resolver — in the step-through on this page.
Free text: SPF, DKIM keys, DMARC policy, site verification
"v=spf1 ip4:198.51.100.0/24 -all"
SRV
Location of a service: priority, weight, port, target
_sip._tcp → 10 60 5060 sip.example.com.
CAA
Which certificate authorities may issue certificates
0 issue "letsencrypt.org"
TextA small zone file
$TTL 3600
example.com. IN SOA ns1.example.com. admin.example.com. (
2026120301 ; serial (bump on every change)
7200 ; refresh — secondaries check every 2 h
900 ; retry
1209600 ; expire — 14 days
300 ) ; negative-cache TTL
example.com. IN NS ns1.example.com.
example.com. IN NS ns2.example.net.
example.com. IN MX 10 mail1.example.com.
example.com. IN MX 20 mail2.example.com.
ns1 IN A 203.0.113.2
www IN A 203.0.113.10
www IN AAAA 2001:db8::10
shop IN CNAME www.example.com.
mail1 IN A 203.0.113.25
mail2 IN A 198.51.100.25
example.com. IN TXT "v=spf1 ip4:203.0.113.25 ip4:198.51.100.25 -all"
MX preference: a sending server tries the lowest number first; servers with equal numbers share the load; if a domain has no MX record, mail goes to its A/AAAA address.
CNAME rules: a name that has a CNAME may hold no other records, so a CNAME cannot sit at the zone apex (which needs SOA and NS); MX and NS records must point to real hostnames, not to aliases.
Reverse lookup: to find the name for 203.0.113.25, reverse the octets and query the PTR record of 25.113.0.203.in-addr.arpa. IPv6 uses ip6.arpa with one label per hex digit, also reversed. Mail servers commonly check that a sender's address has a matching PTR record.
04DNS messages, transport and security
Queries and responses share one format: a 12-byte header followed by four sections — Question, Answer, Authority (NS records, e.g. in a referral) and Additional (helpful extras such as the glue addresses of those NS servers). The header holds a 16-bit ID that matches a response to its query, flags — QR (query/response), opcode, AA (authoritative answer), TC (truncated), RD (recursion desired), RA (recursion available) and the RCODE (0 no error, 3 NXDOMAIN, 2 server failure) — and four counts.
UDP port 53 carries ordinary queries: one small request, one small reply, no handshake. Classic DNS limited UDP replies to 512 bytes; EDNS(0) allows larger ones.
TCP port 53 is used for zone transfers (AXFR/IXFR between primary and secondary) and whenever a reply is too big — the server sets TC = 1 and the client retries over TCP.
DNSSEC adds digital signatures (RRSIG) and keys (DNSKEY), chained from the root through DS records, so a resolver can verify that data is genuine and unmodified. It provides integrity and origin authentication — not secrecy — and defeats cache-poisoning attacks.
DNS over TLS (DoT, port 853) and DNS over HTTPS (DoH, port 443) encrypt the conversation between a client and its resolver for privacy.
Abuses to know: cache poisoning (forged answers), amplification DDoS (small spoofed queries producing large replies), DNS tunnelling (hiding data in queries), and cybersquatting (registering names that trade on someone else's trademark).
Bourne shellEveryday lookups
nslookup www.example.com # A/AAAA answer from the configured resolver
nslookup -type=MX example.com # mail exchangers with preferences
dig example.com AAAA +short # just the IPv6 address(es)
dig +trace www.example.com # follow the referrals root → TLD → authoritative
dig -x 203.0.113.25 # reverse (PTR) lookup
PSC favourite
DNS: UDP 53 for queries, TCP 53 for zone transfers and large or truncated replies. 'nslookup queries the … to find an IP address' → DNS.
05E-mail architecture
Component
Role
Examples
MUA — mail user agent
Composes, reads and organises mail for the user
Outlook, Thunderbird, phone mail apps, webmail in a browser
MSA — mail submission agent
Accepts outgoing mail from authenticated users (port 587)
Usually part of the provider's MTA
MTA — mail transfer agent
Queues (spools) mail and relays it server to server with SMTP
Postfix, Sendmail, Exim, Microsoft Exchange
MDA — mail delivery agent
Files an arriving message into the recipient's mailbox
procmail, Dovecot LDA
MAA — message access agent
Serves stored mail to the user's MUA with POP3 or IMAP
Dovecot, Courier
The journey of one message (asha@a.example → bimal@b.example)
Submit
Asha's MUA sends the message to her provider's server with SMTP on port 587, after authenticating (STARTTLS + AUTH).
Look up
The sending MTA queues it and asks DNS for the MX records of b.example, then the A/AAAA address of the chosen mail exchanger.
Relay
It opens TCP port 25 to that server and transfers the message with SMTP. If the receiver is unreachable the message stays in the queue and is retried for days before a bounce is sent.
Deliver
The receiving MTA hands the message to its MDA, which files it in Bimal's mailbox.
Retrieve
Later Bimal's MUA pulls it with IMAP (port 993 with TLS) or POP3 (995).
A message has an envelope (the SMTP MAIL FROM and RCPT TO addresses used for delivery), header fields (From:, To:, Cc:, Subject:, Date:, Message-ID:, plus a Received: line added by each server — RFC 5322) and, after a blank line, the body. The envelope and the visible header can differ: that is how Bcc and mailing lists work — and how forgers spoof senders.
PSC favourite
SMTP is a push protocol (client → server, server → server); POP3 and IMAP are pull (retrieval) protocols. Webmail uses HTTP(S) between the browser and the webmail server, and SMTP between mail servers.
06SMTP
SMTP (Simple Mail Transfer Protocol) — RFC 821 (1982, Jon Postel), now RFC 5321 — moves mail over a TCP connection in three phases: connection establishment, mail transfer and connection termination. Commands and replies are lines of 7-bit US-ASCII ending in CR LF; the message ends with a line containing a single dot. Because original SMTP was text-only and unauthenticated, MIME, STARTTLS, AUTH and SPF/DKIM/DMARC were added later.
Port
Use
25
MTA-to-MTA relay (server to server)
587
Message submission from mail clients — authentication required, upgraded to TLS with STARTTLS
465
Submission over implicit TLS (SMTPS) — TLS from the first byte
Ports
Command
Purpose
HELO / EHLO
Identify the client; EHLO (extended SMTP) also asks the server to list its extensions (STARTTLS, AUTH, SIZE, 8BITMIME …)
MAIL FROM
Envelope sender — where bounces go
RCPT TO
Envelope recipient — repeated once per recipient
DATA
Start of the message; the server answers 354
RSET / NOOP / VRFY
Abort the transaction / do nothing / verify a mailbox (usually disabled against address harvesting)
QUIT
Close the session; the server answers 221
Commands
Code
Meaning
2xx
Success: 220 service ready, 221 closing channel, 250 requested action OK
3xx
More input needed: 354 start mail input (end with a lone dot)
4xx
Temporary failure — try again later: 421 service not available, 450 mailbox busy, 451 local error
5xx
Permanent failure: 500 syntax error, 502 command not implemented, 530 authentication required, 550 mailbox unavailable or rejected
Reply codes — the first digit tells the outcome
TextAn SMTP session (S = receiving server, C = sending client)
S: 220 mx.b.example ESMTP ready
C: EHLO mail.a.example
S: 250-mx.b.example Hello
S: 250 STARTTLS
C: MAIL FROM:<asha@a.example>
S: 250 OK
C: RCPT TO:<bimal@b.example>
S: 250 OK
C: DATA
S: 354 Start mail input; end with <CRLF>.<CRLF>
C: From: Asha <asha@a.example>
C: To: Bimal <bimal@b.example>
C: Subject: Exam notes
C:
C: See you at the centre at 7:30.
C: .
S: 250 OK queued as 4F2A9
C: QUIT
S: 221 Bye
Watch out
An open relay — an MTA that forwards mail for anyone — is quickly abused by spammers. Modern servers relay only for authenticated users (587/465) or for their own domains.
07MIME: sending more than plain text
SMTP was designed for short 7-bit ASCII text, so it cannot directly carry Malayalam text, images or a PDF. MIME (Multipurpose Internet Mail Extensions, RFC 2045–2049) keeps SMTP unchanged and instead adds header fields that describe the body and encode non-ASCII data as ASCII.
base64: take 3 bytes (24 bits), split them into four 6-bit groups and map each to one of 64 characters (A–Z, a–z, 0–9, +, /); pad with '=' at the end. Output is 4/3 of the input — about 33% larger — in lines of at most 76 characters. Used for images, PDFs and other binary data.
quoted-printable: printable ASCII passes through unchanged and any other byte becomes '=' followed by two hex digits (é in Latin-1 → =E9; '=' itself → =3D). Ideal for text that is mostly ASCII.
Multipart: multipart/mixed holds a body plus attachments; multipart/alternative offers the same content as text/plain and text/html; multipart/related bundles HTML with its images. Parts are separated by a boundary string declared in Content-Type.
'MIME allows SMTP to carry' → non-ASCII data (binary files, images, audio, other character sets). The MIME type for CSS is text/css; for HTML, text/html.
08POP3, IMAP, webmail and e-mail security
POP3 (Post Office Protocol 3, RFC 1939; port 110, or 995 with TLS) is simple: the client logs in, downloads messages and usually deletes them from the server. A session passes through three states — authorisation (USER, PASS), transaction (STAT for the message count and size, LIST, RETR n to download, DELE n to mark for deletion, TOP, UIDL, RSET) and update (after QUIT, marked messages are actually removed). Replies are +OK or −ERR. Clients offer download-and-delete or download-and-keep modes.
IMAP (Internet Message Access Protocol, IMAP4rev1 RFC 3501, now IMAP4rev2 RFC 9051; port 143, or 993 with TLS) treats the server as the master copy. Folders live on the server; messages carry flags such as \Seen, \Answered, \Flagged and \Deleted; the client can search on the server and fetch only part of a message (just the headers, or one attachment); several devices can use the mailbox at once and stay in sync, and IDLE lets the server push new-mail notifications. Commands are tagged: a1 LOGIN, a2 SELECT INBOX, a3 FETCH 1 BODY[HEADER], a4 STORE 1 +FLAGS (\Seen), a5 LOGOUT.
Feature
POP3
IMAP4
Port (TLS port)
110 (995)
143 (993)
Where mail lives
Downloaded to one device; usually deleted from the server
Kept on the server; devices hold copies
Folders
Only the inbox on the server
Create, rename and delete folders on the server
Partial download
No (whole message; TOP shows headers only)
Yes — headers, single MIME parts
Search
On the client
On the server
Several devices
Poor — mail ends up on whichever device downloaded it
Designed for it — read and flag states sync everywhere
Server load and storage
Low
Higher
Best for
One computer, limited server space, offline reading
Phone + laptop + webmail users
Webmail: the browser talks HTTP(S) to the webmail application, which uses IMAP/SMTP internally; servers still exchange mail with SMTP.
Transport encryption: STARTTLS on ports 25/587/143/110, or implicit TLS on 465/993/995, protects each hop but not the message stored on servers.
SPF (RFC 7208): a TXT record lists the hosts allowed to send mail for a domain (v=spf1 ip4:… -all); receivers check the connecting IP against the envelope sender's domain.
DKIM (RFC 6376): the sending domain signs headers and body; the signature travels in a DKIM-Signature header and the public key is published in DNS at selector._domainkey.domain.
DMARC (RFC 7489): a TXT record at _dmarc.domain (v=DMARC1; p=reject) tells receivers what to do when neither SPF nor DKIM passes in alignment with the visible From: domain, and where to send reports.
End-to-end:PGP/OpenPGP (Phil Zimmermann, 1991, web of trust) and S/MIME (X.509 certificates from certificate authorities) sign and encrypt the message itself, so even the mail servers cannot read it.
Note
Quiz yourself on 25, 110, 143, 465, 587, 993 and 995 — and every other service port — with the Ports & protocols flashcards on this page.
Step through · Resolving www.example.com with a cold cache
step 1 / 10
Step 1: A www.example.com? (RD=1)
The browser's stub resolver sends a recursive query over UDP port 53: 'recursion desired — give me the final answer'.
Worked examples
Try the problem first, then reveal the working one step at a time.
EX 1Counting the messages in a DNS lookup
A host asks its local resolver for www.example.com. Count the DNS messages exchanged when (a) the resolver's cache is empty, (b) it already has the .com servers cached, and (c) it already has the answer cached. Which queries are recursive and which iterative?
EX 2Choosing a mail exchanger
A domain publishes MX 10 mxa.b.example, MX 20 mxb.b.example and MX 10 mxc.b.example. In what order does a sending MTA try them? What if the domain had no MX records at all?
EX 3Base64 by hand and its size overhead
Encode the three ASCII characters 'PSC' in base64, and estimate the encoded size of a 3 MB PDF attachment.
EX 4Reading an SMTP transcript
In a session the client sends MAIL FROM:<offers@cheap-deals.example> and RCPT TO:<officer@kshb.example>, and the message header says From: "State Bank" <alerts@bank.example>. The server replies 250, 250, 354 and finally 250. Explain each reply, which address SPF checks, and how DMARC would treat this message if bank.example publishes p=reject.
Practice session
Work each problem on paper first, then check. Marking one solved earns 10 XP.0/5 solved
Q1
Write the reverse-lookup names that hold the PTR records for 203.0.113.25 and for 2001:db8::1.
Q2
A resolver caches www.example.com → 203.0.113.10 with TTL 300 s at 10:00:00. The administrator changes the address at 10:01:00. Until when may clients of this resolver still get the old address, and are those answers authoritative?
Q3
A user reads mail on a phone, a laptop and in a browser, and wants folders and read/unread status to match everywhere. Should the clients use POP3 or IMAP, and why? When would POP3 be the better choice?
Q4
An IMAP client synchronises every 15 minutes for 10 hours a day, transferring 150 KB per session on average. How many sessions occur in a day and how much data is transferred (1 MB = 1,000 KB)?
Q5
Write DNS records for the domain kshb.example so that mail goes to mail1 (preferred) and mail2 (backup), www is an alias of web1, and only the two mail servers 198.51.100.10 and 198.51.100.11 may send mail for the domain.
Exam traps
DNS is not 'UDP only': ordinary queries use UDP 53, but zone transfers and truncated (TC = 1) replies use TCP 53.
There are 13 root server names (a–m), not 13 machines — anycast replicates them at well over a thousand sites in total.
In MX records the lower preference number has higher priority.
SMTP only sends/relays mail (push); retrieving mail from a mailbox is POP3's or IMAP's job (pull). SMTP runs over TCP 25, never UDP.