Networking Fundamentals

30 minLesson 11 of 16

Learning Objectives

  • Understand the OSI model and TCP/IP stack
  • Work with IPv4 addresses, subnets, and CIDR notation
  • Explain DNS resolution and routing
  • Differentiate between public and private IP addresses
  • Configure network interfaces with the ip command

The OSI Model

Network communication is organized in layers. The OSI model defines 7:

LayerNameFunctionExample
7ApplicationUser-facing protocolsHTTP, SSH, DNS
6PresentationData formatting/encryptionSSL/TLS, JPEG
5SessionConnection managementNetBIOS
4TransportReliable deliveryTCP, UDP
3NetworkRouting and addressingIP, ICMP
2Data LinkLocal delivery, MAC addressesEthernet, Wi-Fi
1PhysicalElectrical signals, cablesCat6, fiber

TCP/IP Model (Simplified)

TCP/IP LayerOSI LayersProtocols
Application7, 6, 5HTTP, SSH, DNS, FTP
Transport4TCP, UDP
Internet3IP, ICMP
Network Interface2, 1Ethernet, Wi-Fi

TCP vs UDP

FeatureTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityGuaranteed deliveryBest-effort
SpeedSlower (overhead)Faster
Use caseWeb, SSH, emailStreaming, DNS, gaming

IP Addressing

IPv4 Format

An IPv4 address is 4 octets (32 bits) in dotted decimal:

192.168.1.100

Each octet ranges from 0-255.

Private vs Public IPs

RangeClassUse
10.0.0.0 – 10.255.255.255ALarge private networks
172.16.0.0 – 172.31.255.255BMedium private networks
192.168.0.0 – 192.168.255.255CSmall private networks (home/office)
Everything elsePublic (Internet-routable)

Subnet Masks and CIDR

A subnet mask separates the network portion from the host portion:

CIDRSubnet MaskHosts
/8255.0.0.016,777,214
/16255.255.0.065,534
/24255.255.255.0254
/25255.255.255.128126
/32255.255.255.2551

Example: 192.168.1.100/24 means:

  • Network: 192.168.1.0
  • Hosts: 192.168.1.1 to 192.168.1.254
  • Broadcast: 192.168.1.255

Network Configuration with ip

View Interfaces

ip addr show
# or shorter:
ip a

Key information:

  • lo — Loopback (127.0.0.1, internal communication)
  • eth0 / ens5 — Primary network interface
  • inet — IPv4 address
  • link/ether — MAC address

View Specific Interface

ip addr show dev eth0
 
# IPv4 only
ip -4 a
 
# IPv6 only
ip -6 a

Add/Remove IP Addresses

# Add an IP
sudo ip addr add 192.168.1.50/24 dev eth0
 
# Remove an IP
sudo ip addr del 192.168.1.50/24 dev eth0

Enable/Disable Interfaces

# Disable
sudo ip link set down eth0
 
# Enable
sudo ip link set up eth0

DNS — Domain Name System

DNS translates domain names to IP addresses:

google.com → 142.250.180.3

How DNS Works

  1. Browser asks local DNS resolver
  2. Resolver checks cache, then queries root servers
  3. Root → TLD server (.com) → Authoritative server
  4. IP address returned to browser

DNS Configuration

# View configured DNS servers
cat /etc/resolv.conf
 
# Test DNS resolution
host google.com
dig google.com
nslookup google.com

Local DNS Override (/etc/hosts)

sudo nano /etc/hosts
127.0.0.1   localhost
192.168.1.10  myserver.local
192.168.1.20  database.local

Routing

Routing determines how packets reach their destination across networks.

View Routing Table

ip route
# or
ip r

Output:

default via 172.31.16.1 dev eth0
172.31.16.0/20 dev eth0 proto kernel scope link src 172.31.24.148
  • default — Gateway for all external traffic
  • 172.31.16.0/20 — Local network (direct access)

Add/Remove Routes

# Add route to a network via gateway
sudo ip route add 10.0.0.0/24 via 172.31.16.1 dev eth0
 
# Add default gateway
sudo ip route add default via 192.168.1.1
 
# Remove a route
sudo ip route del 10.0.0.0/24

Essential Network Commands

ping — Test Connectivity

# Test if host is reachable
ping -c 4 8.8.8.8
 
# Ping a domain
ping -c 4 google.com

traceroute — Trace Path

# Show hops to destination
traceroute google.com

DHCP — Automatic IP Assignment

# Request IP from DHCP server
sudo dhclient eth0
 
# Release DHCP lease
sudo dhclient -r eth0

Hostname Management

# View hostname
hostname
 
# Change hostname (persistent)
sudo hostnamectl set-hostname my-server
 
# Verify
hostnamectl

Ports and Sockets

Services listen on specific ports. A socket = IP + Port + Protocol.

PortServiceProtocol
22SSHTCP
80HTTPTCP
443HTTPSTCP
53DNSTCP/UDP
3306MySQL/MariaDBTCP
# View listening ports
sudo ss -tuln
 
# Or with netstat
sudo netstat -tuln

Summary

  • OSI model has 7 layers; TCP/IP simplifies to 4
  • IPv4: 32-bit addresses in dotted decimal (e.g., 192.168.1.1)
  • CIDR notation (/24) defines network size
  • ip addr manages interfaces; ip route manages routing
  • DNS translates names to IPs; configured in /etc/resolv.conf
  • ping tests connectivity; traceroute shows the path
  • Ports identify services; common: 22 (SSH), 80 (HTTP), 443 (HTTPS)

Next Steps

Next, we'll put networking into practice with firewalls (iptables/UFW), port scanning, and SSH configuration.