Netplan Configuration

Netplan configuration for dual WAN failover

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:

  1. Identify Your NICs: Determine the names of your network interface cards (e.g., eth0, eth1, wlan0). You can use ip addr or nmcli to list active interfaces.

  2. 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.

  3. Apply Netplan Changes: Run netplan apply in your terminal to apply the new configuration and restart the network services.

  4. 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:
    enp0s3:
      dhcp4: yes
      routes:
        - to: default
          via: 192.168.1.1  # Replace with your gateway
          metric: 100
    enp0s8:
      dhcp4: yes
      routes:
        - to: default
          via: 192.168.2.1  # Replace with your gateway
          metric: 200

Explanation:

  • network:: Top-level Netplan configuration.

  • version: 2: Specifies the Netplan version.

  • renderer: networkd: Uses systemd-networkd as the backend.

  • ethernets:: Defines configurations for Ethernet interfaces.

  • enp0s3: and enp0s8:: Replace with your actual interface names.

  • dhcp4: yes: Enables DHCP on both interfaces.

  • routes:: Defines routing rules.

    • to: default: Specifies the default route (0.0.0.0/0).

    • via:: Specifies the gateway IP address. Important: Replace the example gateway IPs with your actual gateway addresses.

    • metric:: Sets the routing metric (lower is better). Lower metric has high priority.

Example Netplan YAML Configuration (no gateway):

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 100
    enp0s8:
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 200

Last updated