Alright, let’s get our hands dirty with the routing table. Think of it as your computer’s internal map of the internet. When you want to send a packet to 8.8.8.8, your machine doesn’t just chuck it out the nearest door and hope for the best. It consults this map—the routing table—to find the best path. The ip route command is how you read and, crucially, redraw that map.

Without any arguments, ip route or ip route show spills the beans on your current map. Let’s see what a typical one looks like.

$ ip route
default via 192.168.1.1 dev wlan0 proto dhcp metric 600
10.8.0.0/24 via 10.8.0.2 dev tun0
10.8.0.2 dev tun0 proto kernel scope link src 10.8.0.1
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.37 metric 600

Let’s break this down. You read this table from top to bottom, and the kernel does the same, using the first matching route it finds.

The Anatomy of a Route

Each line is a rule with a simple logic: “To send a packet to this network, use this device and (optionally) send it via this gateway.”

  • default via 192.168.1.1 dev wlan0: This is your catch-all, your “and everywhere else” route. Any packet destined for a network not listed below gets sent to the gateway (192.168.1.1, likely your home router) out of your wireless interface (wlan0). The metric 600 is a cost score; lower is better. The kernel uses this to choose between identical routes, which is rare on a single machine but vital for routers.
  • 10.8.0.0/24 via 10.8.0.2 dev tun0: This is a static route for a VPN. It says, “To reach the network 10.8.0.0/24, send the packets to the gateway 10.8.0.2 via the tun0 interface.” The via keyword is your telltale sign you’re dealing with a gateway.
  • 192.168.1.0/24 dev wlan0: This is a directly connected network. It says, “The entire 192.168.1.0/24 network is directly reachable on the wlan0 interface. No gateway needed; I can just yell these packets onto the local network.” The src 192.168.1.37 tells the kernel which of its IP addresses on that interface to use as the source address for packets matching this route.

Adding and Deleting Routes

Reading the map is one thing; changing it is where the real power lies. You’ll use ip route add and ip route del.

Let’s say you have a second router at 192.168.1.254 that’s the only way to reach a legacy network at 172.16.100.0/24. You’d add a specific route for it:

$ sudo ip route add 172.16.100.0/24 via 192.168.1.254 dev wlan0

Verify it’s there:

$ ip route get 172.16.100.50
172.16.100.50 via 192.168.1.254 dev wlan0 src 192.168.1.37 uid 1000
    cache

Notice I used ip route get—this is your best friend for testing. It shows you the exact route a packet to a specific address would take without actually sending one. Brilliant for debugging.

Now, let’s say you disconnect from that VPN, but the route is still there, now pointing into the void. You need to clean it up:

$ sudo ip route del 10.8.0.0/24

A common pitfall? Forgetting that del needs to exactly match the route you want to remove. Typing sudo ip route del 10.8.0.0/24 is correct; sudo ip route del 10.8.0.0 will fail miserably because the prefix length (/24) is a key part of the route’s definition. The kernel is pedantic, and rightly so.

The Quirks and The Gotchas

Here’s the thing the dry manuals won’t tell you: routes are not persistent. Rebooting your machine will vaporize all the beautiful, intricate routes you just added. This is the biggest “oh crap” moment for newcomers. To make them stick, you need to put them in a network configuration file, which is a distro-specific nightmare of its own (look at /etc/network/interfaces on Debian, netplan on Ubuntu, or systemd-networkd everywhere eventually).

Another classic blunder is adding a route that makes your SSH session instantly die. If you’re connected to a server remotely and you add a new default route, you’ve just redirected all your traffic, including the packets for your current connection, to a new path that probably doesn’t lead back to you. The result? A silent, heartbreaking timeout. Always use ip route get to sanity-check before you add.

The routing table is the fundamental mechanism that makes networking work. It’s not magic, just a very detailed, logical set of instructions. Mastering ip route is your first step toward thinking like a router, and that’s a superpower worth having.