Computer Networks chapters (5)
  1. 01Reference Models & Network Layers
  2. 02Data Link Layer & MAC Protocols
  3. 03Network Layer & IP Addressing
  4. 04Transport Layer (TCP & UDP)
  5. 05Application Layer Protocols & Security

Chapter 05 · CN

Application Layer Protocols & Security

2 topics · 1 sections · beginner-friendly study notes · Updated

Share with friends:WhatsAppTelegram

Embed on your site

Free for teachers, schools and blogs. Please keep the attribution link.

Preview

The application layer is where users meet the network.

This chapter covers HTTP and HTTPS, DNS resolution and record types, email (SMTP, POP3, IMAP) and FTP overview, the basics of TLS, and how firewalls and NAT protect and share addresses.

Port numbers, HTTP response-time counts, DNS steps and NAT tables are common short-answer and numerical topics.

Web development, email server setup, DNS configuration, certificate deployment, firewall rules and home-router NAT.

1

DNS & HTTP/1.1 vs HTTP/2

DNS resolves a hostname to an IP address before a browser can open a TCP (or QUIC) connection; HTTP then carries the request. HTTP/1.1 is a text-based, request/response protocol with persistent connections and optional (rarely used) pipelining. HTTP/2 is a binary protocol that multiplexes many streams over one TCP connection, compresses headers (HPACK) and supports server push and stream prioritisation.

In short: DNS finds the address of the shop; HTTP/1.1 serves one customer at a time per door, HTTP/2 serves many customers at once through the same door.

Think about it

Web-performance and protocol-comparison questions are frequent in interviews and in GATE application-layer sections; the DNS step is part of every response-time calculation.

Page-load sequence: URL → browser/OS cache → recursive resolver (DNS over UDP 53; iterative queries to root → TLD → authoritative) → IP → TCP 3-way handshake (1 RTT) → TLS handshake (1 RTT in TLS 1.3, 2 in TLS 1.2) → HTTP request/response.

DNS caching with TTL removes the lookup for repeat visits.

HTTP/1.0: one object per TCP connection (2 RTT per object).

HTTP/1.1: persistent connections by default, the Host header (virtual hosting), chunked transfer, conditional requests, and pipelining, which suffers head-of-line (HOL) blocking at the HTTP level because responses must return in order; browsers therefore open about 6 parallel connections per host, with domain sharding and sprite/bundle hacks.

HTTP/2: single connection, binary framing layer, streams with IDs multiplexed (no HTTP-level HOL blocking), HPACK header compression (big saving on repeated cookies/headers), stream prioritisation and server push; browsers require TLS for HTTP/2 (ALPN negotiation).

TCP-level HOL blocking remains in HTTP/2 — one lost packet stalls all streams — which HTTP/3 fixes by using QUIC over UDP.

Semantics (methods, status codes, headers) are unchanged across versions.

Comparison summary — connections: 1.1 many (≈6) vs 2 one; format: text vs binary; headers: uncompressed vs HPACK; multiplexing: no vs yes; server push: no vs yes.

Key points

  • Head-of-line blocking: A stalled first item delays everything queued behind it.
  • Multiplexing: Interleaving several streams over one connection.
  • HPACK: HTTP/2 header compression using static/dynamic tables and Huffman coding.
  • ALPN: TLS extension used to negotiate HTTP/2 (h2).
  • Response time for a page with 1 base file + 5 images, one TCP connection: HTTP/1.1 persistent without pipelining = 1 (TCP) + 1 (base) + 5 = 7 RTT; HTTP/2 multiplexed = 1 (TCP) + 1 (base) + 1 (all 5 images together) = 3 RTT (plus 1 RTT for DNS if not cached, plus TLS RTTs for HTTPS).
  • Cold HTTPS page: DNS 1 RTT + TCP 1 + TLS 1 (TLS 1.3) + request 1 = 4 RTT to the first byte.
  • HTTP/1.1 = text, ~6 connections, no multiplexing; HTTP/2 = binary, 1 connection, multiplexing + HPACK; HTTP/3 = HTTP over QUIC/UDP.

Example

Code
DNS lookup and protocol versions:
$ dig www.example.com A +short          # DNS: name -> IPv4
93.184.216.34

$ curl -sI --http1.1 https://www.example.com | head -1
HTTP/1.1 200 OK
$ curl -sI --http2   https://www.example.com | head -1
HTTP/2 200
2

HTTP and HTTPS

HTTP is a stateless, text-based request/response protocol used by web browsers and servers, running over TCP port 80. HTTPS is HTTP carried over TLS on TCP port 443.

In short: The browser asks for a page; the server answers with the page or an error code.

Browser request flow

Think about it

HTTP is the foundation of the web and most APIs.

Request line: method URL version, then headers and an optional body.

Methods: GET (retrieve), POST (submit data), PUT (replace), DELETE, HEAD (headers only), OPTIONS.

Status codes: 1xx informational, 2xx success (200 OK, 201 Created), 3xx redirection (301 Moved Permanently, 304 Not Modified), 4xx client error (400, 401, 403, 404), 5xx server error (500, 503).

HTTP/1.0 used non-persistent connections (a new TCP connection per object); HTTP/1.1 uses persistent connections by default with optional pipelining; HTTP/2 multiplexes streams over one connection; HTTP/3 uses QUIC over UDP.

HTTP is stateless, so cookies (Set-Cookie / Cookie headers) and sessions add state.

Caching with conditional GET (If-Modified-Since) reduces traffic, and proxies/CDNs bring content closer to users.

Key points

  • Stateless: Server keeps no memory of past requests by default.
  • Cookie: Small data stored by the browser and sent back with later requests.
  • Persistent connection: One TCP connection reused for many objects.

Example

Code
HTTP request and response:
GET /index.html HTTP/1.1
Host: www.example.com
Accept: text/html

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1256

<html> ... </html>
3

DNS: hierarchy and resolution

The Domain Name System maps human-readable names to IP addresses using a distributed hierarchical database: root servers, top-level domain (TLD) servers (.com, .org, .in) and authoritative servers for each domain.

In short: DNS is the phone book of the Internet.

Think about it

People remember names, not IP addresses, and DNS makes the Internet scalable.

Name resolution: the host asks its local (recursive) resolver.

In a recursive query the resolver does all the work and returns the final answer; in iterative queries the resolver contacts root → TLD → authoritative, each replying with a referral to the next server.

Results are cached according to TTL.

Common records: A (name → IPv4), AAAA (name → IPv6), CNAME (alias), MX (mail exchanger), NS (name server), PTR (reverse lookup), SOA (zone authority), TXT.

DNS uses UDP port 53 for ordinary queries and TCP port 53 for large responses and zone transfers.

DNSSEC adds digital signatures to prevent spoofing, and attacks include cache poisoning.

Maximum label length is 63 characters and full name length 255.

Key points

  • Resolver: Server or library that performs lookups on behalf of clients.
  • Authoritative server: Holds the real records for a zone.
  • TTL: How long a record may be cached.
  • Typical path: client → local resolver → root → .com TLD → authoritative for example.com → answer cached at resolver.
4

Email protocols and FTP overview

SMTP (port 25, submission 587) transfers mail between mail servers and from client to server (push). POP3 (port 110) and IMAP (port 143) let users retrieve mail (pull). FTP transfers files using two TCP connections: control on port 21 and data on port 20 (active mode).

In short: SMTP sends, POP3/IMAP receive, FTP moves files.

Think about it

Email and file transfer remain core services and exam favourites for port numbers.

SMTP is a text-based protocol over TCP with commands HELO/EHLO, MAIL FROM, RCPT TO, DATA, QUIT; message bodies are 7-bit ASCII and MIME extends this to attachments and non-ASCII.

POP3 usually downloads and deletes mail from the server; IMAP keeps mail on the server, supports folders and synchronization across devices.

HTTP/webmail uses HTTP between the browser and the mail server, but SMTP between mail servers.

FTP is out-of-band: control information (commands, replies) is on a separate connection from data; the control connection persists for the session while a data connection is opened for each file transfer.

FTP sends credentials in clear text, so SFTP (over SSH, port 22) or FTPS is preferred.

DHCP (UDP 67/68) and TFTP (UDP 69) are other common application protocols.

Key points

  • MIME: Multipurpose Internet Mail Extensions: formats for attachments and non-text.
  • Out-of-band: Control and data travel on separate connections (FTP).
  • MX record: DNS record naming the mail server of a domain.
  • Ports: HTTP 80, HTTPS 443, FTP 20/21, SSH 22, Telnet 23, SMTP 25, DNS 53, DHCP 67/68, POP3 110, IMAP 143.
5

SSL/TLS Security Handshake

Transport Layer Security (TLS) provides confidentiality (encryption), integrity (message authentication codes) and authentication (X.509 certificates) for a TCP connection. HTTPS = HTTP over TLS.

In short: TLS puts the conversation in a locked, tamper-evident envelope and proves the website is who it claims to be.

Think about it

Protects passwords, payments and personal data from eavesdroppers and tampering.

Handshake overview: ClientHello (supported versions, cipher suites, random) → ServerHello (chosen suite, random) plus the server certificate → client verifies the certificate chain up to a trusted certificate authority (CA) → key exchange (RSA or, preferably, ephemeral Diffie-Hellman giving forward secrecy) → both derive a symmetric session key → Finished messages → encrypted application data.

Asymmetric cryptography authenticates and exchanges keys; faster symmetric encryption (AES) protects the bulk data.

Hash-based MACs or AEAD modes detect tampering.

TLS 1.3 reduces the handshake to one round trip.

Certificates bind a public key to a domain name; a browser warns when the certificate is expired, untrusted or for a different name.

TLS does not hide the destination IP address or (without ECH) the server name from observers.

Key points

  • Certificate authority: Trusted party that signs certificates.
  • Session key: Symmetric key derived during the handshake.
  • Forward secrecy: Past sessions remain safe even if the server’s long-term key leaks.
  • Symmetric = fast, same key both sides; asymmetric = public/private pair for authentication and key exchange.
  • TLS 1.2 handshake (RSA key exchange): 1) ClientHello (versions, ciphers, client random) 2) ServerHello + Certificate + ServerHelloDone 3) Client verifies certificate, sends encrypted pre-master secret (ClientKeyExchange), ChangeCipherSpec, Finished 4) Server decrypts, sends ChangeCipherSpec, Finished. Both derive the master secret from pre-master + the two randoms, then session keys. Costs 2 RTT after TCP; TLS 1.3 needs 1 RTT (0-RTT on resumption).
  • SSL is the deprecated predecessor (SSL 3.0 broken by POODLE); “SSL/TLS” today means TLS 1.2/1.3. HTTPS = TCP 3-way handshake (1 RTT) + TLS handshake + HTTP request; total RTTs before the first response byte with TLS 1.2 = 1 + 2 + 1 = 4.
6

Firewalls and NAT

A firewall filters traffic according to rules. Packet-filter firewalls check headers (IP, port, protocol), stateful firewalls track connections, and application-layer firewalls/proxies inspect payloads. NAT translates private internal addresses to one or more public addresses; PAT (NAT overload) also rewrites port numbers so many hosts can share one public IP.

In short: A firewall is the security guard at the gate; NAT is the receptionist who answers calls with one public number and routes them to internal extensions.

Think about it

Protects networks and stretches the limited IPv4 address space.

Firewall rule order matters: first match wins and a default-deny policy is safest.

A stateful firewall automatically allows return traffic belonging to an established outgoing connection.

A DMZ hosts public servers separately from the internal LAN.

NAT table example: inside 192.168.1.

10:5000 ↔ outside 203.0.

113.5:40001.

For outgoing packets the router replaces the source IP and port and stores the mapping; for incoming packets it uses the mapping to restore the original destination.

NAT conserves IPv4 addresses and hides internal hosts, but breaks end-to-end addressing, complicates peer-to-peer applications and protocols that embed IP addresses in payloads (FTP active mode, SIP), and is not a security mechanism by itself.

Static NAT maps one private to one public address (for servers); dynamic NAT uses a pool; port forwarding maps a public port to an inside server.

IPv6 aims to remove the need for NAT.

Key points

  • Stateful inspection: Firewall tracks connection state and permits related return traffic.
  • PAT: Port address translation: many private hosts share one public IP using different ports.
  • DMZ: Semi-trusted zone for public-facing servers.
  • NAT operates at the network/transport layers (rewrites IP and ports) and the translation table is created by outgoing traffic.

Read more

Solved examples

Example 01 · Intermediate

A web page consists of 1 base HTML file and 5 small images on the same server. Ignore transmission times and let RTT be the round-trip time. Find the total response time in RTTs for: (a) non-persistent HTTP without parallel connections, (b) persistent HTTP without pipelining, (c) persistent HTTP with pipelining.

Given Data:
  • 6 objects in total (1 + 5)
  • TCP handshake = 1 RTT, each request/response = 1 RTT
Required To Find:

Response time in RTTs

Formula Applied:—
Step-by-Step Solution:
Step 1: (a) Each object needs 1 RTT for the TCP handshake and 1 RTT for the request/response = 2 RTT. For 6 objects: 6 × 2 = 12 RTT.
Step 2: (b) Persistent: one handshake (1 RTT) then one RTT per object sequentially: 1 + 6 = 7 RTT.
Step 3: (c) Persistent with pipelining: 1 RTT handshake + 1 RTT for the base page + 1 RTT for all 5 images requested together = 3 RTT.
Final Answer: (a) 12 RTT, (b) 7 RTT, (c) 3 RTT.

Approach note: The base page must arrive before the browser knows about the images, so it always costs its own RTT.

Example 02 · Basic

Trace the DNS lookup for www.example.com when the local resolver has an empty cache and uses iterative queries.

Given Data:
    Required To Find:

    Sequence of servers contacted

    Formula Applied:—
    Step-by-Step Solution:
    Step 1: Client asks its local resolver (recursive query) for www.example.com.
    Step 2: Resolver asks a root server; it replies with the address of the .com TLD server.
    Step 3: Resolver asks the .com TLD server; it replies with the authoritative server for example.com.
    Step 4: Resolver asks the authoritative server; it returns the A record (IP address).
    Step 5: Resolver caches the answer for its TTL and returns the IP to the client.
    Final Answer: Client → local resolver → root → .com TLD → example.com authoritative → answer returned and cached.

    Approach note: The client–resolver step is recursive; the resolver–server steps are iterative.

    Example 03 · Intermediate

    A PAT router has public IP 203.0.113.5. Host 192.168.1.10 uses source port 5000 to reach 198.51.100.7:80, and host 192.168.1.11 uses source port 5000 to reach the same server. Show the NAT table and the packets seen on the Internet.

    Given Data:
      Required To Find:

      Translation entries

      Formula Applied:—
      Step-by-Step Solution:
      Step 1: The router must keep the flows distinct although both hosts used port 5000.
      Step 2: Entry 1: 192.168.1.10:5000 ↔ 203.0.113.5:40001.
      Step 3: Entry 2: 192.168.1.11:5000 ↔ 203.0.113.5:40002.
      Step 4: Packets on the Internet show source 203.0.113.5:40001 and 203.0.113.5:40002 to 198.51.100.7:80.
      Step 5: Replies to port 40001 are translated back to 192.168.1.10:5000, and replies to 40002 to 192.168.1.11:5000.
      Final Answer: Two table rows mapping the same public IP with different public ports (40001, 40002).

      Approach note: The port number is what lets one public IP serve many private hosts.

      Example 04 · Basic

      HTTPS uses TLS on top of HTTP. A certificate expires. Which security property fails first for new connections, and what should the client do?

      Given Data:
        Required To Find:

        Effect and client action

        Formula Applied:—
        Step-by-Step Solution:
        Step 1: Expired cert fails authentication / trust check
        Step 2: Confidentiality algorithms may still exist but the session should not proceed
        Step 3: Client must abort and warn the user
        Final Answer: Server authentication/trust fails; client should reject the connection (do not ignore warnings).

        Approach note: TLS provides confidentiality, integrity and authentication—cert validity is part of authentication.

        Real-world applications

        Networks

        Using Application Layer Protocols & Security in real projects

        Web development, email server setup, DNS configuration, certificate deployment, firewall rules and home-router NAT.

        Mechanism: Write small programs, read errors carefully, then grow complexity only after the basics are solid.

        Common mistakes

        ❌ Myth: HTTPS hides everything, including which site you visit.

        Why this is wrong: The destination IP address (and often the server name in the handshake) is still visible to observers.

        ✅ Verified Truth: HTTPS encrypts the content, headers and URL path between client and server, not the existence of the connection.

        ⚠️ Exam Tip: Say “confidentiality, integrity and server authentication of the content”.

        ❌ Myth: NAT is a firewall.

        Why this is wrong: NAT only translates addresses; it does not inspect or filter intent by itself, though it blocks unsolicited inbound flows as a side effect.

        ✅ Verified Truth: Use a proper stateful firewall for security; NAT is for address sharing.

        ⚠️ Exam Tip: Keep the two functions separate in answers.

        ❌ Myth: DNS always uses UDP.

        Why this is wrong: Large responses (over 512 bytes without EDNS), DNSSEC data and zone transfers use TCP.

        ✅ Verified Truth: DNS uses UDP port 53 normally and TCP port 53 when needed.

        ⚠️ Exam Tip: Quote “UDP for queries, TCP for zone transfers”.

        Revision notes

        The application layer is where users meet the network. This chapter covers HTTP and HTTPS, DNS resolution and record types, email (SMTP, POP3, IMAP) and FTP overview, the basics of TLS, and how firewalls and NAT protect and share addresses.

        High-Yield Quick Revision Points

        1. HTTP 80, HTTPS 443; stateless, cookies add state
        2. HTTP/1.1 persistent by default; non-persistent costs 2 RTT per object
        3. DNS: root → TLD → authoritative; A, AAAA, CNAME, MX, NS; UDP/TCP 53
        4. SMTP sends (25/587); POP3 110 and IMAP 143 retrieve; FTP 20/21 out-of-band
        5. TLS: certificates authenticate, asymmetric exchanges keys, symmetric encrypts data
        6. Firewall filters; NAT/PAT translates IPs and ports

        Practice questions

        Question 1 · MCQ (GATE / CCNA)

        Which protocol is used by a mail client to send an email to its mail server?

        Question 2 · MCQ (GATE / CCNA)

        The default port for HTTPS is:

        Question 3 · MCQ (CCNA)

        Which DNS record type maps a domain name to an IPv6 address?

        Question 4 · MCQ (GATE)

        FTP uses which ports in the default (active) mode?

        Question 5 · MCQ (CCNA)

        NAT overload (PAT) allows many private hosts to share one public IP by using:

        Question 6 · MCQ (GATE)

        In HTTP/1.1 the connection is by default: