Two NIC WAN failover
How to configure failover for a WAN connection using two network interface cards (NICs) on a system using Netplan
Netplan can be used to configure failover for a WAN connection using two network interface cards (NICs) on a system. By defining two NICs in your Netplan configuration and using routing policies, you can create a primary connection and a backup connection. When the primary connection fails, traffic can be automatically switched to the backup NIC.
Here's a breakdown of how to set up a failover network with Netplan:
Identify Your NICs: Determine the names of your network interface cards (e.g.,
eth0
,eth1
,wlan0
). You can useip addr
ornmcli
to list active interfaces.Configure Netplan (YAML):
Create a Netplan configuration file (usually in
/etc/netplan/
).Define two ethernet interfaces in the
netplan
file, one for the primary WAN connection and one for the backup WAN connection.Set up static IP addresses or utilize DHCP as needed for each interface.
Use the
routing-policy
section to define the order in which routes are applied. This will determine which NIC is used for traffic when both are available.Set the primary NIC as the primary route with a higher priority, and the backup NIC as a lower priority route.
Apply Netplan Changes: Run
netplan apply
in your terminal to apply the new configuration and restart the network services.Test Failover: Simulate a failure of the primary NIC (e.g., unplug the cable or manually disable the interface) to verify that traffic automatically switches to the backup connection.
Example Netplan YAML Configuration (Simplified):
network:
version: 2
renderer: networkd
ethernets:
eth0: # Primary WAN NIC
dhcp4: yes
dhcp6: no
match:
macaddress: "your-mac-address-here"
routes:
- to: "0.0.0.0/0"
on-link: true
gateway: 192.168.1.1 # Example Gateway
metric: 100 # Higher Metric (Priority)
eth1: # Backup WAN NIC
dhcp4: yes
dhcp6: no
match:
macaddress: "your-mac-address-here"
routes:
- to: "0.0.0.0/0"
on-link: true
gateway: 192.168.2.1 # Example Gateway
metric: 200 # Lower Metric (Priority)
Explanation:
ethernets
: Defines the configuration for Ethernet interfaces.dhcp4
: Sets whether to use DHCP for IPv4 (enable for dynamic IP, disable for static).dhcp6
: Sets whether to use DHCP for IPv6.match
: Used to identify the NIC based on its MAC address.routes
: Defines the routing rules.to
: Specifies the destination network (0.0.0.0/0 represents all networks).on-link
: Indicates whether to use this route on the same subnet.gateway
: The IP address of the gateway.
Last updated