Course contentsShow
← Linux
Lesson 1223 of 1,81910. Network Administration and Kernel StacksFree lesson

Managing Persistent Routing Policies

Ensure routing configuration survives system reboots and dynamic interface events.

In this lesson, you will learn how to configure network routes so they remain active after a system reboot or when network interfaces are toggled.

The Problem of Ephemerality

When you add a route using the standard ip route add command, you are modifying the kernel's routing table directly in memory. While this provides immediate connectivity, it is volatile; if your server reboots or the network service restarts, these manual configurations are flushed. In production environments, especially when dealing with complex multi-homed setups or cloud-native instances, manual configuration is unsustainable.

Persistent Configurations via Netplan or Ifcfg

To ensure your routing policy persists, you must define it in the configuration files managed by your distribution’s network daemon (typically systemd-networkd or NetworkManager).

If you are using Netplan (common on Ubuntu/Debian), you define routes within your YAML configuration file. This ensures that every time the system initializes the network stack, it parses these rules and applies them consistently:

network:
  version: 2
  ethernets:
    eth0:
      addresses: [192.168.1.10/24]
      routes:
        - to: 10.0.0.0/8
          via: 192.168.1.1
          metric: 100

Handling Dynamic Interface Events

Static configuration files are excellent for "bootstrap" routes, but what happens when an interface is hot-plugged or a dynamic link (like a VPN tunnel) initializes?

If your routes depend on an interface coming "up," you should use dispatcher scripts. In NetworkManager, you can place a script in /etc/NetworkManager/dispatcher.d/. These scripts trigger whenever an interface state changes, allowing you to run ip route commands precisely when the underlying link is ready. This prevents "Network is unreachable" errors that occur when a script tries to add a route before the interface has acquired an IP address.

By shifting from manual ip commands to declarative configuration files and event-driven dispatcher hooks, you create a self-healing network environment that respects the lifecycle of your hardware and virtual interfaces.

Key Takeaway: Never rely on manual ip route commands for production; always define routes in your distribution’s persistent configuration files or trigger them via network dispatchers to ensure survival across reboots and link resets.