Networking Fundamentals
Chapter 21: Networking Fundamentals
Section titled βChapter 21: Networking FundamentalsβComprehensive Linux Networking Concepts
Section titled βComprehensive Linux Networking Conceptsβ21.1 OSI and TCP/IP Models
Section titled β21.1 OSI and TCP/IP ModelsβNetwork Layer Models
Section titled βNetwork Layer Modelsββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ OSI VS TCP/IP MODEL βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ OSI (7 Layers) TCP/IP (4 Layers) ββ βββββββββββββββββ ββββββββββββββββββ ββ β 7. Application ββββββββββ Application β ββ β 6. Presentationβ β (HTTP, FTP) β ββ β 5. Session β ββββββββββββββββββ ββ βββββββββββββββββ€ β ββ β 4. Transport βββββββββββββββββ€ Transport ββ β (TCP, UDP) β β (TCP, UDP) β ββ βββββββββββββββββ€ ββββββββββββββββββ ββ β 3. Network β β ββ β (IP, ICMP) β β Internet ββ βββββββββββββββββ€ β (IP, ICMP) β ββ β 2. Data Link βββββββββββ€ β ββ β (Ethernet) β ββββββββββββββββββ ββ β 1. Physical β β ββ βββββββββββββββββ β Link/Network Access ββ β (Ethernet, WiFi) ββ ββββββββββββββββββ ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββOSI Layer Functions
Section titled βOSI Layer Functionsββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ OSI LAYER FUNCTIONS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ Layer 7 - Application ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β User interface, HTTP, FTP, SMTP, DNS, SSH β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Layer 6 - Presentation ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Data encoding, encryption, compression (SSL/TLS, JPEG, GIF) β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Layer 5 - Session ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Session management, checkpoints, synchronization β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Layer 4 - Transport ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β End-to-end connection, reliability, flow control β ββ β TCP: connection-oriented, reliable β ββ β UDP: connectionless, fast, unreliable β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Layer 3 - Network ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Routing, logical addressing (IP), fragmentation β ββ β Routers operate at this layer β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Layer 2 - Data Link ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Physical addressing (MAC), frame handling, error detection β ββ β Switches operate at this layer β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Layer 1 - Physical ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Physical connections, cables, hubs, bits β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ21.2 IPv4 Addressing
Section titled β21.2 IPv4 AddressingβIP Address Classes
Section titled βIP Address Classesββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ IPv4 ADDRESS CLASSES βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ Class First Octet Default Mask Networks Hosts/Net ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ A 1-126 /8 (255.0.0.0) 126 16,777,214 ββ B 128-191 /16 (255.255.0.0) 16,384 65,534 ββ C 192-223 /24 (255.255.255.0) 2M 254 ββ D 224-239 - - Multicast ββ E 240-255 - - Reserved ββ ββ Special Addresses: ββ - 127.x.x.x : Loopback (127.0.0.1 = localhost) ββ - 0.0.0.0 : This network (default route) ββ - 255.255.255.255 : Limited broadcast ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββPrivate IP Ranges
Section titled βPrivate IP Rangesββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ PRIVATE IP ADDRESSES βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ 10.0.0.0/8 (10.0.0.0 - 10.255.255.255) ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β 10.0.0.0 - 10.255.255.255 β ββ β 16,777,216 addresses (Class A) β ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ 172.16.0.0/12 (172.16.0.0 - 172.31.255.255) ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β 172.16.0.0 - 172.16.255.255 β ββ β 172.17.0.0 - 172.17.255.255 β ββ β ... β ββ β 172.31.0.0 - 172.31.255.255 β ββ β 1,048,576 addresses (16 contiguous Class B) β ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ 192.168.0.0/16 (192.168.0.0 - 192.168.255.255) ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β 192.168.0.0 - 192.168.255.255 β ββ β 65,536 addresses (Class C) β ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Link-Local (APIPA): 169.254.0.0/16 ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Used for automatic IP assignment when DHCP unavailable β ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββSubnet Mask Calculations
Section titled βSubnet Mask Calculationsββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ SUBNET MASK REFERENCE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ CIDR Mask Usable Hosts Power of 2 ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ /30 255.255.255.252 2 4-2 = 2 ββ /29 255.255.255.248 6 8-2 = 6 ββ /28 255.255.255.240 14 16-2 = 14 ββ /27 255.255.255.224 30 32-2 = 30 ββ /26 255.255.255.192 62 64-2 = 62 ββ /25 255.255.255.128 126 128-2 = 126 ββ /24 255.255.255.0 254 256-2 = 254 ββ /23 255.255.254.0 510 512-2 = 510 ββ /22 255.255.252.0 1022 1024-2 = 1022 ββ /21 255.255.248.0 2046 2048-2 = 2046 ββ /20 255.255.240.0 4094 4096-2 = 4094 ββ /19 255.255.224.0 8190 8192-2 = 8190 ββ /18 255.255.192.0 16382 16384-2 = 16382 ββ /17 255.255.128.0 32766 32768-2 = 32766 ββ /16 255.255.0.0 65534 65536-2 = 65534 ββ /8 255.0.0.0 16777214 16777216-2 ββ ββ Formula: Hosts = 2^(32 - CIDR) - 2 ββ (Subtract 2 for network address and broadcast) ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ21.3 Basic Network Commands
Section titled β21.3 Basic Network CommandsβIP Configuration
Section titled βIP Configurationβ# View IP addressesip addr showip addr show eth0
# Alternative (legacy)ifconfigifconfig -a
# Add IP addresssudo ip addr add 192.168.1.10/24 dev eth0
# Remove IP addresssudo ip addr del 192.168.1.10/24 dev eth0
# Bring interface up/downsudo ip link set eth0 upsudo ip link set eth0 down
# View interface detailsip link showip -s link show eth0Routing
Section titled βRoutingβ# View routing tableip route showip route
# Alternative (legacy)route -n
# Add default routesudo ip route add default via 192.168.1.1
# Add static routesudo ip route add 10.0.0.0/24 via 192.168.1.1
# Delete routesudo ip route del default via 192.168.1.1
# View specific routeip route get 8.8.8.8
# Add route with metricsudo ip route add default via 192.168.1.1 metric 100Connectivity Testing
Section titled βConnectivity Testingβ# Pingping -c 4 8.8.8.8ping -c 4 google.comping -i 0.2 host # 0.2 second intervalping -f host # Flood ping (root only)
# Trace pathtraceroute google.comtraceroute -I google.com # ICMPtraceroute -T -p 80 google.com # TCP
# Alternative: mtr (combined ping + traceroute)mtr google.com
# Path MTU discoverytracepath google.comDNS Commands
Section titled βDNS Commandsβ# DNS lookupnslookup google.comdig google.comhost google.com
# Specific DNS servernslookup google.com 8.8.8.8dig @8.8.8.8 google.com
# Query specific recorddig google.com MXdig google.com TXTdig google.com AAAA
# Reverse DNS lookupdig -x 8.8.8.8host 8.8.8.8Connection Monitoring
Section titled βConnection Monitoringβ# Socket statistics (modern)ss -tunaplss -tunapl | grep :80ss -tn | wc -l # Count connections
# Socket statistics (legacy)netstat -tunaplnetstat -i # Interface stats
# Listening portsss -tulpnss -tulpn | grep LISTEN
# Connection statesss -tan state established
# Process using portss -tulnp | grep :80lsof -i :80fuser 80/tcpNetwork Interface Testing
Section titled βNetwork Interface Testingβ# Bandwidth testiperf3 -s # Serveriperf3 -c server # Client
# Quick testcurl -I https://google.comwget -O /dev/null https://google.com
# NIC bonding/team infoip link show type bondip link show type team21.4 Network Configuration Files
Section titled β21.4 Network Configuration FilesβDNS Configuration
Section titled βDNS Configurationβnameserver 8.8.8.8nameserver 8.8.4.4search example.com
# View current DNScat /etc/resolv.conf
# Check DNS resolutiongetent hosts google.comHostname Configuration
Section titled βHostname Configurationβ# View hostnamehostnamehostnamectl
# Set hostname (persistent)sudo hostnamectl set-hostname server01.example.com
# Set hostname (temporary)sudo hostname temp-hostname
# /etc/hostnameecho "server01" | sudo tee /etc/hostnameNetwork Configuration (Debian)
Section titled βNetwork Configuration (Debian)βauto eth0iface eth0 inet static address 192.168.1.10 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 8.8.8.8 8.8.4.4
# DHCPiface eth0 inet dhcp
# Restart networkingsudo systemctl restart networkingNetwork Configuration (RHEL/CentOS)
Section titled βNetwork Configuration (RHEL/CentOS)βDEVICE=eth0BOOTPROTO=staticONBOOT=yesIPADDR=192.168.1.10NETMASK=255.255.255.0GATEWAY=192.168.1.1DNS1=8.8.8.8
# Restart networksudo systemctl restart networkStatic Routes
Section titled βStatic Routesβ# RHEL/CentOS - /etc/sysconfig/network-scripts/route-eth0# 10.0.0.0/24 via 192.168.1.1 dev eth0
# Debian - /etc/network/interfacesup ip route add 10.0.0.0/24 via 192.168.1.121.5 Network Troubleshooting
Section titled β21.5 Network TroubleshootingβDiagnostic Flow
Section titled βDiagnostic Flowββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ NETWORK TROUBLESHOOTING FLOW βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ 1. Is the interface up? ββ βββΊ ip link show ββ βββΊ ip link set eth0 up ββ ββ 2. Does it have an IP? ββ βββΊ ip addr show ββ βββΊ dhclient eth0 or ip addr add ββ ββ 3. Can it reach gateway? ββ βββΊ ping <gateway> ββ βββΊ Check routing table ββ ββ 4. Can it reach external hosts? ββ βββΊ ping 8.8.8.8 ββ βββΊ Check DNS, firewall ββ ββ 5. Can it resolve DNS? ββ βββΊ nslookup google.com ββ βββΊ Check /etc/resolv.conf ββ ββ 6. Check firewall ββ βββΊ iptables -L -n ββ βββΊ firewall-cmd --list-all ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββCommon Issues
Section titled βCommon Issuesβ# Interface not showingip link show# Check driver loadedlsmod | grep e1000
# No IP addressdhclient -v eth0# Check DHCP server
# Can't ping gateway# Check IP, netmask, gateway settings
# Can't ping external# Check DNS, firewall
# DNS not workingcat /etc/resolv.confping 8.8.8.8Advanced Diagnostics
Section titled βAdvanced Diagnosticsβ# Capture packetstcpdump -i eth0tcpdump -i eth0 port 80tcpdump -i eth0 host 192.168.1.1
# Analyze traffictcpdump -w capture.pcap# Then analyze with Wireshark
# Check ARP tableip neigh showarp -a
# Check link statusethtool eth0mii-tool eth021.6 IPv6 Basics
Section titled β21.6 IPv6 BasicsβIPv6 Addressing
Section titled βIPv6 Addressingββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ IPv6 ADDRESS TYPES βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ Global Unicast (2000::/3) ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β 2001:0db8:85a3:0000:0000:8a2e:0370:7334 β ββ β ββββββ΄ββββββ΄βββββββ΄ββββββ΄βββββββ΄ββββββ΄βββββββ΄βββββββββββββ β ββ β Prefix Registry Site ID Subnet Interface ID β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Link-Local (fe80::/10) ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β fe80::1 (automatic on every interface) β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Unique Local (fc00::/7) ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β fd00::/8 (private, like 10.x.x.x) β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Loopback (::1) ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β ::1 β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Special Addresses: ββ - :: (unspecified, like 0.0.0.0) ββ - ::1 (loopback, like 127.0.0.1) ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββIPv6 Commands
Section titled βIPv6 Commandsβ# View IPv6 addressesip -6 addr show
# Add IPv6 addresssudo ip -6 addr add 2001:db8::1/64 dev eth0
# Ping IPv6ping6 -I eth0 fe80::1ping6 google.com
# Trace IPv6 pathtraceroute6 google.com21.7 Interview Questions
Section titled β21.7 Interview QuestionsβQ1: Explain the OSI model layers.
Section titled βQ1: Explain the OSI model layers.βAnswer:
- Physical - Hardware, cables, hubs
- Data Link - MAC addresses, switches
- Network - IP addresses, routers
- Transport - TCP/UDP, ports
- Session - Session management
- Presentation - Data formatting, encryption
- Application - User interface, protocols (HTTP, FTP, SMTP)
Q2: Whatβs the difference between TCP and UDP?
Section titled βQ2: Whatβs the difference between TCP and UDP?βAnswer:
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Reliability | Reliable, ordered | Unreliable |
| Speed | Slower | Faster |
| Overhead | Higher | Lower |
| Use Cases | HTTP, SSH, Email | DNS, VoIP, Video |
| Flow Control | Yes | No |
| Congestion Control | Yes | No |
Q3: What are private IP ranges?
Section titled βQ3: What are private IP ranges?βAnswer:
- 10.0.0.0/8 (10.0.0.0 - 10.255.255.255)
- 172.16.0.0/12 (172.16.0.0 - 172.31.255.255)
- 192.168.0.0/16 (192.168.0.0 - 192.168.255.255)
- 169.254.0.0/16 (Link-local/APIPA)
Q4: What is a subnet mask?
Section titled βQ4: What is a subnet mask?βAnswer: A subnet mask defines which portion of an IP address is the network and which is the host:
- /24 = 255.255.255.0 = 256 addresses (254 usable)
- /16 = 255.255.0.0 = 65,536 addresses (65,534 usable)
- /8 = 255.0.0.0 = 16,777,216 addresses
Q5: What is the difference between /bin and /usr/bin?
Section titled βQ5: What is the difference between /bin and /usr/bin?βAnswer: In modern Linux, theyβre often the same or similar:
- /bin - Essential system commands (legacy)
- /usr/bin - User programs
- On many systems, /bin is a symlink to /usr/bin
- Both are in the default PATH
Q6: What is the loopback address?
Section titled βQ6: What is the loopback address?βAnswer: 127.0.0.1 (IPv4) or ::1 (IPv6) - A special IP address that refers to the local machine. Traffic to this address doesnβt go to the network - it loops back within the host.
Q7: What does the default route (0.0.0.0) mean?
Section titled βQ7: What does the default route (0.0.0.0) mean?βAnswer: The default route (0.0.0.0/0 or simply 0.0.0.0) matches all IP addresses. Itβs used to send traffic that doesnβt match any specific route to a gateway (usually an internet-facing router).
Q8: What is NAT?
Section titled βQ8: What is NAT?βAnswer: Network Address Translation (NAT) maps private IP addresses to public IPs. Common types:
- SNAT: Source NAT - outgoing traffic
- DNAT: Destination NAT - incoming traffic
- PAT: Port Address Translation - many-to-one (port forwarding)
Quick Reference
Section titled βQuick ReferenceβCommands
Section titled βCommandsβ# Configurationip addr add 192.168.1.10/24 dev eth0ip link set eth0 upip route add default via 192.168.1.1
# Testingping -c 4 hosttraceroute hostnslookup hostdig host
# Monitoringss -tunaplnetstat -tunapl
# DNScat /etc/resolv.confhostnamectlWell-Known Ports
Section titled βWell-Known Portsβ| Port | Service |
|---|---|
| 20/21 | FTP |
| 22 | SSH |
| 23 | Telnet |
| 25 | SMTP |
| 53 | DNS |
| 80 | HTTP |
| 110 | POP3 |
| 143 | IMAP |
| 443 | HTTPS |
| 3306 | MySQL |
| 5432 | PostgreSQL |
| 6379 | Redis |
| 8080 | HTTP Alt |
Why This Matters in DevOps/SRE
Section titled βWhy This Matters in DevOps/SREβNetworking fundamentals are essential for cloud and infrastructure work:
Networking in DevOps/SRE+------------------------------------------------------------------+| || Cloud Networking: || +----------------------------------------------------------+ || | VPC -> Virtual Private Cloud | || | Subnets -> Public/Private segmentation | || | Security Groups -> Instance-level firewall | || | NACLs -> Subnet-level firewall | || +----------------------------------------------------------+ || || Load Balancing: || +----------------------------------------------------------+ || | ALB -> Layer 7 routing | || | NLB -> Layer 4 performance | || | Route 53 -> DNS load balancing | || +----------------------------------------------------------+ || || Service Mesh: || +----------------------------------------------------------+ || | Istio -> Service-to-service communication | || | Linkerd -> Lightweight service mesh | || | Envoy -> Sidecar proxy | || +----------------------------------------------------------+ || |+------------------------------------------------------------------+Practical Impact:
- Design and troubleshoot cloud infrastructure
- Configure VPCs, subnets, and security groups
- Debug network issues in distributed systems
Common Mistakes & Anti-Patterns
Section titled βCommon Mistakes & Anti-Patternsβ1. Not Using Private Subnets
Section titled β1. Not Using Private Subnetsβ# WRONG: All resources in public subnet# Database directly accessible from internet# Security vulnerability
# CORRECT: Private subnets for databases# public subnet -> load balancers, bastion# private subnet -> application servers, databases2. Overly Permissive Security Groups
Section titled β2. Overly Permissive Security Groupsβ# WRONG: Wide open security group# 0.0.0.0/0 for all traffic# Security risk
# CORRECT: Least privilege# sg-abc123 -> port 443 from sg-xyz789# Specific CIDR ranges only3. Not Planning IP Addressing
Section titled β3. Not Planning IP Addressingβ# WRONG: Random IP allocation# Overlapping VPCs# Can't peer or connect
# CORRECT: Plan CIDR ranges# 10.0.0.0/16 for VPC# 10.0.1.0/24 for public# 10.0.10.0/24 for private app# 10.0.20.0/24 for private databaseSummary
Section titled βSummaryβIn this chapter, you learned:
- β OSI and TCP/IP models
- β IPv4 addressing and classes
- β Private IP ranges
- β Subnet mask calculations
- β Basic network commands
- β Network configuration files
- β Network troubleshooting
- β IPv6 basics
- β Interview questions and answers
Next Chapter
Section titled βNext ChapterβChapter 22: Network Configuration
Last Updated: February 2026