How to create and manage Bridge Interface in Ubuntu

To create and manage Bridge Interface in Ubuntu

Bridge Interface is a software used to unite more than one LAN segments in Layer-2. It is used to filter and reduce network traffic between many LAN segments. The users can set up a software bridge that interconnects multiple network interfaces. Bridge interface service in Ubuntu is explained in this article.

Creation of Bridge Interface

First check the network interfaces by using the " ip link" command.

root@linuxhelp:~# ip link
1: lo: < LOOPBACK,UP,LOWER_UP>  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens33: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:d7:91:be brd ff:ff:ff:ff:ff:ff


Now run the below command to install the bridge utility.

root@linuxhelp:~# apt-get install bridge-utils
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  bridge-utils
0 upgraded, 1 newly installed, 0 to remove and 370 not upgraded.
Need to get 28.6 kB of archives.
After this operation, 102 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 bridge-utils amd64 1.5-9ubuntu1 [28.6 kB]
Fetched 28.6 kB in 0s (43.7 kB/s) 
Selecting previously unselected package bridge-utils.
(Reading database ... 172193 files and directories currently installed.)
Preparing to unpack .../bridge-utils_1.5-9ubuntu1_amd64.deb ...
Unpacking bridge-utils (1.5-9ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up bridge-utils (1.5-9ubuntu1) ...


Next add the bridge interface with the following command.

root@linuxhelp:~# brctl addbr br0


Add default interface to bridge interface.

root@linuxhelp:~# brctl addif br0 ens33


Use nano editor to configure the added interfaces.

root@linuxhelp:~# nano /etc/network/interfaces


After configuration, open and add the following details in the interfaces. Then save and close the configuration file.

auto br0
iface br0 inet static
    bridge_ports      ens33
    address 192.168.7.124
    netmask 255.255.255.0
    gateway 192.168.7.1


Run the below command to restart the network service.

root@linuxhelp:~# /etc/init.d/networking restart


Check the IP address by using the following command.

root@linuxhelp:~# ip a
1: lo: < LOOPBACK,UP,LOWER_UP>  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether 00:0c:29:d7:91:be brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.123/24 brd 192.168.7.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed7:91be/64 scope link 
       valid_lft forever preferred_lft forever
3: br0: < BROADCAST,MULTICAST>  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:0c:29:d7:91:be brd ff:ff:ff:ff:ff:ff


Next use the below command to up the bridge interface.

root@linuxhelp:~# ip link set dev br0 up


Again check the IP address with the ip command.

root@linuxhelp:~# ip a
1: lo: < LOOPBACK,UP,LOWER_UP>  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
    link/ether 00:0c:29:d7:91:be brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.123/24 brd 192.168.7.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed7:91be/64 scope link 
       valid_lft forever preferred_lft forever
3: br0: < BROADCAST,MULTICAST,UP,LOWER_UP>  mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:d7:91:be brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.124/24 brd 192.168.7.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fed7:91be/64 scope link 
       valid_lft forever preferred_lft forever

To remove the Bridge Interface

First remove the connection bridge to default interface in the config file.

brctl delif br0 eth0


Then remove bridge interface.

brctl delbr br0
FAQ
Q
How to bring up the new or recently configured interfaces, issue a command as root?
A
For bring up the new or recently configured interfaces, issue a command as root, use the following format in Linux as "ifup device"
Q
Where is the IP configuration file on CentOS?
A
For configuring the IP address on CentOS, use the following configuration file as given below "/etc/sysconfig/network-scripts/ifcfg-interface name"
Q
What is the network configuration path for Debian based systems?
A
The network confguration path for Debian based systems, use the following file as given below "/etc/network/interfaces"
Q
How to create bridge interface via command line?
A
For creating the bridge interface on Linux, use the following command as below "brctl addbr br0"
Q
How to enable the bridge interface on Linux?
A
For enable the bridge interface on Linux, use the following command as given below "ip link set dev br0 up"