Skip to content

Linux IP Routing

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Linux IP Routing Guide

Complete beginner-friendly guide to IP routing on Linux, covering Arch Linux, CachyOS, and other distributions including routing tables, static routes, and network routing configuration.


Table of Contents

  1. Routing Tables
  2. Static Routes
  3. Routing Configuration
  4. Troubleshooting

Routing Tables

View Routes

List routes:

# List routes
ip route show

# Or
route -n

# Show routing table
ip route list

# Show default route
ip route show default

What it shows:

  • Destination networks
  • Gateway addresses
  • Interface used
  • Route metrics

Understanding Routes

Route format:

192.168.1.0/24 via 192.168.1.1 dev eth0

Components:

  • 192.168.1.0/24: Destination network
  • via 192.168.1.1: Gateway (router)
  • dev eth0: Network interface

Static Routes

Add Route

Add static route:

# Add route
sudo ip route add 192.168.2.0/24 via 192.168.1.1

# Add with interface
sudo ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0

# Add default route
sudo ip route add default via 192.168.1.1

What it does:

  • Routes traffic for specific network through gateway
  • Useful for multiple networks or VPNs
  • Temporary (lost on reboot)

Delete Route

Remove route:

# Delete route
sudo ip route del 192.168.2.0/24

# Delete default route
sudo ip route del default

Routing Configuration

Persistent Routes

Make permanent (systemd-networkd):

# Create route file
sudo vim /etc/systemd/network/route-eth0

Add:

[Route]
Destination=192.168.2.0/24
Gateway=192.168.1.1

Using NetworkManager:

# Edit connection
nmcli connection edit "Wired connection 1"

# Add route
set ipv4.routes "192.168.2.0/24 192.168.1.1"
save
activate

Route Metrics

Set route priority:

# Add route with metric
sudo ip route add 192.168.2.0/24 via 192.168.1.1 metric 100

# Lower metric = higher priority

Troubleshooting

Routing Issues

Check routing:

# Check routes
ip route show

# Test connectivity
ping -r 192.168.2.1

# Trace route
traceroute 192.168.2.1

# Check gateway
ip route get 192.168.2.1

Default Route Missing

Fix default route:

# Add default route
sudo ip route add default via 192.168.1.1

# Check gateway
ip route show default

Summary

This guide covered IP routing for Arch Linux, CachyOS, and other distributions, including routing tables, static routes, and configuration.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally