A packet leaves — and never comes back. The server sees the internet but cannot reach the corporate subnet. After a reboot, the routes are gone. All of this is fixed through the routing table — but only if you understand how it is structured and where its settings live on different distributions.
How Linux Decides Where to Send a Packet
When an application sends a packet, the kernel checks the routing table from top to bottom. The first match between the destination address and a table entry sends the packet through the specified interface and gateway. If there are no matches — the default route is used. If there is no default route — the packet is dropped with Network unreachable.
The routing table is not an exotic tool. It runs on every server and every laptop — it just rarely needs to be touched.
View the Routing Table
Modern approach via ip:
ip route
Typical output:
default via 192.168.1.1 dev enp2s0 proto static metric 100
192.168.1.0/24 dev enp2s0 proto kernel scope link src 192.168.1.50
10.0.0.0/8 via 10.0.0.1 dev eth1 proto static
Field breakdown: default is the fallback route when no specific entry matches. via 192.168.1.1 is the gateway. dev enp2s0 is the network interface. proto static means added by an administrator; proto kernel means added automatically by the kernel when the interface was configured. metric 100 is priority — lower number means higher priority.
Show all routing tables:
ip route show table all
The older route command also works — shows the table with hostnames:
route

To show numeric IP addresses instead of hostnames, add the -n flag:
route -n
Detailed table via routel:
routel

Modern view via ip route:
ip route

Add a Temporary Route
Set the default gateway:
sudo ip route add default via 192.168.1.1
Route to a specific subnet:
sudo ip route add 203.0.113.0/24 via 192.168.1.1
Route through a specific interface without specifying a gateway:
sudo ip route add 10.0.0.0/8 dev eth1
Two paths to the same network with different priorities:
sudo ip route add 10.0.0.0/8 via 10.0.0.1 metric 50
sudo ip route add 10.0.0.0/8 via 10.0.0.2 metric 100
Traffic goes through 10.0.0.1 (metric 50 = higher priority). If it becomes unreachable, the system automatically falls back to 10.0.0.2.
Temporary routes disappear after reboot.
Delete a Route
sudo ip route del default via 192.168.1.1
sudo ip route del 10.0.0.0/8
Persistent Routes: Ubuntu and Debian (Netplan)
On Ubuntu 18.04+ and modern Debian, network configuration lives in Netplan — YAML files in /etc/netplan/.
Check the current file:
ls /etc/netplan/
cat /etc/netplan/01-netcfg.yaml
Add a persistent route:
network:
version: 2
ethernets:
enp2s0:
dhcp4: true
routes:
- to: 10.0.0.0/8
via: 192.168.1.1
- to: 172.16.0.0/12
via: 192.168.1.1
Apply without rebooting:
sudo netplan apply
Persistent Routes: Debian Legacy (/etc/network/interfaces)
On systems without Netplan, routes go into /etc/network/interfaces:
sudo nano /etc/network/interfaces
Add to the relevant interface section:
iface enp2s0 inet dhcp
up ip route add 10.0.0.0/8 via 192.168.1.1
up ip route add 172.16.0.0/12 via 192.168.1.1

up means: run this command when the interface comes up.
Persistent Routes: CentOS / RHEL / Rocky Linux
On Red Hat family systems, routes for each interface live in /etc/sysconfig/network-scripts/route-INTERFACE:
sudo nano /etc/sysconfig/network-scripts/route-eth0
In ip route format:
10.0.0.0/8 via 192.168.1.1
172.16.0.0/12 via 192.168.1.1
Reload:
sudo nmcli connection reload
sudo nmcli connection up eth0
Two ISPs: Policy Routing
If the server has two upstream providers and traffic from different source IPs should exit through different gateways — the standard routing table is not enough. Policy routing requires separate tables per interface.
Add tables to /etc/iproute2/rt_tables:
echo "200 isp1" >> /etc/iproute2/rt_tables
echo "201 isp2" >> /etc/iproute2/rt_tables
Add routes and rules:
sudo ip route add default via 192.168.1.1 table isp1
sudo ip route add default via 10.0.0.1 table isp2
sudo ip rule add from 192.168.1.50 table isp1
sudo ip rule add from 10.0.0.50 table isp2
Traffic from 192.168.1.50 exits through the first provider, from 10.0.0.50 through the second.
Diagnostics: Where Does the Packet Go
Check which gateway a packet to a specific address will use:
ip route get 8.8.8.8
Trace the route with latency at each hop:
traceroute 8.8.8.8
Live tracing with real-time updates:
mtr 8.8.8.8
Quick Reference
| Task | Command |
|---|---|
| View routing table | ip route |
| Full table output | ip route show table all |
| Add default gateway | sudo ip route add default via 192.168.1.1 |
| Add subnet route | sudo ip route add 10.0.0.0/8 via 192.168.1.1 |
| Delete a route | sudo ip route del 10.0.0.0/8 |
| Apply Netplan config | sudo netplan apply |
| Reload NM config | sudo nmcli connection reload |
| Check packet path | ip route get 8.8.8.8 |
| Trace route | traceroute 8.8.8.8 |
| Live trace | mtr 8.8.8.8 |