Bridge traffic between two network interfaces in GNU/LInux

A bridge is a device for forwarding packets between two or more Ethernets so that they behave in most respects as if they were a single network. It could be a physical device, but it is also possible for a bridge to be implemented entirely in software. The Linux kernel has the ability to perform bridging by means of the bridge module.

Linux bridge setup can be done with a user-space command-line tool called brctl which allows you to create, remove and administer Linux ethernet bridges.

Here i describes how to bridge eth0 to wlan0

To use brctl command, you need to install the bridge-utils package.

In Ubuntu

sudo apt-get install bridge-utils

In Fedora

sudo yum install bridge-utils

After installation to see all current bridge interfaces, execute the command

brctl show

To create a bridge

brctl addbr br0

To bring the interface up and to see in ifconfig issue this command

ifconfig br0 up

To add an interface to your bridge is simple

brctl addif br0 eth0

You can add multiple interfaces to the bridge

brctl addif br0 wlan0

Enable ip forwarding to share the internet

echo 1 > /proc/sys/net/ipv4/ip_forward

Finally you can either give br0 an ip address manually or can use the dhclient

dhclient -d br0

After this all the packets obtained via eth0 will be forwarded to wlan0.

Happy Hacking 🙂

Advertisements