Linux Routing Basics (ip route)¶
Routing is the process by which a Linux kernel determines where to send network packets. Whether a packet is destined for a local server or a remote website, the Routing Table acts as the system's internal map. In modern Linux, the ip route utility is the primary tool for inspecting and manipulating this map.
graph TD
User([Linux Server]) --> RT{Routing Table}
RT -- "Match found" --> GW[Specific Gateway/Interface]
RT -- "No match" --> Default[Default Gateway]
Default --> Ext((External Internet))
classDef client fill:#dbeafe,stroke:#93c5fd,color:#1e3a5f
classDef gateway fill:#ede9fe,stroke:#a78bfa,color:#3b1f6e
classDef route fill:#fef9c3,stroke:#fbbf24,color:#78350f
classDef external fill:#f1f5f9,stroke:#94a3b8,color:#1e293b
class User client
class RT gateway
class GW external
class Default route
class Ext external
1. Viewing the Routing Table¶
To see the current map of network paths, use the show object of the ip route command.
ip route show
Common Output Fields:
- default: The catch-all route for any traffic not matching other entries.
- via: The IP address of the gateway (router).
- dev: The network interface (e.g.,
eth0,wlan0). - proto kernel: Indicates the route was created automatically by the kernel.
- metric: The priority of the route (lower values have higher priority).
2. Managing the Default Gateway¶
The default gateway is the most critical entry in your routing table. Without it, your server cannot communicate with any host outside its immediate local subnet.
Adding a Default Gateway: If your server loses its gateway, you can manually restore it:
sudo ip route add default via 10.0.0.1 dev eth0
Tip
Always verify that the gateway IP (via) is reachable within your local subnet before adding it, or the route will remain inactive.
3. Creating Static Routes¶
Static routes are manual entries used to direct traffic for specific IPs or subnets through non-standard paths.
Host Route (Single IP): Direct traffic for a specific server through a dedicated interface:
sudo ip route add 1.1.1.1 dev eth0
Network Route (Subnet): Route an entire subnet (using CIDR notation) through a specific gateway:
sudo ip route add 192.168.100.0/24 via 10.0.0.1
4. Deleting Routes¶
To avoid routing conflicts or clean up temporary paths, you can remove entries using the del command.
sudo ip route del 192.168.100.0/24
5. Persistence and Runtime State¶
Commands executed with ip route are applied directly to the kernel's runtime memory.
Important
These changes are temporary. If the system reboots, all manually added routes will be lost. To make them permanent, you must add them to your distribution's network configuration files (e.g., /etc/netplan/*.yaml on Ubuntu).
๐ง Quick Quiz - Routing Basics¶
Which keyword in the routing table represents the path for all traffic that doesn't match a specific subnet?
What is the effect of running 'sudo ip route add 1.1.1.1 dev eth0'?
True or False: Routes added via 'ip route' will persist after a system reboot.
๐ Want More Practice?¶
To strengthen your understanding and prepare for interviews, try the full 20-question practice quiz based on this chapter:
๐ Start Networking Quiz (20 Questions)
(If there is no exact matching directory, default to the top-level topic quiz page URL).
๐ฌ DevopsPilot Weekly โ Learn DevOps, Cloud & Gen AI the simple way.
๐ Subscribe here