Understanding Linux Local Routing Table: Purpose, Configuration and Practical Use Cases


2 views

The local routing table (table local) is a special routing table in Linux that maintains information about all IP addresses that belong to the local system. Unlike the main routing table which handles forwarding decisions, the local table identifies which addresses are locally owned.

# View local routing table
ip route show table local
  • Managed automatically by the kernel when interfaces come up/down
  • Contains all local IPs (including loopback)
  • Handles broadcast and multicast addresses
  • Takes precedence over other routing tables

The local table serves critical functions:

# Example of automatic entries
local 192.168.1.100 dev eth0 proto kernel scope host src 192.168.1.100
broadcast 192.168.1.255 dev eth0 proto kernel scope link src 192.168.1.100

Without this table, the system couldn't distinguish between:

  1. Addresses that should be processed locally
  2. Addresses that should be forwarded

1. Testing Network Stack

Adding dummy local routes helps test networking without actual interfaces:

# Add test route
sudo ip route add to local 192.168.99.99 dev eth0

# Verify ping works
ping 192.168.99.99 -c 3

2. Virtual IP Management

When working with VIPs in clustering:

# Add VIP
sudo ip addr add 192.168.100.100/32 dev eth0
sudo ip route add to local 192.168.100.100 dev eth0

3. Network Namespace Isolation

In container environments, the local table helps isolate network stacks:

# Create namespace
sudo ip netns add testns

# Add interface
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth1 netns testns

# Configure local routing
sudo ip netns exec testns ip route add local 10.0.0.1 dev lo
  • Use ip route get 192.168.1.1 to see which table handles a route
  • Check /proc/net/fib_trie for detailed local address info
  • Remember local table entries can't be routed through

The local routing table (table ID 255) is a special routing table in Linux that contains routes to locally hosted IP addresses. Unlike the main routing table, it specifically handles:

  • IP addresses assigned to local interfaces
  • Broadcast addresses
  • Locally originated traffic
  • Special purpose addresses (like 127.0.0.0/8)

When you added 192.168.22.22 to the local table, you essentially told the kernel to treat this IP as belonging to the system, even though no interface is actually configured with it:

# Adding entry to local routing table
sudo ip route add to local 192.168.22.22 dev wlp2s0

# Verify the entry
ip route show table local | grep 192.168.22.22

While your example demonstrates the basic behavior, here are more practical scenarios where manipulating the local table is useful:

1. Virtual IP Simulation:

# Create a virtual IP for testing services
sudo ip route add to local 10.0.0.100 dev eth0

# Test connectivity without actual interface configuration
ping -c 3 10.0.0.100

2. Network Namespace Isolation:

# Create network namespace
sudo ip netns add testns

# Add local route in namespace
sudo ip netns exec testns ip route add local 172.16.0.1 dev lo

The local table operates at a lower level than standard routing. When you ping an address in the local table:

  1. The kernel checks the local table before consulting the main routing table
  2. For matching entries, it considers the IP as locally owned
  3. Traffic is looped back internally without requiring ARP resolution

Here's how to permanently add entries to the local table that persist across reboots:

# Add to /etc/network/interfaces (Debian)
post-up ip route add local 192.168.33.33 dev eth0

# Or create /etc/sysconfig/network-scripts/route-eth0 (RHEL)
local 192.168.33.33 dev eth0

If your local route isn't working as expected:

# Check if rp_filter is interfering
sysctl net.ipv4.conf.all.rp_filter

# Verify reverse path filtering
ip route get 192.168.22.22

# Check kernel logs for route issues
dmesg | grep -i route

Remember that while this technique is useful for testing, production environments should use proper interface configuration for persistent IP assignments.