The OSI Model
Network communication is organized in layers. The OSI model defines 7:
| Layer | Name | Function | Example |
|---|---|---|---|
| 7 | Application | User-facing protocols | HTTP, SSH, DNS |
| 6 | Presentation | Data formatting/encryption | SSL/TLS, JPEG |
| 5 | Session | Connection management | NetBIOS |
| 4 | Transport | Reliable delivery | TCP, UDP |
| 3 | Network | Routing and addressing | IP, ICMP |
| 2 | Data Link | Local delivery, MAC addresses | Ethernet, Wi-Fi |
| 1 | Physical | Electrical signals, cables | Cat6, fiber |
TCP/IP Model (Simplified)
| TCP/IP Layer | OSI Layers | Protocols |
|---|---|---|
| Application | 7, 6, 5 | HTTP, SSH, DNS, FTP |
| Transport | 4 | TCP, UDP |
| Internet | 3 | IP, ICMP |
| Network Interface | 2, 1 | Ethernet, Wi-Fi |
TCP vs UDP
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Reliability | Guaranteed delivery | Best-effort |
| Speed | Slower (overhead) | Faster |
| Use case | Web, SSH, email | Streaming, 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
| Range | Class | Use |
|---|---|---|
| 10.0.0.0 – 10.255.255.255 | A | Large private networks |
| 172.16.0.0 – 172.31.255.255 | B | Medium private networks |
| 192.168.0.0 – 192.168.255.255 | C | Small private networks (home/office) |
| Everything else | — | Public (Internet-routable) |
Subnet Masks and CIDR
A subnet mask separates the network portion from the host portion:
| CIDR | Subnet Mask | Hosts |
|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 |
| /16 | 255.255.0.0 | 65,534 |
| /24 | 255.255.255.0 | 254 |
| /25 | 255.255.255.128 | 126 |
| /32 | 255.255.255.255 | 1 |
Example: 192.168.1.100/24 means:
- Network:
192.168.1.0 - Hosts:
192.168.1.1to192.168.1.254 - Broadcast:
192.168.1.255
Network Configuration with ip
View Interfaces
ip addr show
# or shorter:
ip aKey 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 aAdd/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 eth0Enable/Disable Interfaces
# Disable
sudo ip link set down eth0
# Enable
sudo ip link set up eth0DNS — Domain Name System
DNS translates domain names to IP addresses:
google.com → 142.250.180.3
How DNS Works
- Browser asks local DNS resolver
- Resolver checks cache, then queries root servers
- Root → TLD server (.com) → Authoritative server
- 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.comLocal DNS Override (/etc/hosts)
sudo nano /etc/hosts127.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 rOutput:
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/24Essential Network Commands
ping — Test Connectivity
# Test if host is reachable
ping -c 4 8.8.8.8
# Ping a domain
ping -c 4 google.comtraceroute — Trace Path
# Show hops to destination
traceroute google.comDHCP — Automatic IP Assignment
# Request IP from DHCP server
sudo dhclient eth0
# Release DHCP lease
sudo dhclient -r eth0Hostname Management
# View hostname
hostname
# Change hostname (persistent)
sudo hostnamectl set-hostname my-server
# Verify
hostnamectlPorts and Sockets
Services listen on specific ports. A socket = IP + Port + Protocol.
| Port | Service | Protocol |
|---|---|---|
| 22 | SSH | TCP |
| 80 | HTTP | TCP |
| 443 | HTTPS | TCP |
| 53 | DNS | TCP/UDP |
| 3306 | MySQL/MariaDB | TCP |
# View listening ports
sudo ss -tuln
# Or with netstat
sudo netstat -tulnSummary
- 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 addrmanages interfaces;ip routemanages routing- DNS translates names to IPs; configured in
/etc/resolv.conf pingtests connectivity;tracerouteshows 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.