Skip to content

Networking_fundamentals


┌────────────────────────────────────────────────────────────────────────┐
│ 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 │
├────────────────────────────────────────────────────────────────────────┤
│ │
│ 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 │ │
│ └─────────────────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────────────┘

┌────────────────────────────────────────────────────────────────────────┐
│ 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 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 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) │
│ │
└────────────────────────────────────────────────────────────────────────┘

Terminal window
# View IP addresses
ip addr show
ip addr show eth0
# Alternative (legacy)
ifconfig
ifconfig -a
# Add IP address
sudo ip addr add 192.168.1.10/24 dev eth0
# Remove IP address
sudo ip addr del 192.168.1.10/24 dev eth0
# Bring interface up/down
sudo ip link set eth0 up
sudo ip link set eth0 down
# View interface details
ip link show
ip -s link show eth0
Terminal window
# View routing table
ip route show
ip route
# Alternative (legacy)
route -n
# Add default route
sudo ip route add default via 192.168.1.1
# Add static route
sudo ip route add 10.0.0.0/24 via 192.168.1.1
# Delete route
sudo ip route del default via 192.168.1.1
# View specific route
ip route get 8.8.8.8
# Add route with metric
sudo ip route add default via 192.168.1.1 metric 100
Terminal window
# Ping
ping -c 4 8.8.8.8
ping -c 4 google.com
ping -i 0.2 host # 0.2 second interval
ping -f host # Flood ping (root only)
# Trace path
traceroute google.com
traceroute -I google.com # ICMP
traceroute -T -p 80 google.com # TCP
# Alternative: mtr (combined ping + traceroute)
mtr google.com
# Path MTU discovery
tracepath google.com
Terminal window
# DNS lookup
nslookup google.com
dig google.com
host google.com
# Specific DNS server
nslookup google.com 8.8.8.8
dig @8.8.8.8 google.com
# Query specific record
dig google.com MX
dig google.com TXT
dig google.com AAAA
# Reverse DNS lookup
dig -x 8.8.8.8
host 8.8.8.8
Terminal window
# Socket statistics (modern)
ss -tunapl
ss -tunapl | grep :80
ss -tn | wc -l # Count connections
# Socket statistics (legacy)
netstat -tunapl
netstat -i # Interface stats
# Listening ports
ss -tulpn
ss -tulpn | grep LISTEN
# Connection states
ss -tan state established
# Process using port
ss -tulnp | grep :80
lsof -i :80
fuser 80/tcp
Terminal window
# Bandwidth test
iperf3 -s # Server
iperf3 -c server # Client
# Quick test
curl -I https://google.com
wget -O /dev/null https://google.com
# NIC bonding/team info
ip link show type bond
ip link show type team

/etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
# View current DNS
cat /etc/resolv.conf
# Check DNS resolution
getent hosts google.com
Terminal window
# View hostname
hostname
hostnamectl
# Set hostname (persistent)
sudo hostnamectl set-hostname server01.example.com
# Set hostname (temporary)
sudo hostname temp-hostname
# /etc/hostname
echo "server01" | sudo tee /etc/hostname
/etc/network/interfaces
auto eth0
iface 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
# DHCP
iface eth0 inet dhcp
# Restart networking
sudo systemctl restart networking
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
# Restart network
sudo systemctl restart network
Terminal window
# RHEL/CentOS - /etc/sysconfig/network-scripts/route-eth0
# 10.0.0.0/24 via 192.168.1.1 dev eth0
# Debian - /etc/network/interfaces
up ip route add 10.0.0.0/24 via 192.168.1.1

┌────────────────────────────────────────────────────────────────────────┐
│ 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 │
│ │
└────────────────────────────────────────────────────────────────────────┘
Terminal window
# Interface not showing
ip link show
# Check driver loaded
lsmod | grep e1000
# No IP address
dhclient -v eth0
# Check DHCP server
# Can't ping gateway
# Check IP, netmask, gateway settings
# Can't ping external
# Check DNS, firewall
# DNS not working
cat /etc/resolv.conf
ping 8.8.8.8
Terminal window
# Capture packets
tcpdump -i eth0
tcpdump -i eth0 port 80
tcpdump -i eth0 host 192.168.1.1
# Analyze traffic
tcpdump -w capture.pcap
# Then analyze with Wireshark
# Check ARP table
ip neigh show
arp -a
# Check link status
ethtool eth0
mii-tool eth0

┌────────────────────────────────────────────────────────────────────────┐
│ 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) │
│ │
└────────────────────────────────────────────────────────────────────────┘
Terminal window
# View IPv6 addresses
ip -6 addr show
# Add IPv6 address
sudo ip -6 addr add 2001:db8::1/64 dev eth0
# Ping IPv6
ping6 -I eth0 fe80::1
ping6 google.com
# Trace IPv6 path
traceroute6 google.com

Answer:

  1. Physical - Hardware, cables, hubs
  2. Data Link - MAC addresses, switches
  3. Network - IP addresses, routers
  4. Transport - TCP/UDP, ports
  5. Session - Session management
  6. Presentation - Data formatting, encryption
  7. 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:

FeatureTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityReliable, orderedUnreliable
SpeedSlowerFaster
OverheadHigherLower
Use CasesHTTP, SSH, EmailDNS, VoIP, Video
Flow ControlYesNo
Congestion ControlYesNo

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)

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

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).

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)

Terminal window
# Configuration
ip addr add 192.168.1.10/24 dev eth0
ip link set eth0 up
ip route add default via 192.168.1.1
# Testing
ping -c 4 host
traceroute host
nslookup host
dig host
# Monitoring
ss -tunapl
netstat -tunapl
# DNS
cat /etc/resolv.conf
hostnamectl
PortService
20/21FTP
22SSH
23Telnet
25SMTP
53DNS
80HTTP
110POP3
143IMAP
443HTTPS
3306MySQL
5432PostgreSQL
6379Redis
8080HTTP Alt

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

Chapter 22: Network Configuration


Last Updated: February 2026