Linux & Networking Fundamentals

Networking Fundamentals: TCP/IP and DNS

4 min read

Networking questions appear in 100% of DevOps/SRE interviews. Master these concepts and you'll handle anything they throw at you.

TCP/IP Fundamentals

The TCP Three-Way Handshake

Client                     Server
   |                          |
   |-------- SYN ------------>|
   |                          |
   |<------- SYN-ACK ---------|
   |                          |
   |-------- ACK ------------>|
   |                          |
   |  Connection Established  |

Interview question: "What happens if the final ACK is lost?"

Answer: The server retransmits SYN-ACK until it receives ACK or times out. The connection will eventually be established or fail after retries.

TCP vs UDP

FeatureTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityGuaranteed deliveryBest effort
OrderingOrderedNo ordering
SpeedSlower (overhead)Faster
Use casesHTTP, SSH, databasesDNS, video, gaming

Key TCP States

# View TCP connections and states
netstat -an | grep tcp
ss -tan

# Common states:
# LISTEN      - Waiting for connections
# ESTABLISHED - Active connection
# TIME_WAIT   - Waiting after close (2x MSL)
# CLOSE_WAIT  - Received FIN, waiting for app
# FIN_WAIT_1/2 - Sent FIN, waiting for ACK/FIN

Interview question: "You see thousands of TIME_WAIT connections. Is this a problem?"

Answer: TIME_WAIT is normal—it prevents old packets from being confused with new connections. However, too many can exhaust ephemeral ports. Solutions:

  • Enable tcp_tw_reuse for outbound connections
  • Increase ephemeral port range: net.ipv4.ip_local_port_range
  • Use connection pooling

DNS Deep Dive

DNS Resolution Process

1. Browser checks cache
2. OS checks /etc/hosts, then nsswitch.conf
3. Query local resolver (from /etc/resolv.conf)
4. Resolver checks cache
5. If not cached, resolver queries:
   Root servers → TLD servers → Authoritative servers
6. Answer cached and returned

DNS Record Types

RecordPurposeExample
AIPv4 addressexample.com → 93.184.216.34
AAAAIPv6 addressexample.com → 2606:2800:...
CNAMEAliaswww → example.com
MXMail server@ → mail.example.com
TXTText dataSPF, DKIM, verification
NSName server@ → ns1.example.com
PTRReverse lookupIP → hostname
SRVService location_http._tcp → ...

DNS Troubleshooting

# Basic lookup
dig example.com

# Query specific record type
dig example.com MX

# Query specific DNS server
dig @8.8.8.8 example.com

# Trace the full resolution path
dig +trace example.com

# Check TTL
dig example.com | grep -E "^example.com"

# Reverse lookup
dig -x 93.184.216.34

Load Balancing Concepts

Layer 4 vs Layer 7

AspectLayer 4 (TCP/UDP)Layer 7 (HTTP)
SpeedFasterSlower
IntelligenceIP/Port onlyContent-aware
SSL terminationNoYes
Sticky sessionsSource IP hashCookies
Use caseHigh throughputWeb apps

Load Balancing Algorithms

AlgorithmBehaviorBest For
Round RobinRotate through serversEqual capacity servers
Least ConnectionsSend to least busyVarying request times
IP HashSame client → same serverSession persistence
WeightedPrefer higher capacityMixed server specs
RandomRandom selectionSimple, even distribution

Essential Network Commands

# Check connectivity
ping -c 4 host
traceroute host  # or tracepath

# DNS lookup
nslookup host
host domain
dig domain

# Port scanning and connectivity
nc -zv host port
telnet host port

# Network statistics
netstat -tulpn  # listening ports
ss -tulpn       # faster alternative

# Packet capture
tcpdump -i eth0 port 80
tcpdump -i any host 10.0.0.1

# Network interfaces
ip addr
ip route

Interview Practice

Q: "A service can't connect to the database. How do you troubleshoot?"

# 1. Check if DNS resolves
dig db.internal

# 2. Check if host is reachable
ping db.internal

# 3. Check if port is open
nc -zv db.internal 5432

# 4. Check local firewall
iptables -L -n
# or firewalld
firewall-cmd --list-all

# 5. Check if service is listening on target
ssh db.internal "ss -tlnp | grep 5432"

# 6. Check for network path issues
traceroute db.internal
mtr db.internal

Next, we'll put it all together with real troubleshooting scenarios. :::

Quick check: how does this lesson land for you?

Quiz

Module 2: Linux & Networking Fundamentals

Take Quiz
FREE WEEKLY NEWSLETTER

Stay on the Nerd Track

One email per week — courses, deep dives, tools, and AI experiments.

No spam. Unsubscribe anytime.