How to Bridge Two Network Interfaces in Linux Using Netplan

Netplan is a utility for easily configuring networking on a Linux system, typically used in Ubuntu. It allows users to configure network interfaces through a simple YAML file.

One common use case is creating a network bridge, which is useful for connecting two or more network interfaces to share a network segment, which is particularly useful in virtualized environments.

In this article, we will discuss how to bridge two interfaces using Netplan, explaining both DHCP and static IP configurations.

Why Bridging Interfaces is Useful

Bridging network interfaces can be highly beneficial in various scenarios:

  • When running virtual machines (VMs), you often need the VMs to communicate with the external network. A bridge allows VMs to appear as if they are physically connected to the same network as the host machine.
  • It allows multiple network interfaces to share a single IP subnet, facilitating easier management and communication within the network.
  • In complex network setups, bridges can simplify configurations and reduce the need for additional routing.

Prerequisites

  • An Ubuntu system with Netplan installed (usually comes by default with newer Ubuntu versions).
  • At least two network interfaces that you want to bridge.

Installing bridge-utils in Ubuntu

To bridge network interfaces, you need to install a bridge-utils package which is used to configure and manage network bridges in Linux-based systems.

sudo apt install bridge-utils
Install Bridge-Utils Package
Install Bridge-Utils Package

Creating a Network Bridge Using DHCP

To configure a network bridge between two or more network interfaces, you need to list your network interface using the following ip command.

List Network Interfaces in Ubuntu
List Network Interfaces in Ubuntu

Once you know the name of your network interfaces, open the Netplan configuration file called ‘01-netcfg.yaml‘ or similar which is typically located in ‘/etc/netplan‘ directory.

sudo nano /etc/netplan/01-netcfg.yaml

Add the following configuration to create a bridge named br0 that bridges two interfaces (enp3s0 and enp4s0) using DHCP.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: no
    enp4s0:
      dhcp4: no
    enp2s0f1:  # Define the interface 'enp2s0f1'
      dhcp4: no
  bridges:
    br0:
      interfaces: [enp3s0, enp2s0f1]  # Correct the interface name
      dhcp4: yes
Configure Network Bridge Using DHCP
Configure Network Bridge Using DHCP

Save the file and apply the Netplan configuration.

sudo netplan apply

This command will apply the new network configuration and bring up the bridge interface br0 with DHCP.

Let’s confirm that our configurations have been updated successfully.

ip a
Confirm Network Bridge
Confirm Network Bridge

Creating a Network Bridge Using Static IP

Similar to the DHCP configuration, you can also configure static IP addresses on the bridge in the same configuration file.

sudo nano /etc/netplan/01-netcfg.yaml

Modify the configuration to assign a static IP to the bridge ‘br0‘.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: no
    enp2s0f1:
      dhcp4: no
  bridges:
    br0:
      dhcp4: no
      addresses: [192.168.122.100/24]
      routes:
        - to: 0.0.0.0/0
          via: 192.168.122.1  # Adjust according to your network configuration
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]  # DNS servers
      interfaces: [enp1s0, enp2s0f1]

Save the file and apply the Netplan configuration:

sudo netplan apply

This will bring up the bridge interface ‘br0‘ with the specified static IP configuration.

ip a
Configure Network Bridge with Static IP
Configure Network Bridge with Static IP
Conclusion

Using Netplan to bridge two network interfaces is a straightforward process that significantly simplifies network management in various scenarios, such as virtualization and complex network setups.

By following the steps outlined above, you can configure a bridge using either DHCP or static IP addresses, depending on your network requirements. Netplan’s simple YAML configuration files make it easy to manage and apply these settings, ensuring that your network setup is both flexible and reliable.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.