How to setup a network bridge in Ubuntu Linux

How to setup a network bridge in Ubuntu Linux

This post guides on how to setup a network bridge in Ubuntu Lniux. I just cannot guarantee that this will work on all Ubuntu versions but this will surely work on 12.04, 14.04, 14.10 and 15.04.

I am not going to cover every corner aspects of a network bridge setup rather I my guide will be short but contain enough data to setup a working software bridge.

If you know what is a software bridge then that’s really good but if you don’t know what is network bridge and how you can take advantage of this then yes this will be very much helpful for you. If you are a newbie then you may not have the understanding of network concepts.

I will try to keep things simple as much as possible. Personally I am not a network administrator, so, I am creating a network bridge to setup my Virtual Machines. Hence I will be explaining the network bridge concept from setting up a virtual machine environment context only.

Why a bridge setup is needed or How a network bridge is helpful???

– When you say a “bridge” means it may come to your mind that it must be connecting two or more things. Similarly a network bridge also connects a one or more number of ethernet adapters.
– Using a network bridge you can combine two ethernet networks.
– A software network bridge virtualizes a physical network adapter as N number of virtual ethernet adapters. If you have only a single ethernet adapter on the host machine then using a software network bridge you can virtualize the adapter to N number of ethernet adapters which can be used by N number of Virtual Machines running on the host machine.

How to setup or create a network bridge in Ubuntu Linux???

First of all you need to have the bridge utils installed on your Ubuntu machine.
Execute the below command in the console to install bridg utils:

$ sudo apt-get update
$ sudo apt-get install bridge-utils

After that create a software bridge using the following command:

$ sudo brctl addbr BRIDGE_NAME
$ sudo brctl addbr bridge0

This bridge0 is temporary and will be deleted on the next boot.
So to retain the bridge and route all other network adapters through this bridge we will configure the network script accordingly.

/etc/network/interfaces contains network interface configuration information. So open the file as a superuser and edit that file.

$ sudo vim /etc/network/interfaces

You will see something like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto em1
    iface em1 inet dhcp

In the above data the line iface em1 inet dhcp directs the network service to assign IP to em1 ethernet adapter from DHCP. You may not have em1 or em2 as your etherenet adapters but you may have eth1 or eth2 or some other name.

Now we will be setting all our ethernet adapters (Physical or even the virtual adapters) to route through the spftware brodge bridge0 that we had created in the earlier step. You need to edit the /etc/network/interfaces file. Any line in the file starting with a # is comment.

You can straight away use the following data to setup the network configuration file:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto em1
auto em2

# Bridge network interface
auto bridge0
# Below line will create a bridge and assign IP from DHCP server
iface bridge0 inet dhcp
  bridge_ports all em1 em2

If you need to setup static IP then you need to setup the bridge interface data similar to below:

# Bridge network interface
auto bridge0
# Below line will create a bridge and assign static IP
iface bridge0 inet static
  # Set a free IP from your network
  # Your network may have different class of IP, so set them up accordingly
  address 192.168.1.xxx
  netmask 255.255.255.0
  broadcast 192.168.1.255
  network 192.168.1.0
  gateway 192.168.1.1
  dns-nameserver YOUR_DNS_SERVER_IP
  bridge_ports all em1 em2

After setting up as above either you need to reboot the Ubuntu machine or restart networking services by executing the following command:

$ sudo /etc/init.d/networking restart

If everything is setup correctly then you will notince in the ifconfig output that there is one IP assigned only to the bridge0 interface and all others do not show any IP information.

That’s all folks. If you need a complete guide of setting up a bridge in Ubuntu then I will recommend you to visit the following page:
bridge utils man page from Ubuntu network

Previous Xperia M Lollipop 5.1.1 CyanogenMod 12.1 ROM
Next Asus ZenPad S 8.0: 6mm thick with 64-bit processing

About author

siba 698 posts

A B.Tech degree holder with more than 5 years of experience on Embedded Systems design domain. He has worked on Aerospace domain, NAND storage, Server storage and Wireless networking.

View all posts by this author →

You might also like

Linux Guides 0 Comments

How to Learn Linux with an Online Linux Terminal

Are you looking for some online linux terminals to work with?? Yes, there are some Linux terminals available online which will be helpful for you to learn Linux on the

Linux Guides 0 Comments

How to Learn Linux Without Having a Linux Machine?

Wondering how to learn Linux without having a Linux PC with you?? You might be thinking, is it really possible or you’re just kidding me?? Trust me it’s all possible

Linux Guides 0 Comments

How to Unload a Module in Linux or Blacklist Module in Grub

Sometimes you need to unload a kernel module to load your own written code or you want to replace an out-of-box stock module to a vendor provided kernel module. Ir

0 Comments

No Comments Yet!

You can be first to comment this post!