The TCP/IP protocol stack is the fundamental framework for networking in Linux and all modern computer systems. It governs communication across networks using Internet Protocol versions 4 (IPv4) and 6 (IPv6), addressing, routing packets between hosts and networks, and defining how data is encapsulated and transported.
A strong understanding of IP addressing, routing concepts, routing table management, policy-based routing, and default gateway configuration is essential for effective network administration and troubleshooting in professional Linux environments.
IP Addressing: IPv4 and IPv6
To understand networking fundamentals, it is important to know how IPv4 and IPv6 addressing works. The list below introduces address structure, types, and usage.
1. IPv4: 32-bit addresses written as four octets separated by dots (e.g., 192.168.1.10).
It supports subnetting using subnet masks or prefix lengths (e.g., /24).
Address classes (A, B, C) historically defined address ranges, but now superseded by CIDR.
2. IPv6: 128-bit address format, written as eight groups of four hexadecimal digits separated by colons (e.g., 2001:0db8::1).
It Supports vast address space to accommodate future growth.
Includes address types like unicast, multicast, and anycast.
Linux supports both IPv4 and IPv6 often in dual-stack configurations, with configuration possible via command line or network managers.
Routing defines how network traffic moves between different networks. The list below describe routing tables, next-hop decisions, and route types.
1. Routing directs packets between source and destination across networks using routing tables.
2. Routers or hosts consult routing tables to decide the next hop for packet forwarding.
3. Routes can be static (manually configured) or dynamic (learned via routing protocols).
4. Linux systems commonly use static routes configured for fixed network topologies.
Routing Table Management with ip route
Linux provides the ip command suite for routing table management. Basic commands include:
1. Display routing table:
ip route show2. Add a static route:
sudo ip route add 10.0.0.0/24 via 192.168.1.1 dev eth03. Delete a route:
sudo ip route del 10.0.0.0/24Routes consist of destination prefixes, gateways (next hops), and output interfaces.
PBR allows routing decisions based on policies beyond destination IP, such as source address, packet marks, or interface. Commonly configured using multiple routing tables and rules with ip rule.
Use cases: Multi-homing, VPN routing, traffic segregation.
Example policy routing commands
1. Add a new routing table entry:
echo "200 customroute" >> /etc/iproute2/rt_tables2. Add IP rules to select table based on source IP:
sudo ip rule add from 192.168.2.0/24 table customroute
sudo ip route add default via 192.168.1.254 table customrouteDefault Gateway Configuration
The default gateway is the router used to forward packets for destinations not in the routing table.
1. View default route:
ip route show default2. Set default gateway:
sudo ip route add default via 192.168.1.1Persistent default gateways can be configured in network configuration files or managers (e.g., Netplan, NetworkManager).