Ubuntu

How to use bridge-utils on Ubuntu

A bridge in a network plays an important role in transmitting the data from one LAN (local area network) to the other. The two ethernet ports are used to transfer the data which uses the ethernet address rather than the IP(internet protocol) addresses. The bridge uses both layers; the physical as well as the data layer and because of these layers data transfers smoothly and privacy is guaranteed. Now the tools which are a part of bridge or which help bridge to communicate with the devices are known as bridge utilities and in Ubuntu there is a package we install for the bridge.

In this guide we are focussing on the use of bridge utils on ubuntu. We will discuss the installation of this package on Ubuntu and will also learn how this package will be utilized in Ubuntu.

How to use bridge-utils on Ubuntu

Before understanding the use of the bridge-utils we will open the repository, will update as well as upgrade the repository and then we will install the bridge-utils.

For the updating of the repository we will use the following command.

$ sudo apt update

In this step we will update the repository by:

$ sudo apt upgrade

Finally we will install the bridge utils in the Ubuntu:

$ sudo apt install bridge-utils

For the identification of the ethernet device interface name we use the following command:

$ sudo ip add

Here the interface name of our ethernet device is enp0s3. Here “en” represents ethernet, “p0” represents the ethernet card number and “s3” represents the slot number.

Now to understand the use of bridge-utils, we will create a bridge in Ubuntu using bridge-utils.

How to create network bridge using nmcli command

The nmcli is a command line utility to manage the network manager. We can modify, delete, add or activate the network devices by using the nmcli command. A bridge, named br0 is created by the command:

$ sudo nmcli conn add type bridge con-name br0 ifname br0

Addition of the ethernet bridge in the bridge by the following command but you have to change the ethernet name of the device which you noted above and replace in the command:

$ sudo nmcli conn add type ethernet slave-type bridge con-name bridge-br0 ifname enp0s3 master b0

To show the newly created bridge:

$ sudo nmcli conn show --active

We can see in the output that a bridge with a name of “br0” has been created. Now we will activate the newly created bridge as:

$ sudo nmcli conn up br0

So in this way we can make and activate the bridge.

How to create network bridge using brctl command

We can create a bridge by using the brctl command. To do this first we will open the terminal and update the repository by using the following command:

$ sudo apt update

Now we will check the networks we have already by using the “ip link” command:

$ ip link

We will also note the interface name of the ethernet device. Now we will install the bridge utilities which we need for the creation of the bridge:

$ sudo apt install bridge-utils

After the installation of the bridge utilities, we will add a bridge using brctl command with the name “cr0” but you can use some other name of your choice too.

$ sudo brctl addbr cr0

Now we will add the bridge interface to the default interface as:

$ sudo brctl addif cr0 enp0s3

Now for the configuration of the newly created bridge we will create the file /etc/network/interface by using nano command:

$ nano /etc/network/interfaces

Copy and paste the following text to the editor. Write the ip address, gateway and networks address of your own which are of your machine and network.

auto cr0

iface cr0 inet static

bridge -ports enp0s3

address 192.168.18.152

network 255.255.255.0

gateway 192.168.5.1

To confirm whether the bridge cr0 has been created or not we will run the command:

$ sudo ip add

We can note that the cr0 bridge has been created.

Conclusion

A bridge is used for connecting two things with each other, the bridge we discussed in this guide is used for connecting two LANS with each other. It is used to communicate the data with each other. This guide is helpful in understanding what is the purpose of bridge and how we can use bridge-utils command for the creation of the bridge. We created a bridge by two methods; one is by using nmcli command and the other one is by using brctl command. We also verified the creation of the bridges by using the “ip add” command. Bridges are used in creating the network in which different computers are connected to the one computer by means of the bridges. We hope this post not only resolves the issues regarding the creation of the bridges but also helps to understand the bridge utilities.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.