Skip to content

Drill: Read and Manipulate the Routing Table

Goal

Use ip route to inspect, query, and manipulate the Linux routing table for network debugging.

Setup

  • Linux system with iproute2 installed
  • Root access for modifying routes

Commands

Show the main routing table:

ip route show

Show the routing table with all details:

ip route show table all | head -30

Find which route a specific destination uses:

ip route get 8.8.8.8
ip route get 10.0.0.5

Show routes for a specific subnet:

ip route show 10.0.0.0/8

Add a static route:

ip route add 192.168.100.0/24 via 10.0.0.1 dev eth0

Add a route with a specific metric:

ip route add 172.16.0.0/16 via 10.0.0.1 metric 200

Delete a route:

ip route del 192.168.100.0/24

Show the default gateway:

ip route show default

Check routing cache/nexthop:

ip -s route show cache

What to Look For

  • ip route get shows the exact route and source IP used for a destination
  • Routes with lower metrics are preferred when multiple paths exist
  • scope link routes are for directly connected networks
  • The default route is the gateway of last resort

Common Mistakes

  • Using route command instead of ip route (route is deprecated)
  • Forgetting that routes added with ip route add are not persistent across reboots
  • Not checking ip route get to verify which route is actually selected
  • Adding routes with wrong source interface, causing asymmetric routing

Cleanup

# Remove any test routes you added
ip route del 192.168.100.0/24 2>/dev/null
ip route del 172.16.0.0/16 2>/dev/null