Linux Routing Basics: Adding, Deleting Host, Network, and Default Routes
This article explains Linux routing fundamentals, describing how routing tables are used to select interfaces and next hops, detailing the six-step packet routing process, and providing step‑by‑step commands and examples for adding and removing host, network, and default routes on Linux systems.
Routing Basics : A routing table consists of one or more entries; before sending each IP packet the system looks up the host routing table to decide which network interface and next hop to use. Each entry includes destination IP, netmask, interface, gateway (next‑hop IP), and metric.
Packet routing six steps :
Search the routing table.
If a matching entry is found, forward the packet via the specified interface to the next hop or directly to the destination.
If not matched, continue searching.
If no entry matches, look for a default route.
If a default route exists, forward the packet according to it.
If no default route exists, drop the packet.
Viewing the current routing table on Linux :
The table columns are:
Destination : target network or host.
Gateway : gateway address; "*" or "0.0.0.0" means the target is on a directly connected network.
Genmask : network mask.
Flags : e.g., U (active), H (host), G (gateway), R (dynamic), D (installed by daemon), M (modified), ! (reject).
Metric : route distance; lower numbers have higher priority.
Ref : reference count (unused in Linux kernel).
Use : number of times the route has been used.
Iface : output interface.
Host Routing
Adding a host route on Linux:
sudo route add -host 192.168.43.192 metric 301 dev wlan0
Result: a new entry directs traffic for 192.168.43.192 through wlan0 with metric 301.
If the destination requires a gateway, include the gw option (the gateway must be reachable):
sudo route add -host 192.168.43.192 gw 192.168.43.1 metric 301 dev wlan0
Deleting the host route:
sudo route del -host 192.168.43.192 metric 301 dev wlan0
Network Routing
Adding a network route:
sudo route add -net 192.168.3.0 netmask 255.255.255.0 metric 100 dev eth0
Result: traffic to any IP in 192.168.3.0/24 is sent via eth0 with metric 100. A gateway can be added similarly if required.
Deleting the network route:
sudo route del -net 192.168.3.0 netmask 255.255.255.0 metric 100 dev eth0
Default Route
Adding a default route:
sudo route add default gw 192.168.43.1 dev wlan0
Result: a default route with metric 0 is created, sending all unspecified traffic through wlan0 .
Deleting the default route:
sudo route del default gw 192.168.43.1
These commands illustrate how to manage routing entries on a Linux system, covering host, network, and default routes.
--- End of technical guide ---
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.