ReGex's profile picture

Adding Failover Network Configuration in Ubuntu with Netplan

To set up a failover network configuration in Ubuntu using Netplan, you'll need to configure multiple network interfaces with different priority levels. Here's how to do it:

## Basic Failover Configuration

1. First, identify your network interfaces:
  ```bash
  ip a
  ```

2. Create or edit your Netplan configuration file (typically located in `/etc/netplan/`):
  ```bash
  sudo nano /etc/netplan/01-netcfg.yaml
  ```

3. Here's a basic failover configuration example:

```yaml
network:
 version: 2
 renderer: networkd
 ethernets:
   eth0:
     dhcp4: true
     dhcp4-overrides:
       route-metric: 100
     optional: true
   eth1:
     dhcp4: true
     dhcp4-overrides:
       route-metric: 200
     optional: true
```

In this example:
- `eth0` is the primary interface (lower metric = higher priority)
- `eth1` is the secondary interface (higher metric = lower priority)
- Both interfaces are marked as `optional` so the system boots even if they're not connected

## Static IP Failover Configuration

For static IP addresses:

```yaml
network:
 version: 2
 renderer: networkd
 ethernets:
   eth0:
     addresses: [192.168.1.10/24]
     routes:
       - to: default
         via: 192.168.1.1
         metric: 100
     nameservers:
       addresses: [8.8.8.8, 8.8.4.4]
     optional: true
   eth1:
     addresses: [192.168.2.10/24]
     routes:
       - to: default
         via: 192.168.2.1
         metric: 200
     nameservers:
       addresses: [8.8.8.8, 8.8.4.4]
     optional: true
```

## Applying the Configuration

1. Test your configuration:
  ```bash
  sudo netplan try
  ```
  (Press ENTER to accept the configuration after testing)

2. Apply the configuration:
  ```bash
  sudo netplan apply
  ```

## Verifying the Configuration

Check the routing table to verify the failover setup:
```bash
ip route show
```

You should see the default route with different metrics for each interface.

## Advanced Options

For more control, you can add health checks using networkd's routing policy:

```yaml
network:
 version: 2
 renderer: networkd
 ethernets:
   eth0:
     dhcp4: true
     routes:
       - to: 0.0.0.0/0
         via: 192.168.1.1
         metric: 100
         on-link: true
     routing-policy:
       - from: 192.168.1.0/24
         table: 101
     optional: true
   eth1:
     dhcp4: true
     routes:
       - to: 0.0.0.0/0
         via: 192.168.2.1
         metric: 200
         on-link: true
     routing-policy:
       - from: 192.168.2.0/24
         table: 102
     optional: true
```

Remember to adjust interface names, IP addresses, and gateways to match your network environment.

0 comments

Comments (0)

Login to post a comment