CN Interview Guide
CN Interview Guide
Computer Networks
Technical Interview Preparation Guide
54 Most Asked Questions with Detailed Answers
Covers: OSI Model · TCP/IP · Physical · Data Link · Network · Transport · Application · Security · Troubleshooting
Q3. What is the difference between the Internet, Intranet, and Extranet?
• Internet: A global public network accessible to everyone. Connects millions of private, public, academic, and
government networks.
• Intranet: A private network accessible only within an organization. Used for internal communication and
resource sharing.
• Extranet: An extended intranet that allows controlled access to outsiders (partners, suppliers, customers)
using internet technology but with authentication.
• Bus: All devices share a single communication line. Simple but a failure in the main cable brings down the
whole network.
• Star: All devices connect to a central hub/switch. Most common; failure of one device does not affect others,
but hub failure brings down all.
• Ring: Devices are connected in a circular chain. Data travels in one or both directions. Failure of one node can
disrupt the network.
• Mesh: Every device connects to every other device. Highly reliable and fault-tolerant but expensive.
• Tree: Hierarchical topology combining star and bus. Easy to expand.
• Hybrid: Combination of two or more topologies.
2. OSI Model
• Layer 7 – Application: Closest to the user. Provides network services directly to applications. Protocols: HTTP,
HTTPS, FTP, SMTP, DNS, Telnet. Example: Web browser sending an HTTP request.
• Layer 6 – Presentation: Handles data translation, encryption/decryption, and compression. Converts data
formats (e.g., JPEG, MPEG, ASCII, SSL/TLS encryption). Ensures data is in a readable format for the application
layer.
• Layer 5 – Session: Manages sessions (connections) between applications. Responsible for establishing,
maintaining, and terminating communication sessions. Protocols: NetBIOS, PPTP, RPC.
• Layer 4 – Transport: Provides end-to-end communication, error recovery, and flow control. Segments data
and reassembles at the destination. Protocols: TCP (reliable), UDP (unreliable/fast). Introduces port numbers.
• Layer 3 – Network: Handles logical addressing (IP addresses) and routing of packets across networks.
Determines the best path for data delivery. Protocols: IP, ICMP, ARP, OSPF, BGP. Devices: Routers.
• Layer 2 – Data Link: Provides node-to-node data transfer. Handles MAC addressing, error detection (CRC),
and framing. Divided into LLC and MAC sublayers. Protocols: Ethernet, Wi-Fi (802.11), PPP. Devices: Switches,
Bridges.
• Layer 1 – Physical: Deals with the physical transmission of raw bits over a medium (cables, fiber, radio
waves). Defines electrical signals, cable types, pin layouts, and transmission rates. Devices: Hubs, Repeaters,
Cables.
Memory tip: 'All People Seem To Need Data Processing' (Application → Physical) or 'Please Do Not Throw Sausage
Pizza Away' (Physical → Application).
Q7. What is the difference between the OSI model and the TCP/IP model?
• Layers: OSI has 7 layers; TCP/IP has 4 layers (Application, Transport, Internet, Network Access).
• Development: OSI is a theoretical/conceptual model by ISO; TCP/IP is a practical model developed by DARPA,
actually used in the Internet.
• Protocols: OSI is protocol-independent; TCP/IP is built around specific protocols (TCP, IP, UDP, etc.).
• Usage: OSI is used as a reference/teaching model; TCP/IP is the actual working model of the Internet.
• Mapping: TCP/IP Application layer combines OSI's Application + Presentation + Session layers. TCP/IP
Network Access layer combines OSI's Data Link + Physical layers.
3. TCP/IP Model
• Application Layer: Combines OSI Application, Presentation, and Session layers. Handles high-level protocols
for user interaction. Protocols: HTTP, HTTPS, FTP, SMTP, DNS, SSH, DHCP.
• Transport Layer: Provides end-to-end communication using TCP or UDP. TCP provides reliable, ordered,
connection-oriented delivery. UDP provides fast, connectionless, best-effort delivery.
• Internet Layer: Corresponds to OSI Network layer. Handles IP addressing and routing. Protocols: IP
(IPv4/IPv6), ICMP, ARP, IGMP.
• Network Access Layer: Combines OSI Data Link and Physical layers. Handles hardware addressing (MAC),
framing, and physical transmission. Protocols: Ethernet, Wi-Fi, PPP.
Q9. What is TCP? How does the TCP 3-way handshake work?
TCP (Transmission Control Protocol) is a connection-oriented, reliable transport layer protocol that guarantees
ordered and error-free delivery of data between applications.
The 3-Way Handshake establishes a connection before data transfer:
• Step 1 – SYN: Client sends a SYN (synchronize) packet to the server with a random Initial Sequence Number
(ISN). Client enters SYN_SENT state.
• Step 2 – SYN-ACK: Server responds with SYN-ACK packet: acknowledges client's SYN (ACK = Client_ISN + 1)
and sends its own SYN with server's ISN. Server enters SYN_RECEIVED state.
• Step 3 – ACK: Client sends ACK packet acknowledging server's SYN (ACK = Server_ISN + 1). Connection is now
ESTABLISHED. Data transfer begins.
Connection Termination (4-Way): FIN → ACK → FIN → ACK. The extra step is because server may still have data to
send after receiving client's FIN.
4. Physical Layer
• Bit transmission: Converting data into electrical signals, light pulses, or radio waves.
• Physical medium specification: Defines cable types (coaxial, twisted pair, fiber optic), connectors, and pin
layouts.
• Signal encoding: How bits are represented as signals (e.g., NRZ, Manchester encoding).
• Data rate control: Defines transmission speed (bits per second).
• Synchronization: Ensuring sender and receiver are synchronized at the bit level.
• Transmission mode: Simplex, Half-duplex, Full-duplex.
Devices: Hubs, Repeaters, Cables, Modems, Network Interface Cards (NIC).
• Twisted Pair Cable: Pairs of copper wires twisted together to reduce electromagnetic interference. Types:
UTP (Unshielded – common in LANs) and STP (Shielded – better noise immunity). Categories: Cat5e, Cat6,
Cat6a.
• Coaxial Cable: Central copper conductor surrounded by insulation and a metal shield. Used in cable TV and
broadband internet. Higher bandwidth than twisted pair.
• Fiber Optic Cable: Transmits data as pulses of light through glass/plastic fibers. Very high bandwidth, immune
to electromagnetic interference, long distances. Types: Single-mode (long distance) and Multi-mode (short
distance).
Unguided (Wireless) Media:
• Radio Waves: Long range, can penetrate walls. Used in Wi-Fi, Bluetooth, cellular networks.
• Microwaves: High frequency, line-of-sight transmission. Used in satellite communication and point-to-point
links.
• Infrared: Short range, line-of-sight. Used in TV remotes and IrDA devices.
Q13. What is the difference between Simplex, Half-Duplex, and Full-Duplex transmission?
• Simplex: Data flows in ONE direction only. Sender cannot receive; receiver cannot send. Example: TV
broadcast, keyboard to computer.
• Half-Duplex: Data flows in BOTH directions but NOT simultaneously. One side transmits while the other
receives. Example: Walkie-talkie, old Ethernet hubs.
• Full-Duplex: Data flows in BOTH directions SIMULTANEOUSLY. Both sides can send and receive at the same
time. Example: Phone call, modern Ethernet switches, HTTP/2.
• LLC (Logical Link Control): Manages flow control and error control between the network layer and MAC
sublayer.
• MAC (Media Access Control): Controls how devices access the shared communication medium. Provides
hardware addressing using MAC addresses.
Key functions: Framing, Physical Addressing (MAC), Error Detection (CRC/checksum), Flow Control, Access
Control.
Devices: Switches, Bridges. Protocols: Ethernet, Wi-Fi (IEEE 802.11), PPP, HDLC.
• Device A wants to send data to [Link] but doesn't know its MAC address.
• A broadcasts an ARP Request: 'Who has IP [Link]? Tell [Link] (my IP).'
• All devices on the network receive this broadcast.
• The device with IP [Link] replies with an ARP Reply: 'I am [Link], my MAC is AA:BB:CC:DD:EE:FF.'
• Device A stores this mapping in its ARP cache for future use.
ARP Cache: A temporary table of IP-to-MAC mappings stored locally to avoid repeated ARP broadcasts.
RARP (Reverse ARP): Maps MAC address to IP address. Largely replaced by DHCP.
Gratuitous ARP: A device sends an ARP reply without being asked, used to detect IP conflicts or update network
caches.
Q18. What are the error detection methods used in the Data Link Layer?
• Parity Check: Adds a parity bit (even or odd) to each data block. Simple but can only detect odd numbers of
bit errors. Cannot detect even number of errors or correct errors.
• Checksum: Sender divides data into segments, adds them, and sends the sum's complement. Receiver adds
all segments including checksum; result should be all 1s. Used in TCP/UDP/IP headers.
• CRC (Cyclic Redundancy Check): Most powerful and widely used. Treats data as a binary polynomial and
divides by a generator polynomial. Remainder is the CRC (FCS – Frame Check Sequence). Can detect burst
errors. Used in Ethernet, Wi-Fi.
• Hamming Code: Can detect AND correct single-bit errors. Uses redundant bits placed at power-of-2
positions.
• Go-Back-N (GBN): Sender can have up to N unacknowledged frames (window size N). If frame i is
lost/corrupted, sender retransmits frame i and ALL subsequent frames (i+1, i+2,...). Receiver discards all
frames after the error. Simpler receiver; wasteful if window is large.
• Selective Repeat (SR): Sender retransmits ONLY the specific lost/corrupted frame. Receiver buffers out-of-
order frames. More efficient than GBN but requires more receiver memory/complexity.
• Switch: Modern evolution of the bridge. Has many ports (8, 16, 24, 48+). Hardware-based forwarding (ASICs)
– much faster. Maintains a MAC address table for each port. Effectively replaced bridges in modern networks.
Both operate at Layer 2 and use MAC addresses for forwarding decisions. A switch is essentially a multi-port
bridge with hardware acceleration.
6. Network Layer
Formula: Usable hosts = 2^(32 - prefix) - 2 (subtract network and broadcast addresses).
Benefits: Reduces broadcast domain size, improves security, enables better IP management, allows VLSM
(Variable Length Subnet Masking).
• Static NAT: One private IP is mapped to one specific public IP. Used for servers.
• Dynamic NAT: Private IPs are mapped to a pool of public IPs on demand.
• PAT (Port Address Translation) / NAT Overload: Multiple private IPs share a SINGLE public IP, differentiated
by unique port numbers. Most common form (used in home routers).
Limitations: NAT breaks end-to-end connectivity, complicates peer-to-peer applications, and introduces latency.
Q26. What is the difference between Static Routing and Dynamic Routing?
• Static Routing: Routes are manually configured by the administrator. No overhead from routing protocols.
Best for small, stable networks. Does not adapt to topology changes automatically.
• Dynamic Routing: Routes are automatically discovered and updated by routing protocols. Adapts to network
changes (link failures, new paths). Examples: RIP, OSPF, EIGRP, BGP.
Dynamic Routing Protocols:
• RIP (Routing Information Protocol): Distance-vector. Uses hop count as metric (max 15 hops). Slow
convergence. Simple but not scalable.
• OSPF (Open Shortest Path First): Link-state protocol. Uses Dijkstra's algorithm. Fast convergence, scalable.
Suitable for large enterprise networks.
• BGP (Border Gateway Protocol): Path-vector protocol. Used between autonomous systems on the Internet
(inter-domain routing). The routing protocol of the Internet.
• EIGRP: Cisco proprietary. Hybrid (distance-vector + link-state features). Fast convergence.
• Ping: Uses ICMP Echo Request and Echo Reply to test reachability and measure round-trip time (RTT).
• Traceroute: Uses ICMP Time Exceeded messages to map the path packets take to a destination by
incrementing the TTL field.
• Error reporting: Destination Unreachable, Time Exceeded, Redirect, Source Quench messages.
ICMP is connectionless and unreliable. It cannot be used to transfer data. Firewalls sometimes block ICMP for
security reasons.
• Traceroute exploits TTL by sending packets with TTL=1, TTL=2, TTL=3... Each router that discards the packet
reveals its IP address, mapping the path.
• DNS TTL specifies how long a DNS record should be cached.
• D – Discover: Client broadcasts a DHCP Discover message on the network (because it has no IP yet).
Destination: [Link] (broadcast).
• O – Offer: DHCP server responds with a DHCP Offer, proposing an IP address, lease time, and network config.
• R – Request: Client broadcasts a DHCP Request to accept the offered IP (also informs other DHCP servers it
didn't choose them).
• A – Acknowledge: DHCP server sends a DHCP ACK confirming the IP assignment. Client configures its network
interface.
DHCP Lease: IP addresses are assigned for a limited time (lease duration). Before expiry, client can request a
renewal.
7. Transport Layer
• Segmentation & Reassembly: Breaks application data into segments (TCP) or datagrams (UDP) and
reassembles at the receiver.
• Port Numbers: Identifies specific applications/processes. Source and destination ports multiplexed to allow
multiple simultaneous connections. Well-known ports: 0–1023 (HTTP:80, HTTPS:443, FTP:21, SSH:22,
DNS:53).
• Flow Control: Prevents the sender from overwhelming the receiver. TCP uses a sliding window and receiver
advertises its receive window size.
• Congestion Control: Prevents the sender from overwhelming the network. TCP uses algorithms like Slow
Start, Congestion Avoidance, Fast Retransmit, Fast Recovery.
• Error Control: Detects and retransmits lost or corrupted segments (TCP only).
• Connection Management: TCP establishes and tears down connections (3-way handshake and 4-way FIN).
Q33. What is Flow Control and how does TCP implement it?
Flow control ensures the sender does not transmit data faster than the receiver can process it, preventing buffer
overflow at the receiver.
TCP implements flow control using the Receive Window (rwnd):
• The receiver advertises its available buffer space in the TCP header (Window Size field).
• The sender can only have unacknowledged data up to the amount of the advertised window.
• If the receiver's buffer fills up, it sets window size to 0 (Zero Window), stopping the sender.
• When the receiver frees buffer space, it sends a Window Update to resume transmission.
Silly Window Syndrome: Inefficiency where small window sizes lead to tiny segments. Solved by Clark's Algorithm
(receiver-side) and Nagle's Algorithm (sender-side – buffers small writes).
• Slow Start: cwnd starts at 1 MSS and doubles every RTT (exponential growth) until it reaches the Slow Start
Threshold (ssthresh). Despite its name, growth is fast.
• Congestion Avoidance: After cwnd reaches ssthresh, growth slows to linear (adds 1 MSS per RTT). When
congestion is detected (timeout or 3 duplicate ACKs): cwnd is reduced.
• Fast Retransmit: On receiving 3 duplicate ACKs, retransmit the lost segment immediately without waiting for
a timeout.
• Fast Recovery: After fast retransmit, set cwnd = ssthresh + 3 MSS and continue with congestion avoidance
(instead of slow start). Used in TCP Reno/CUBIC.
• TCP CUBIC: Modern default in Linux. Uses a cubic function for cwnd growth, better for high-bandwidth, high-
latency networks.
• Stream Socket (SOCK_STREAM): Uses TCP. Provides reliable, ordered, connection-oriented communication.
• Datagram Socket (SOCK_DGRAM): Uses UDP. Connectionless, unreliable, faster.
• Raw Socket: Allows direct access to lower-level protocols. Used for custom protocol implementations and
network tools (ping, traceroute).
Socket Pair: A connection is uniquely identified by (Source IP, Source Port, Destination IP, Destination Port,
Protocol). This is why a server on port 80 can handle thousands of simultaneous connections.
8. Session Layer
• Session Establishment, Maintenance & Termination: Sets up communication sessions, keeps them alive
during data exchange, and closes them gracefully.
• Synchronization: Adds checkpoints (synchronization points) to data streams so that if a connection breaks,
transmission can resume from the last checkpoint rather than from the beginning.
• Dialog Control: Manages half-duplex or full-duplex communication between nodes.
• Session Restoration: Allows resumption of interrupted sessions.
Note: In practice, the TCP/IP model does not have a separate Session layer. Session management is handled by
the Application and Transport layers (e.g., HTTP sessions via cookies, TLS sessions).
Protocols: NetBIOS (Network Basic Input/Output System), RPC (Remote Procedure Call), PPTP, SQL session
management.
9. Presentation Layer
• Data Translation: Converts data between formats used by the application and the network. Example:
Converting EBCDIC to ASCII, translating character encoding.
• Encryption & Decryption: Encrypts data at the sender for security and decrypts at the receiver. SSL/TLS
operates conceptually at this layer.
• Data Compression: Reduces the size of data to improve transmission efficiency. Formats: JPEG, MPEG, GIF,
ZIP.
• Serialization: Converts complex data structures into a format suitable for network transmission (e.g., JSON,
XML, Protocol Buffers).
Note: Like the Session layer, in practice the Presentation layer's functions are handled by the Application layer in
TCP/IP (e.g., TLS in HTTPS, JSON encoding in REST APIs).
Formats: ASCII, Unicode, JPEG, MPEG, MP3, SSL/TLS, XML, JSON.
• 1. Browser Cache Check: Browser first checks its own DNS cache.
• 2. OS Cache: Checks the operating system's DNS cache and /etc/hosts file.
• 3. Recursive Resolver: If not cached, the query goes to the ISP's Recursive Resolver (also called DNS Resolver
or Recursor).
• 4. Root Name Server: Resolver queries a Root Name Server. It doesn't know the answer but directs to the
TLD Name Server (e.g., .com, .org server).
• 5. TLD Name Server: Returns the address of the Authoritative Name Server for the specific domain.
• 6. Authoritative Name Server: Returns the actual IP address for the requested domain.
• 7. Response: Resolver returns the IP to the browser and caches the result per the TTL value.
DNS Record Types: A (IPv4 address), AAAA (IPv6), CNAME (alias), MX (mail server), NS (name server), TXT (text,
used for SPF/DKIM), PTR (reverse lookup).
Q41. What is HTTP? What is the difference between HTTP/1.1, HTTP/2, and HTTP/3?
HTTP (HyperText Transfer Protocol) is the foundation of data communication on the World Wide Web. It is a
stateless, application-layer protocol for transmitting hypermedia documents.
• HTTP/1.1: Introduced persistent connections (keep-alive), chunked transfer encoding, and host headers.
However, it processes requests sequentially (Head-of-Line blocking). Multiple requests require multiple TCP
connections (browsers open 6 parallel connections to same domain).
• HTTP/2: Major performance upgrade. Binary framing instead of text. Multiplexing: multiple
requests/responses over a single TCP connection simultaneously. Header compression (HPACK). Server Push
capability. Still suffers from TCP-level Head-of-Line blocking.
• HTTP/3: Based on QUIC protocol (runs over UDP instead of TCP). Eliminates TCP Head-of-Line blocking. Built-
in TLS 1.3 encryption. Faster connection establishment (0-RTT or 1-RTT). Better performance on lossy
networks (mobile). Used by major platforms (Google, Meta, Cloudflare).
Q42. What is the difference between GET and POST methods in HTTP?
• GET: Retrieves data from the server. Parameters included in the URL (query string). Idempotent (same
request = same result). Can be cached and bookmarked. Not suitable for sensitive data. Limited URL length
(~2048 chars). Example: Searching Google.
• POST: Submits data to the server (to create/update a resource). Data in the request body. Not idempotent
(repeated requests may create multiple records). Not cached or bookmarked. Suitable for sensitive data
(password in form). No size limit. Example: Login form, file upload.
• 1. Client Hello: Client sends supported TLS versions, cipher suites, and a random number.
• 2. Server Hello: Server selects the TLS version and cipher suite, sends its SSL certificate (containing its public
key) and a random number.
• 3. Certificate Verification: Client verifies the server's certificate against trusted Certificate Authorities (CAs).
• 4. Key Exchange: Client generates a pre-master secret, encrypts it with the server's public key, and sends it.
Both sides generate the same session keys from the pre-master secret and random numbers.
• 5. Finished: Both sides send encrypted 'Finished' messages. All subsequent communication is encrypted with
the symmetric session key.
TLS 1.3 improvement: Reduces the handshake to 1-RTT (and supports 0-RTT for resumption). Removed weak
cipher suites. More secure and faster.
Certificates: Issued by Certificate Authorities (CA). Types: DV (Domain Validated), OV (Organization Validated), EV
(Extended Validation). Let's Encrypt provides free DV certificates.
Q44. What is FTP? What is the difference between Active and Passive FTP?
FTP (File Transfer Protocol) is an application-layer protocol for transferring files between client and server. It uses
TWO separate connections: a Control connection (port 21) and a Data connection (port 20 or a dynamic port).
• Active FTP: Client connects to server port 21 (control). Client tells server 'connect to MY IP:PORT for data.'
Server initiates the data connection back to the client. Problem: Client-side firewalls/NAT block incoming
connections from the server.
• Passive FTP: Client connects to server port 21 (control). Client asks server for a data port. Server opens a
random high-numbered port and tells the client. Client initiates both connections. Firewall-friendly since all
connections are initiated by the client.
SFTP (SSH FTP): Completely different protocol that tunnels file transfer over SSH (port 22). Fully encrypted.
Recommended over FTP.
FTPS: FTP with SSL/TLS encryption added. Different from SFTP.
• Packet Filtering Firewall: Inspects packets at the Network/Transport layer. Makes decisions based on
source/destination IP, port, and protocol. Stateless – doesn't track connection state. Fast but limited.
• Stateful Inspection Firewall: Tracks the state of active connections. Allows only packets that are part of an
established, legitimate connection. More secure than packet filtering.
• Application Layer Firewall (WAF): Inspects traffic at Layer 7 (application content). Can detect SQL injection,
XSS, malicious HTTP requests. More resource-intensive.
• Next-Generation Firewall (NGFW): Combines stateful inspection with application awareness, deep packet
inspection (DPI), intrusion prevention (IPS), and SSL inspection.
• Site-to-Site VPN: Connects two entire networks (e.g., branch office LAN to headquarters LAN). Users don't
need VPN client software.
• Remote Access VPN: Individual users connect to a corporate network from anywhere. Used by remote
workers.
VPN Protocols:
• IPSec: Gold standard for VPNs. Provides strong encryption at the Network layer. Can work in Tunnel mode
(entire packet encrypted) or Transport mode.
• OpenVPN: Open-source, highly secure, runs over TCP or UDP.
• WireGuard: Modern, fast, simple VPN protocol with excellent performance.
• L2TP/IPSec: Layer 2 Tunneling Protocol combined with IPSec for encryption.
• PPTP: Old, fast but weak security. Not recommended.
• IPS (Intrusion Prevention System): Actively MONITORS, DETECTS, and BLOCKS malicious traffic in real-time.
Placed in-line in the network path. Can drop packets, reset connections, or block IP addresses automatically.
Like a security guard that can physically stop intruders.
Detection Methods (both):
• Signature-based: Compares traffic against known attack patterns/signatures. Cannot detect zero-day attacks.
• Anomaly-based: Establishes a baseline of normal behavior and alerts on deviations. Can detect novel attacks
but may have false positives.
• Hybrid: Combines both methods.
• Volumetric attacks: Flood the bandwidth (UDP flood, ICMP flood). Measured in Gbps.
• Protocol attacks: Exploit weaknesses in network protocols (SYN flood – exhausts TCP connection table, Ping
of Death).
• Application layer attacks: Target specific application functions (HTTP flood, Slowloris – holds connections
open).
Mitigation: Rate limiting, CAPTCHAs, anycast network diffusion, scrubbing centers, CDN providers (Cloudflare,
AWS Shield).
• ARP Spoofing/Poisoning: Attacker sends fake ARP replies to associate their MAC address with the gateway
IP, causing traffic to pass through the attacker.
• DNS Spoofing: Attacker poisons the DNS cache to redirect users to malicious websites.
• SSL Stripping: Attacker downgrades HTTPS connection to HTTP.
• Evil Twin Wi-Fi: Attacker creates a fake Wi-Fi hotspot with the same SSID as a legitimate network.
Prevention: Use HTTPS/TLS, enable HSTS (HTTP Strict Transport Security), use strong encryption, verify
certificates, use VPNs on public Wi-Fi, use DNSSEC.
Q50. What is a Cookie? What is the difference between a Session Cookie and a Persistent Cookie?
A cookie is a small piece of data stored by the browser on behalf of a website, used to maintain state, track users,
and store preferences since HTTP is stateless.
• Session Cookie: Temporary cookie. Stored only in browser memory (RAM). Deleted when the browser is
closed. Used for session management (login state, shopping cart). No expiry date set.
• Persistent Cookie: Stored on disk with a specified expiry date. Survives browser restarts. Used for 'Remember
Me' functionality, analytics, tracking preferences.
Security attributes:
• HttpOnly: Cookie cannot be accessed via JavaScript ([Link]). Prevents XSS cookie theft.
• Secure: Cookie is only sent over HTTPS connections.
• SameSite: Controls cross-site cookie sending. Values: Strict (only same-site), Lax (allows navigational GET),
None (cross-site, requires Secure). Prevents CSRF attacks.
• Parameterized Queries / Prepared Statements: Most effective. SQL structure is defined separately from user
input, so input cannot change query logic.
• Input Validation: Validate and sanitize all user inputs. Whitelist allowed characters.
• Stored Procedures: Can prevent injection when implemented correctly.
• Principle of Least Privilege: Database accounts should only have the minimum permissions needed.
• WAF: Web Application Firewall can detect and block common injection patterns.
Q53. What happens when you type a URL in your browser and press Enter?
This is one of the most famous interview questions. Here is the complete end-to-end flow:
• 1. URL Parsing: Browser parses the URL into: protocol (HTTPS), domain ([Link]), path (/search?
q=hello).
• 2. HSTS Check: Browser checks if the domain is in the HSTS preload list (forces HTTPS).
• 3. DNS Resolution: Browser checks DNS cache → OS cache → /etc/hosts → Recursive DNS Resolver → Root
NS → TLD NS → Authoritative NS → Returns IP address (e.g., [Link]).
• 4. TCP Connection: Browser initiates TCP 3-way handshake with the server's IP on port 443.
• 5. TLS Handshake: TLS handshake occurs: certificate verification, cipher suite negotiation, session key
establishment. Secure encrypted tunnel is ready.
• 6. HTTP Request: Browser sends HTTP GET request over the TLS tunnel. Includes headers: Host, User-Agent,
Accept-Encoding, Cookies, etc.
• 7. Server Processing: Web server (Nginx/Apache) receives the request → Routes to application server →
Application processes (queries DB if needed) → Returns HTML response.
• 8. HTTP Response: Server sends HTTP 200 OK with HTML content, headers (Content-Type, Cache-Control,
Set-Cookie, etc.).
• 9. Browser Rendering: Browser parses HTML → Builds DOM tree → Parses CSS → Builds CSSOM → Combines
into Render Tree → Layouts → Paints pixels to screen. Additional resources (JS, CSS, images) trigger parallel
requests.
• 10. JavaScript Execution: JS engine executes scripts, enabling interactive behavior, AJAX calls, etc.
Q54. What are common network troubleshooting commands and what do they do?
• ping <host>: Tests basic reachability and measures round-trip time (RTT) using ICMP Echo Request/Reply.
'ping [Link]' tells you if the host is reachable and latency.
• traceroute / tracert <host>: Shows the path packets take to reach a destination, revealing each hop (router)
along the way and its latency. Useful for identifying where packets are being dropped or delayed.
• nslookup / dig <domain>: Queries DNS to resolve domain names to IP addresses. 'dig [Link]' shows the
full DNS resolution chain. Useful for diagnosing DNS issues.
• netstat -an: Displays all active network connections, listening ports, and their states (ESTABLISHED, LISTEN,
CLOSE_WAIT). Useful for identifying what ports are open and active connections.
• ipconfig (Windows) / ifconfig or ip addr (Linux): Displays network interface configuration: IP address, subnet
mask, default gateway, MAC address.
• nmap <host>: Network scanner for discovering hosts, open ports, services, and OS fingerprinting. Essential
for security audits.
• arp -a: Displays the ARP cache (IP to MAC address mappings) for the local network.
• route print / ip route: Displays the routing table, showing how the system routes packets to different
destinations.
• tcpdump / Wireshark: Packet capture tools. Capture and analyze raw network traffic. Invaluable for deep
troubleshooting and understanding protocol behavior.
• curl -I <url>: Sends an HTTP HEAD request, showing response headers without downloading body. Useful for
checking server responses, headers, and redirect chains.
• ss -tuln: Modern replacement for netstat on Linux. Shows TCP/UDP listening sockets quickly.
• mtr <host>: Combines ping and traceroute in real-time. Shows continuous latency and packet loss statistics
for each hop.