1. Overview

Linux’s robust suite of network management tools provides unparalleled flexibility and control. These tools enable simple and sophisticated network configurations, making Linux an ideal choice for various networking settings. The tools range from user-friendly utilities like netplan and NetworkManager to powerful command-line tools like ip and iptables

In this tutorial, we’ll explore Netplan and how to use it to create network bridges.

2. Netplan

Netplan is a network configuration utility in Linux that provides a simple and consistent way to configure networking using YAML files. It was introduced in Ubuntu 17.10, and it’s also available in other distributions like Debian.

To install Netplan on Debian, let’s run:

$ sudo apt update
$ sudo apt install netplan.io

Netplan uses human-readable YAML files for configuration. This approach is less error-prone and more intuitive compared to traditional methods like ifupdown or manual edits to the /etc/network/interfaces file.

It abstracts traditional network configuration’s complexity by integrating with backend renderers such as systemd-networkd and NetworkManager.

Netplan supports different backend renderers. The two primary renderers are systemd-networkd and NetworkManager, which are typically used in most Debian environments to manage network configurations.

Next, Netplan configuration files are in the /etc/netplan/ directory and typically have a .yaml extension. This configuration file is divided into different sections:

  • network is the top-most level that encapsulates all network settings.
  • version specifies the Netplan version
  • renderer defines the backend, which is the network configuration tool we’re using to set up our network. Often, it’s either networkd or NetworkManager.
  • Other sections are ethernets, wifis, bonds, bridges, and vlans. We use these sections to define the various network interfaces and their settings.

Additionally, Netplan supports advanced configurations like static IP addresses, bonding, bridging, and VLANs.

Whenever we make any changes to the Netplan config file, we need to apply the configuration using sudo netplan apply. This command will read the YAML files in /etc/netplan/, generate the necessary configurations for the specified renderer, and apply the settings.

3. Network Bridging Using Netplan

Bridging two or more network interfaces involves configuring network settings to combine multiple interfaces into a single logical network segment. A bridge acts like a virtual switch, allowing multiple network interfaces to be grouped to form a single network segment. Network Bridge is a link-layer device. It operates at the data link layer (Layer 2) of the OSI model.

In Linux systems, we can use the netplan utility to create network bridges.

Let’s first install the bridge-utils package, which provides all the tools needed to create and manage a bridge network:

$ sudo apt install bridge-utils

Next, let’s check the current IP information:

$ ip a
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:69:1a:17 brd ff:ff:ff:ff:ff:ff
    inet 1.1.1.13/24 brd 1.1.1.255 scope global dynamic noprefixroute enp0s3
       valid_lft 85285sec preferred_lft 85285sec
    inet6 fe80::a00:27ff:fe69:1a17/64 scope link
       valid_lft forever preferred_lft forever

From the snippet above, we can see we currently have one active interface, enp0s3, which obtained its IP address dynamically.

3.1. Creating a Network Bridge Using DHCP

Before making any changes, let’s first view the current Neplan settings:

$ cat /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

The snippet above doesn’t have any major configurations apart from specifying the renderer and the version.

Now, let’s open the Netplan configuration file:

$ sudo vi /etc/netplan/01-network-manager-all.yaml

To add a bridge and make it obtain an IP address dynamically, let’s add the following settings:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: no

  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp0s3

Finally, let’s save the changes and exit the file.

Following this, let’s apply the configuration:

$ sudo netplan apply

From the configuration above, we’ve specified the Netplan version we’re using (2). Following this, we’ve set up the renderer to Network Manager and selected the interface we intend to use (enp0s3), and its DHCP we’ve turned off as the bridge will manage it. Next, we’ve defined the bridge (br0) and enabled its DHCP.

Let’s verify that our configurations have been updated successfully:

$ ip a
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether 08:00:27:69:1a:17 brd ff:ff:ff:ff:ff:ff
4: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 92:76:79:c1:b5:c0 brd ff:ff:ff:ff:ff:ff
    inet 1.1.1.20/24 brd 1.1.1.255 scope global noprefixroute br0
       valid_lft forever preferred_lft forever

3.2. Creating a Network Bridge Using a Static IP

Alternatively, we can configure static IP addresses on the bridge.

First, let’s edit the Netplan configuration file and add the following configurations:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: no
  bridges:
    br0:
      dhcp4: no
      interfaces:
        - enp0s3
      addresses:
        - 192.168.137.100/24
      nameservers:
         search: []
         addresses: [8.8.8.8,1.1.1.1]
      routes:
         - to: default
           via: 192.168.137.1

In this section, we’ve configured our bridge to get its address manually. On the bridge interface, we’ve explicitly set the IP address to 192.168.137.20/24. Following this, we’ve set the default gateway for the bridge and added the DNS server (8.8.8.8). The interface option lists the interfaces that are part of the bridge.

Let’s verify if the IP address has been updated:

$ ip a
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether 08:00:27:69:1a:17 brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 92:76:79:c1:b5:c0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.137.150/24 brd 192.168.137.255 scope global noprefixroute br0
       valid_lft forever preferred_lft forever
    inet6 fe80::9076:79ff:fec1:b5c0/64 scope link
       valid_lft forever preferred_lft forever

Also, let’s confirm our bridge can access the internet:

$ ping 8.8.8.8 -c2
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=113 time=8.67 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=113 time=8.78 ms (DUP!)
64 bytes from 8.8.8.8: icmp_seq=2 ttl=113 time=39.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=113 time=39.5 ms (DUP!)

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, +2 duplicates, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 8.673/17.189/39.489/12.104 ms

Lastly, if we intend to bridge two or multiple interfaces, we need to make our configurations like this:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s4:
      dhcp4: no
    enp0s5:
      dhcp4: no
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp0s4
        - enp0s5

4. Conclusion

In this article, we’ve looked at Netplan and how we can use it to configure bridges. Netplan simplifies network configuration by using YAML for its definitions, and it integrates with backend renderers. Lastly, while using YAML to make our configurations, we should be wary of the indentation. Having the wrong indentation can cause our file to not work.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments