This post will tell you how to setup a network bridge in Ubuntu. 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 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