• Contact
  • About Me
  • Privacy Policy
DefenceDev
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos
No Result
View All Result
DefenceDev
No Result
View All Result
ADVERTISEMENT
Home Linux Tutorials Networking

Linux Networking: Add Multiple Network Gateways (Redundancy) on Ubuntu with netplan

neo by neo
May 27, 2025
in Networking
0
Linux Networking: Add Multiple Network Gateways (Redundancy) on Ubuntu with netplan

Linux Networking: Add Multiple Network Gateways (Redundancy) on Ubuntu with netplan

0
SHARES
102
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

Linux Networking: Add Multiple Gateways with netplan

Configuring multiple gateways is an essential networking task when managing multi-homed servers or creating redundant connections in Linux or any other environment. Netplan, a modern network configuration tool, simplifies this process with its YAML-based syntax.

Introduciton

Netplan is a simple and effective utility used to configure networking on modern Ubuntu systems. It helps manage interfaces using YAML configuration files and integrates seamlessly with backends such as systemd-networkd or NetworkManager.

Purpose of this Configuration

Add multiple network gateways (redundancy) on Ubuntu with netplan (Backup Gateway in the Same Network) provides essential network redundancy and failover capabilities crucial for maintaining connectivity in diverse networking environments. This guide explores how to set up and manage primary and backup gateways within the same network using Netplan, ensuring reliable network access and seamless failover when encountering connectivity issues.

More about netplan you can find at the link.

Netplan Configuration to Add Multiple Network Gateways

Netplan configuration file is located under the folder: /etc/netplan To list the content of the /etc/netplan folder type the following:

ls /etc/netplan

To edit the file type, the following:

sudo nano 00-installer-config.yaml

Content of the file:

network:
    renderer: networkd
    version: 2
    ethernets:
        eth0:
            dhcp4: false
            addresses: [192.168.19.189/24]
            gateway4: 192.168.19.252
            optional: true
            nameservers:
                addresses: [192.168.19.11, 8.8.8.8]
            #routes:
             - to: 0.0.0.0/0
               via: 192.168.19.252  # Primary gateway IP
               metric: 100  # Lower metric means higher priority
               on-link: yes
             - to: 0.0.0.0/0
               via: 192.168.19.1  # Backup gateway IP
               metric: 1000  # Higher metric means lower priority
               on-link: yes

This configuration directs all traffic (0.0.0.0/0) through the primary gateway 192.168.19.252 with a lower metric (higher priority).

Explanation of the Configuration

Top-Level Keys

  1. network
    • This key marks the beginning of the network configuration block.
  2. renderer: networkd
    • Specifies the backend responsible for managing the network settings. Here, systemd-networkd is used.
  3. version: 2
    • Defines the Netplan schema version.

Configuring Ethernet Interfaces

This section configures the network interface eth0:

  • dhcp4: false
    • Disables DHCP, indicating that a static IP configuration will be used.
  • addresses
    • Specifies the IP address in CIDR notation. 192.168.19.189/24 corresponds to an IP of 192.168.19.189 and a subnet mask of 255.255.255.0.
  • gateway4
    • Defines the primary IPv4 gateway, here set to 192.168.19.252.
  • optional: true
    • Marks this interface as optional. If it does not initialize successfully, the system will still boot without waiting indefinitely.
  • nameservers
    • Defines DNS servers for name resolution. In this example:
      • 192.168.19.11 could be a local DNS server.
      • 8.8.8.8 is Google’s public DNS.

Adding Static Routes

The routes section, which is commented out in the provided configuration, allows for more granular control over routing traffic:

  1. Primary Route
    • to: 0.0.0.0/0
      • The default route, directing traffic destined for any IP through the primary gateway.
    • via: 192.168.19.252
      • Sets the gateway as 192.168.19.252 for this route.
    • metric: 100
      • Specifies the priority of the route. A lower metric means higher priority.
    • on-link: yes
      • Indicates that the gateway is reachable directly on the link, even without ARP resolution.
  2. Backup Route
    • to: 0.0.0.0/0
      • Another default route for all traffic.
    • via: 192.168.19.1
      • Sets the backup gateway.
    • metric: 1000
      • Higher metric assigns lower priority. The backup gateway is used only if the primary route becomes unavailable.
    • on-link: yes
      • Similarly ensures that the backup gateway is reachable on the link.

Behavior of the Configuration

  1. The interface eth0 is assigned a static IP of 192.168.19.189 with a primary gateway (192.168.19.252) and a DNS resolver setup.
  2. The system will prioritize routing traffic through the primary gateway. If 192.168.19.252 becomes unreachable, the backup gateway 192.168.19.1 will take over, thanks to the route metrics.
  3. Uncommenting the routes section enables automatic route management for gateway redundancy.

Test and Apply netplan Configuration

Once you have updated your Netplan configuration file, you can test and apply the changes using the following commands:

ADVERTISEMENT

Test the Configuration

netplan try -timeout 120 

This command applies the new configuration temporarily, allowing you to verify that it works as intended. If there are issues, the system will revert to the previous settings automatically after 120 seconds.

Apply the Configuration

# Apply network configuration
netplan apply

Use this command to make the configuration changes permanent. Ensure you have tested the settings before applying them.

ADVERTISEMENT
ADVERTISEMENT

Other topics related to the netplan:

  • Linux Networking: Add VLAN on Ubuntu with netplan
  • Linux Networking: netplan DHCP Configuration on Ubuntu
  • Linux Networking: netplan Network Configuration on Ubuntu

About The Author

neo

See author's posts

ADVERTISEMENT
Previous Post

Linux Networking: ifconfig, Managing Network Interfaces on Ubuntu

Next Post

Linux Files Operation: find Temp Files and Execute Commands on Found Files

neo

neo

Next Post
Linux Files Operation: find Temp Files and Execute Commands on Found Files

Linux Files Operation: find Temp Files and Execute Commands on Found Files

Follow Us

  • Trending
  • Comments
  • Latest
MikroTik: Export Configuration in Text File

MikroTik: Export Configuration in Text File

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Fortinet FortiGate: Static Route Configuration via GUI and CLI

Immich: Installation on Ubuntu 22.04

Immich: Installation on Ubuntu 22.04

Fortinet FortiGate Upgrade Path Tool

Fortinet FortiGate Upgrade Path Tool

NextCloud: Port Forwarding - Essential Ports for Smooth Functionality

NextCloud: Port Forwarding – Essential Ports for Smooth Functionality and Remote Access

Organizing and Managing Photos with Immich: Features I Use

Organizing and Managing Photos with Immich: Features I Use

Install Ubuntu 22.04 on Oracle VM Virtual Box

Install Ubuntu 22.04 on Oracle VM Virtual Box

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Linux Directories: cd (Change Directory), pwd (Print Working Directory), mkdir (Make Directory)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nginx Proxy Manager on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

Install Docker on Raspberry Pi 4 with Ubuntu 22.04

MikroTik: Check Your Wireless Password

MikroTik: Check Your Wireless Password

ADVERTISEMENT

DefenceDev Tutorials

defencedev Logo

Whether you’re just starting or looking to expand your skills, I hope you find useful information and engaging discussions here. Let me take you through my journey and the goals behind this space!

Follow Us

Browse by Category

  • Blog
  • Cloud
    • Private
  • Linux Tutorials
    • Bash Scripting Tutorials
    • Commands
    • Networking
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Solutions
    • Docker
  • Video Tutorials
    • MikroTik Videos

Recent News

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install WordPress on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

Install Nextcloud on Raspberry Pi 4 with Docker (Ubuntu 22.04)

  • Site Map
  • Privacy Policy
  • Facebook Page
  • Disclaimer
  • Contact
  • About Me

© 2025 defencedev.com - All rights reserved.

No Result
View All Result
  • Home
  • Blog
  • Linux Tutorials
    • Bash Scripting Lessons
    • Commands
    • Networking
  • Solutions
    • Docker
  • Network Tutorials
    • FortiGate
    • MikroTik
  • Projects
    • AdGuard
    • Immich
    • Nextcloud
    • WordPress
  • Cloud
  • Video Tutorials
    • YouTube Channel
    • MikroTik Videos

© 2025 defencedev.com - All rights reserved.