Marcio Cunha

How to set up automatic network failover in systemd-networkd

Learn how to configure network redundancy and automatic failover on Linux servers using systemd-networkd, ensuring high availability without complex tools.

Marcio Cunha•3 min
Also available in:PortuguêsEspañol
Summary
  • The systemd-networkd utility manages network configurations natively and efficiently across modern Linux distributions.
  • Network failover allows the system to automatically switch to a backup interface if the primary one fails.
  • Route metrics and gateway priorities determine which network path data packets should follow.
  • Physical testing and hardware validations help isolate cable or switch issues before blaming software.
  • Continuous connection monitoring prevents prolonged downtime in demanding production environments.

Why network failover is vital for production servers

Keeping a server connected to the network or the internet is the backbone of any corporate infrastructure. In practice, this means that if a network cable breaks or the primary interface burns out, the system must keep running without human intervention. To achieve this resilience on Linux servers, we use failover, which is the ability to shift data traffic to a backup route or interface immediately and transparently. Before tinkering with complex code, it helps to understand how to diagnose physical faults, such as learning how to test the Realtek network chip with a multimeter to rule out hardware defects. The systemd-networkd tool, built right into systemd on almost all modern distros, offers robust features to handle this redundancy without requiring heavy installations.

Understanding the role of systemd-networkd in redundancy

The systemd-networkd daemon is the standard connection manager in many enterprise environments because it is fast, lightweight, and integrated into the operating system ecosystem. It reads simple text-based configuration files to define IP addresses, gateways, and static routes. In practice, setting up redundancy with it involves creating numeric priorities for different network routes, called metrics. The lower the metric number, the higher the priority of the network interface. If the primary interface loses signal or fails, the operating system checks the routing table and automatically reroutes data flow to the secondary interface configured with a higher metric.

Preparing the interface configuration files

To get started, the first step is to create specific configuration files for each physical network card on your server. These files reside in the /etc/systemd/network/ directory. Let us set up two connections, referred to here as eth0 (primary) and eth1 (secondary). Open your favorite text editor and create the main interface file with the following code:

[Match]
Name=eth0

[Network]
Address=192.168.1.10/24
Gateway=192.168.1.1
DNS=8.8.8.8
Metric=10

Notice that we set a low metric (Metric=10) for the eth0 interface, indicating it is the preferred path. The metric acts like a priority queue where packets always choose the lowest numerical path available.

Configuring the backup secondary interface

Now we need to configure the contingency interface, eth1, which will take over traffic if the primary goes down. Create a second configuration file in the same directory with a numerically higher metric, such as 20. This ensures the system only looks at this interface if the first one stops responding. Here is how the backup configuration file should look:

[Match]
Name=eth1

[Network]
Address=192.168.1.11/24
Gateway=192.168.1.1
DNS=8.8.8.8
Metric=20

With this tiered metric structure (10 for primary and 20 for backup), systemd-networkd automatically builds the Linux kernel routing table. To audit whether the system applied the rules correctly and check how connections are distributed, you can use the ss command on Linux to audit network connections in real time and confirm interface behavior.

Applying changes and testing failover

After saving the configuration files, you need to restart the network service so systemd-networkd processes the new rules. To avoid dropping active SSH sessions abruptly, execute the restart commands carefully and validate the status immediately afterward. Use the command sequence below to apply and verify the network state:

  1. Restart the systemd-networkd service to apply the new configuration files.
    sudo systemctl restart systemd-networkd
  2. Check the current status of network interfaces and active connections.
    networkctl status
  3. Test the active route by sending continuous pings to the gateway.
    ping -c 4 192.168.1.1

To test whether failover actually works in practice, you can simulate a failure by unplugging the cable from eth0 or disabling it via software using the command 'sudo ip link set eth0 down'. Watch the terminal behavior to see if traffic migrates smoothly to the eth1 card without dropping critical services.

Final thoughts on production redundancy

Configuring automatic failover using native tools like systemd-networkd removes the need for complex external software, making infrastructure leaner and easier to audit. The key to success with this approach lies in proper planning of route metrics and performing periodic simulated failover tests in a controlled environment. Keeping the network layer simple reduces hidden failure points and ensures your server remains resilient even in the face of unexpected hardware physical issues.