Dual NIC WAN failover setup

How to configure failover for a WAN connection using two network interface cards (NICs) on a system that switches back to primary when connection restores

A WAN failover script using systemd automates switching network traffic to a backup/secondary internet connection (WAN) when the primary connection fails. This ensures continuous connectivity and can be implemented by periodically checking the primary connection's status and adjusting routing rules via a systemd service and script.

A script for switching back to the primary WAN after a failover involves detecting the restoration of the primary connection and then directing traffic back to it. This often involves monitoring the primary link's status (e.g., using ping checks) and then modifying routing rules or firewall configurations to ensure traffic flows through the primary interface again.

The setup includes four main steps:

  1. Configure the Netplan inline with the failover script

  2. Create a failover script file wan-failover.sh which switches network traffic to backup/secondary WAN when primary WAN fails and back to primary when connection restores

  3. Deploy the script file wan-failover.sh as systemd service wan-failover.service

  4. Set up systemd timer which Periodically triggers the failover script wan-failover.timer

Last updated