ebtables

On this page 7

ebtables is the Linux utility for filtering and modifying Ethernet frames that cross a Linux bridge, matching on MAC addresses, EtherType, VLAN tags and bridge ports rather than on IP addresses alone. In Linux Networking, it is the link layer counterpart of iptables: where iptables works on IP packets, ebtables works on frames inside a bridge.

The name stands for Ethernet bridge tables. The tool configures rule tables in the kernel through the netfilter framework, and it has long been used to stop MAC spoofing on virtual machine bridges, filter ARP traffic and redirect frames. On current distributions, its role is gradually taken over by the bridge family in nftables.

How ebtables filters bridged frames

ebtables works by attaching rule chains to netfilter hooks in the bridge code path. When a frame enters a bridge port, the kernel walks the relevant chain and compares the frame against each rule until a rule with a terminal target such as ACCEPT or DROP matches, or the chain policy applies.

Rules are organized into three tables, each with its own built-in chains. The table determines when a rule runs and what it is allowed to do, as the following overview shows.

TableBuilt-in chainsMain purpose
filterINPUT, FORWARD, OUTPUTAccept or drop frames
natPREROUTING, OUTPUT, POSTROUTINGRewrite source or destination MAC
brouteBROUTINGDecide whether to bridge or route
ebtables tables and their built-in chains

The broute table is unique to ebtables. In its BROUTING chain, the target DROP does not discard the frame; it means pass the frame up to the IP stack for routing instead of bridging it. ACCEPT means bridge the frame normally. This inversion is a frequent source of confusion.

Matches, targets and extensions

An ebtables rule combines match conditions with one target. Basic matches cover the protocol field, source and destination MAC addresses, the input or output bridge port and the logical bridge device, while extensions add protocol-specific matching.

Option or extensionMatches onExample
-pEtherType of the frame-p IPv4, -p ARP
-s and -dSource or destination MAC-s 52:54:00:12:34:56
-i and -oBridge port interface-i vnet0
–logical-inBridge device the frame entered--logical-in br0
arp extensionARP opcode and addresses--arp-ip-src 10.0.0.5
ip and ip6 extensionsIP addresses and ports--ip-proto tcp
vlan extension802.1Q VLAN ID--vlan-id 20
among extensionLists of MAC and IP pairs--among-src
Commonly used ebtables matches and options

Targets include ACCEPT, DROP, CONTINUE and RETURN, plus extension targets such as snat and dnat for MAC rewriting, redirect for sending frames to the local host, arpreply for answering ARP requests directly and log or nflog for recording matches. Each target is valid only in certain tables and chains.

ebtables compared with iptables and nftables

ebtables, iptables and nftables all build on netfilter, but they see different layers of traffic. Choosing among them depends on whether the traffic is bridged or routed, and on what the distribution supports.

Aspectebtablesiptablesnftables
LayerEthernet framesIPv4 packetsAll families
Typical trafficBridgedRouted or localBridged, routed or local
Matches MAC addressesNativelyOnly source MACNatively in bridge family
Rule updatesPer rule or atomic filePer rule or restoreAtomic transactions
StatusLegacy, maintainedLegacy, maintainedCurrent framework
Link layer and network layer filtering tools

Bridged IP traffic can also reach iptables when the br_netfilter module is loaded and net.bridge.bridge-nf-call-iptables is set to 1, as container platforms often require. This lets IP rules see bridged packets, but it adds overhead and can produce surprising interactions with ebtables rules.

Legacy and nft backends

Modern distributions ship ebtables in two implementations. ebtables-legacy talks to the original kernel ebtables module, while ebtables-nft accepts the same syntax but translates rules into the nftables bridge family. The ebtables command usually points to the nft variant through the alternatives system.

The two backends maintain separate rule sets, so rules added with one are invisible to the other. Mixing them on the same host is a classic cause of rules that appear correct yet have no effect. Running ebtables --version shows which backend is active, and nft list ruleset reveals rules created through ebtables-nft.

For new deployments, writing native nftables rules in a table of type bridge is the recommended direction, because it offers atomic updates, sets and maps in one framework. ebtables syntax remains useful when maintaining existing scripts and virtualization tooling.

Practical uses and common pitfalls

ebtables is most valuable where traffic never leaves the bridge layer, for example between virtual machines on the same host. In these setups, IP firewalls on the host may never see the frames, so link layer filtering is the only enforcement point.

SituationRule approachBenefit
VM MAC spoofingDrop frames whose source MAC differs per portGuests cannot impersonate others
ARP poisoningRestrict ARP sender IP per portPrevents traffic hijacking
Protocol isolationDrop unwanted EtherTypesBlocks IPv6 or legacy protocols
Transparent proxyBroute selected frames to the IP stackIntercepts traffic without readdressing
Typical ebtables use cases
  • Forgetting rule order causes an early ACCEPT to bypass later DROP rules, because the first terminal match wins.
  • Misreading broute DROP as discarding a frame leads to traffic being routed unexpectedly.
  • Losing rules at reboot happens because ebtables keeps rules only in kernel memory; persistence needs ebtables-save and a restore service.
  • Assuming IP visibility without the ip extension causes rules on IP addresses to match nothing.

A plain-language summary

A network bridge in Linux works like a switch inside the computer, connecting virtual machines or network cards so they can talk directly. ebtables is a gatekeeper on that switch. It looks at the hardware addresses written on each piece of traffic and decides whether to let it through, block it or change it.

Ordinary firewalls look at internet addresses, which come later in the journey. ebtables acts earlier, at the switch itself, which is why it can stop one machine from pretending to be another.

An example from practice

A university laboratory runs about 40 student virtual machines on two hosts, all attached to the bridge br0. One semester, a student experiments with ARP spoofing tools and redirects a classmate’s traffic through their own machine, which the host IP firewall never notices because the frames stay inside the bridge.

The administrator adds per-port ebtables rules: frames from each vnet interface must carry the MAC address assigned to that VM, and ARP replies must carry its assigned IP address, using the arp extension. Everything else from the port is dropped and logged with a rate limit.

The rules are saved with ebtables-save and restored at boot. In the following weeks, the log shows several blocked spoofing attempts and no successful hijacks, while normal student traffic flows unchanged.