Kernel Korner - Linux as an Ethernet Bridge

It passes packets like a bridge and filters like a firewall. Put extra security and versatility in front of any server or device, without reconfiguring it.
Surviving a Reboot

How you set up your install to survive a reboot is your choice. A simple way is to add all of the commands we have used to /etc/rc.local, which is processed at the end of startup. Enter the commands used above to this file, and your bridge is functional after startup.


As with any Linux install that passes or forwards traffic, you have the ability to filter the stream of information as it passes by. A bridging firewall is no different. There are many ways to create and maintain firewall configurations. Below, I explain how to use the most basic firewall type: deny all, pass some. We want to deny everything passing this firewall unless we specifically state that something is allowed.

This firewall configuration requires you to download and install the ebtables user-space tools available from the ebtables Web site (see Resources). At the time of this writing, the latest release was v2.0.6. Grab a copy of this from one of the many mirrors. Do the usual extract and install dance without the initial configure step:

#> tar -xzf ebtables-v2.0.6.tar.gz
#> cd ebtables-v2.0.6
#> make
#> install

If all goes well, you should have the ebtables command set at your fingertips. Test this by typing ebtables at the prompt; you should see something similar to this:

#> ebtables -V
ebtables v2.0.6 (November 2003)

Let's start by making sure iptables is set to accept. Remember we're on Fedora Core 3, so we simply can tell the service to quit, which does the same thing:

#> service iptables stop
#> chkconfig --level 35 iptables off

You can do something similar by issuing the flush command. List your available chains and then flush each of them in turn:

#> iptables -L
#> iptables -F INPUT
#> iptables -F OUTPUT
#> iptables -F FORWARD
#> iptables -F RH-Firewall-1-INPUT

Now we want to stop all traffic from all areas of our network from passing through the firewall. The following rules are specific to the network we're working with for this example; you need to amend the subnets or hosts to reflect your specific requirements:

/sbin/ebtables -A FORWARD -p IPv4 \
--ip-source -j DROP
/sbin/ebtables -A FORWARD -p IPv4 \
--ip-source -j DROP
/sbin/ebtables -A FORWARD -p IPv4 \
--ip-source -j DROP
/sbin/ebtables -A FORWARD -p IPv4 \
--ip-source -j DROP
/sbin/ebtables -A FORWARD -p IPv4 \
--ip-source -j DROP
/sbin/ebtables -A FORWARD -p IPv4 \
--ip-source -j DROP

Those of you familiar with iptables should notice that the syntax above is similar. We tell the ebtables program that when FORWARDING using the IPv4 protocol to DROP any packets sourced from the subnet. We then tell it to repeat for the rest of the subnets.

The next step is to allow the device behind the firewall itself. If you do not allow its IP address to pass through, nothing works. Also, if you assign an IP address to the firewall itself, don't forget to allow it as well:

/sbin/ebtables -I FORWARD 1 -p IPv4 \
--ip-source -j ACCEPT
/sbin/ebtables -I FORWARD 1 -p IPv4 \
--ip-source -j ACCEPT

Here, I add the devices on my network that are allowed to access my laptop:

/sbin/ebtables -I FORWARD 1 -p IPv4 \
--ip-source -j ACCEPT
/sbin/ebtables -I FORWARD 1 -p IPv4 \
--ip-source -j ACCEPT
/sbin/ebtables -I FORWARD 1 -p IPv4 \
--ip-source -j ACCEPT

To test this, I simply go to a machine listed in the ACCEPT rules above and see if I can ping my laptop at Now move to a node not listed above—no pings for you!

Real-World Implementation

Recently, I was called to a customer's site to secure a financial server. The request was simple: we need a firewall in front of this system but we cannot change its IP address. With two NICs and a Linux OS, I was able to have a working firewall up and running in a few minutes. Installation also was a breeze. I simply used a crossover cable that connected the firewall to the server and a regular cable from the other network card on the firewall to the network jack. That was it. No redesign was necessary of any part of the existing IP scheme; it truly was plug-and-play. Once a few rules were in place to drop all packets unless they were from the IP addresses and ports listed as acceptable, the project was completed.

One of the beautiful aspects of Linux is its ability to run many services on one system. Take the above example. I quickly firewalled a sensitive server, but that was not the end of the project. With all the extra time and money we saved using Linux, we were able to load Snort on the firewall. With a quick hack to the sniffer's config file—/etc/snort.conf in our case—we told Snort to listen to interface br0, and snort immediately began to do its stuff on the bridging interface.

This is where the true power of the bridging code can be felt. Ever had a segment of the network running slow but you don't know why? Next time, load a Linux box with Snort and any other sleuthing software you like and get the bridge up and running. Find your trusty crossover cable and head out to the site. Because the bridge acts like a hub, you simply can insert your Linux box at any point in the network. As long as you have the physical connections, you can drop your box in and begin to sniff live in a matter of seconds. The latest project we have been working on included transparent Squid cache servers that are truly transparent requiring zero reconfiguration to the IP scheme, clients or browsers. Simply insert the Squid box in front of the router and redirect all port 80 traffic to the box itself and you're done.

The ability of Linux to slide transparently into existing network infrastructure opens a world of new and improved services that the penguin can provide. With the ability to place dissimilar networking devices into one virtual entity, you can use a single device to firewall and monitor any aspect of your network. You're only limitation is the speed of your hardware and its number of available slots.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Note to readers: The author

Kevin Borders's picture

Note to readers: The author says many times that brctl causes your machine to act like a HUB. This is incorrect, brctl will make your machine behave like a SWITCH. If a particular MAC address has sent some packets on one of the bridge ports, brctl will only forward packets destined for that MAC address to that one port, not all ports.

Bridge as router

Beginer 's picture

How to configure Bridge as Router?
I have box, which acts as bridge und AP. Internet => Bridge,AP => Laptop WiFi. I have to change MAC Address on Laptop-WiFi (that know my Internet Provider). Bridge is transparent. I want set up MAC Addres on Bridge interface from Internet porvider and to connect to WiFi net with whatever MAC Address.

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
On Demand
Moderated by Linux Journal Contributor Mike Diehl

Sign up and watch now

Sponsored by Skybot