Marcio Cunha

Implementation of WireGuard Tunnels with Policy-Based Routing for Link Failover in Distributed Industrial Environments

Learn how to build a resilient industrial network combining WireGuard tunnels and policy-based routing to ensure continuous operation during connectivity failures.

Marcio Cunha•4 min
Also available in:PortuguêsEspañol
Summary
  • Link redundancy in industrial environments prevents catastrophic production shutdowns when the primary internet connection fails.
  • WireGuard provides low processing overhead and highly efficient encrypted connections for distributed scenarios.
  • Policy-based routing directs traffic intelligently based on destination and origin, overcoming traditional route limitations.
  • Packet loss and latency fluctuate dramatically in industrial cellular networks, demanding active health monitoring.
  • Automating route switching via checking scripts eliminates manual intervention and reduces plant downtime.

The Connectivity Challenge in Distributed Industrial Plants

Keeping automation systems connected in remote areas is one of the greatest challenges for network engineering. Often, the only available option involves satellite internet links or cellular networks that suffer from constant instability. When a PLC, which is the control computer responsible for driving motors and valves on an assembly line, loses contact with the central server, the entire production stops. In practice, this means massive financial losses and serious operational risks that demand highly resilient network architectures.

To overcome this fragility, the industry adopts the concept of failover, meaning the automatic ability to switch data traffic to a secondary route when the primary one drops. However, traditional routing based solely on the packet destination cannot handle multiple active links intelligently. It is necessary to look beyond the destination IP and examine who is sending the data and what the priority of that critical traffic is. It is precisely in this complex scenario that the combination of encrypted virtual tunnels with advanced packet forwarding rules comes into play.

Architecture and Fundamentals of WireGuard in Critical Networks

WireGuard revolutionized the way we create virtual private networks by drastically simplifying encryption and eliminating the complexity of legacy protocols. Simply put, it creates a secure tunnel between two points across the internet, wrapping the data so no one can intercept it. Unlike heavier traditional solutions, it consumes very little processing power, making it ideal for low-cost industrial routers installed in cramped electrical panels without forced ventilation.

In a distributed topology, each factory unit or remote station establishes a permanent WireGuard tunnel with the corporate data center. The major differentiator lies in how traffic is encapsulated, allowing telemetry packets and critical commands to travel identically regardless of the underlying physical infrastructure. In practice, this means the industrial application sees a perfectly stable local network, even if the external radio signal fluctuates constantly.

Policy-Based Routing for Multi-Link Management

Conventional routing makes decisions looking only at the IP address where the packet wants to go, completely ignoring which internet connection is performing best at the moment. Policy-based routing, known by the acronym PBR, breaks this rule by allowing administrators to define custom rules. In practice, it decides that packets coming from a specific factory subnet must go out through the primary fiber optic link, while data from less urgent sensors uses the satellite or 4G backup link.

When we combine this flexibility with WireGuard, we can create multiple tunnel instances—one over fiber and another over the cellular network. The industrial router's operating system continuously evaluates which tunnel is responding better through latency and packet loss tests. If the fiber optic suffers a physical interruption in the street, the routing rules are recalculated instantly, diverting the flow from the primary tunnel to the backup tunnel without the operator noticing the interruption.

Practical Implementation and Network Configuration

Practical implementation requires careful configuration of Linux kernel routing tables present in industrial gateways. The first step involves defining custom routing tables for each operator or physical link available at the remote plant. Next, we associate the policy rules using native system tools to ensure traffic is correctly directed to the WireGuard tunnel interfaces.

ip route add default dev wg-fiber table 100
ip rule add from 192.168.10.0/24 table 100
ip route add default dev wg-cellular table 200
ip rule add from 192.168.20.0/24 table 200

In the example above, we created two distinct routing tables identified by numbers 100 and 200. The first table directs internal network traffic to the WireGuard tunnel over fiber, while the second directs it to the cellular tunnel. The monitoring script comes into play by checking the health of these links and adjusting rule priorities if a failure occurs in any of the communication circuits.

Health Monitoring and Failover Automation

A VPN tunnel may look active to the operating system even when the real internet connection is completely degraded. To prevent false positives, we implement monitoring scripts known as ping checkers or active probes. These small programs send test packets at regular intervals to reliable IP addresses in the corporate cloud, measuring response time and packet loss rate in real time.

In practice, if the script detects more than three consecutive packet losses on the primary link, it triggers an action that changes the priority of the routing rules. Industrial traffic is immediately redirected to the secondary tunnel, keeping PLCs and HMIs connected to the supervisory system. When the primary link recovers and stabilizes for a minimum safety period, the system reverses the process, returning the data flow to the original route without causing abrupt session drops.

Final Considerations on Industrial Network Resilience

The joint adoption of WireGuard tunnels and policy-based routing represents a qualitative leap in network engineering for harsh industrial environments. By decentralizing decision intelligence and automating route switching, companies eliminate single points of failure and drastically reduce on-site maintenance costs. In short, investing in a robust and flexible communication infrastructure ensures business continuity and protects operations against the unpredictability of external telecommunications infrastructure.