SkillPilotAI

ebtables and arptables

ebtables is a Layer 2 firewall for a Linux bridge: it filters or rewrites Ethernet frames by MAC, EtherType, VLAN, STP and the IP/ARP fields inside. arptables filters only the ARP packets entering or leaving the host. Both stop attacks that iptables never sees, like ARP spoofing.

105.1 Why is it used?

  • ARP is its own EtherType (0x0806) and never reaches iptables, so iptables cannot stop ARP spoofing.
  • On a VM host, ebtables stops a rogue VM from faking its source IP or MAC on the bridge.
  • arptables locks an IP (e.g. the gateway) to its real MAC so the host's ARP cache is not poisoned.
  • Both use iptables-style chains, rules and -j targets. Linux only; modern distros ship ebtables-nft / arptables-nft in the iptables package (not on Windows/macOS).

105.2 How it works

ebtables anti-spoofing on br0
  1. 1.VMs connect to bridge br0 via vnet ports

  2. 2.VM1 (vnet0, 192.168.122.10) sends a normal frame -> ebtables forwards it to the router

  3. 3.Rogue VM (vnet1, real IP .20) fakes source 192.168.122.10

  4. 4.FORWARD rule: from vnet1 only IPv4 with source .20 may leave

  5. 5.Fake frame is dropped right at the bridge

arptables blocking a fake ARP on the host
  1. 1.PC 192.168.125.20 replies to ARP; host 192.168.125.10 stores its real MAC

  2. 2.bad (192.168.125.30) broadcasts a gratuitous ARP: .20 is at my MAC

  3. 3.Host arptables INPUT: ARP for .20 accepted only from the real MAC

  4. 4.Fake ARP dropped, cache stays correct

105.3 ebtables: tables, chains and commands

TableChainsPurpose
filter (default)INPUT, FORWARD, OUTPUTFilter bridge frames
natPREROUTING, OUTPUT, POSTROUTINGChange MAC addresses
brouteBROUTINGDROP = route the frame, ACCEPT = bridge it
Output
-j ACCEPT | DROP | CONTINUE | RETURN | chain-A / -I nr / -D rule | nr | 2:4-C nr pcnt bcnt   counters set (+N / -N)-P FORWARD DROP   chain policy-F / -Z [chain]   flush / counters zero-L -Z             list, phir zero-L --Ln --Lc      rule numbers + counters-L --Lx [--Lc]    rules as commands-L --Lmac2        full-length MACs-N chain [-P DROP]  -X chain  -E old new--init-table      table khaali karo
  • CONTINUE moves to the next rule: useful just for counting.
  • Lab kernel: NF_TABLES_ARP=y, but NF_TABLES_BRIDGE is not set and EBTABLES is only a module, so ebtables never touches the kernel here: only -V, -h and ebtables-translate are run.
Terminal
zcat /proc/config.gz | grep -E \  "TABLES_(BRIDGE|ARP)|EBTABLES=|ARP_MANGLE"ebtables -Varptables -V
Output
CONFIG_NF_TABLES_ARP=yCONFIG_IP_NF_ARP_MANGLE=m# CONFIG_NF_TABLES_BRIDGE is not setCONFIG_BRIDGE_NF_EBTABLES=m$ ebtables -Vebtables 1.8.10 (nf_tables)$ arptables -Varptables v1.8.10 (nf_tables)

105.4 ebtables matches via ebtables-translate

ebtables-translate is userspace only: it converts an ebtables rule to the nft bridge rule, which makes every option clear.

Terminal
ebtables-translate -A FORWARD \  -s 00:11:22:33:44:55 -j DROPebtables-translate -A FORWARD -i vnet0 \  -p IPv4 --ip-src ! 192.168.122.10 -j DROPebtables-translate -A FORWARD -p IPv4 \  --ip-proto udp --ip-dport 67:68 -i eth1 \  -j DROPebtables-translate -A FORWARD -p 802_1Q \  --vlan-id 10 -j ACCEPTebtables-translate -A FORWARD \  --pkttype-type broadcast \  --limit 100/second -j ACCEPTebtables-translate -A FORWARD \  --mark 0x1 -j DROP
Output
nft 'add rule bridge filter FORWARD ether saddr 00:11:22:33:44:55 counter drop'nft 'add rule bridge filter FORWARD iifname "vnet0" ip saddr != 192.168.122.10 counter drop'nft 'add rule bridge filter FORWARD iifname "eth1" ether type ip udp dport 67-68 counter drop'nft 'add rule bridge filter FORWARD vlan id 10 counter accept'nft 'add rule bridge filter FORWARD meta pkttype broadcast limit rate 100/second burst 5 packets counter accept'nft 'add rule bridge filter FORWARD meta mark 0x1 counter drop'
MatchKey options
ip--ip-src/--ip-dst, --ip-proto, --ip-sport/--ip-dport, --ip-tos
vlan (-p 802_1Q)--vlan-id 0-4095, --vlan-prio 0-7 (VID 0 or unspecified), --vlan-encap
arp (-p ARP)--arp-opcode, --arp-ip-src/dst, --arp-mac-src/dst, --arp-gratuitous
ip6 (-p IPv6)--ip6-src/dst, --ip6-proto, --ip6-sport/dport, --ip6-icmp-type
among--among-src|dst[-file] MAC[=IP],... (MAC allowlist)
stp (-d BGA)--stp-type, --stp-flags, root/sender prio, timers
802_3 (-p LENGTH)--802_3-sap / --802_3-type
limit, mark_m, pkttype--limit 100/second, --mark 0x1, --pkttype-type broadcast

105.5 ebtables watchers and targets

  • Watchers (log, nflog, ulog) only observe a frame before the target, never change it.
  • nat table: snat changes the source MAC, dnat the destination MAC, redirect sets dst MAC to the bridge's own MAC.
  • mark sets a frame mark iptables can read; arpreply answers ARP on the bridge (no nft translation yet).
Terminal
ebtables-translate -A FORWARD -p IPv4 \  --log --log-ip --log-prefix BR -j CONTINUEebtables-translate -A FORWARD \  --nflog-group 5 -j ACCEPTebtables-translate -t nat -A POSTROUTING \  -o eth1 -j snat --to-src 00:aa:bb:cc:dd:eeebtables-translate -t nat -A PREROUTING \  -d 00:11:22:33:44:55 -j dnat \  --to-dst 00:aa:bb:cc:dd:eeebtables-translate -A FORWARD -i eth0 \  -j mark --mark-set 0x1ebtables-translate -t nat -A PREROUTING \  -p ARP --arp-ip-dst 192.168.1.1 \  -j arpreply \  --arpreply-mac 00:11:22:33:44:55
Output
nft 'add rule bridge filter FORWARD ether type 0x800 log prefix "BR" level notice flags ether counter'nft 'add rule bridge filter FORWARD log group 5 counter accept'nft 'add rule bridge nat POSTROUTING oifname "eth1" counter ether saddr set 00:AA:BB:CC:DD:EE accept'nft 'add rule bridge nat PREROUTING ether daddr 00:11:22:33:44:55 counter ether daddr set 00:AA:BB:CC:DD:EE accept'nft 'add rule bridge filter FORWARD iifname "eth0" counter meta mark set 0x1 accept'nft ' # -t nat -A PREROUTING -p ARP --arp-ip-dst 192.168.1.1 -j arpreply --arpreply-mac 00:11:22:33:44:55Translation not implemented

105.6 arptables: blocking a host

Lab: containers host 192.168.125.10, pc .20, bad .30, all inside the lab network. arptables has only the filter table with INPUT and OUTPUT chains.

Terminal
# host 192.168.125.10 (NET_ADMIN)arptables -Larptables -A INPUT -s 192.168.125.30 -j DROPip neigh flush all# bad 192.168.125.30 (sirf apna lab)ping -c 2 -W 1 192.168.125.10 | tail -2# pc 192.168.125.20ping -c 2 -W 1 192.168.125.10 | tail -2# hostarptables -L INPUT -n -v --line-numbersarptables -F INPUT
Output
[host]$ arptables -LChain INPUT (policy ACCEPT) Chain OUTPUT (policy ACCEPT)[bad]$ ping -c 2 -W 1 192.168.125.10 | tail -22 packets transmitted, 0 received, 100% packet loss, time 1008ms[pc]$ ping -c 2 -W 1 192.168.125.10 | tail -22 packets transmitted, 2 received, 0% packet loss, time 1006ms[host]$ arptables -L INPUT -n -v --line-numbersChain INPUT (policy ACCEPT 4 packets, 112 bytes)1 -j DROP -i * -o * -s 192.168.125.30 , pcnt=4 -- bcnt=112

105.7 Real-world example: stopping ARP spoofing

Cache poisoning, then the fix
  1. 1.Host pings pc and learns real MAC ...7d:14 (REACHABLE)

  2. 2.bad runs arping -U with source 192.168.125.20

  3. 3.Host cache now shows ...7d:1e: poisoned

  4. 4.Fix: flush, relearn, add rule -s .20 ! --source-mac ...7d:14 -j DROP

  5. 5.Same arping again: cache keeps ...7d:14, rule counter = 2

Terminal
# host 192.168.125.10ping -c 1 -W 1 192.168.125.20 >/dev/nullip neigh show 192.168.125.20# bad (sirf apna lab): fake gratuitous ARParping -U -c 2 -I eth0 \  -s 192.168.125.20 192.168.125.20# host: cache poison, ab fixip neigh flush allping -c 1 -W 1 192.168.125.20 >/dev/nullarptables -A INPUT -s 192.168.125.20 \  ! --source-mac 02:42:c0:a8:7d:14 -j DROP# bad: wahi arping dobara# hostip neigh show 192.168.125.20arptables -L INPUT -n -v
Output
[host]$ ip neigh show 192.168.125.20192.168.125.20 dev eth0 lladdr 02:42:c0:a8:7d:14 REACHABLE[bad]$ arping -U -c 2 -I eth0 -s 192.168.125.20 192.168.125.20ARPING 192.168.125.20 from 192.168.125.20 eth0Sent 2 probes (2 broadcast(s))[host]$ ip neigh show 192.168.125.20192.168.125.20 dev eth0 lladdr 02:42:c0:a8:7d:1e STALE[bad]$ arping -U -c 2 -I eth0 -s 192.168.125.20 192.168.125.20Sent 2 probes (2 broadcast(s))[host]$ ip neigh show 192.168.125.20192.168.125.20 dev eth0 lladdr 02:42:c0:a8:7d:14 REACHABLE[host]$ arptables -L INPUT -n -vChain INPUT (policy ACCEPT 9 packets, 252 bytes)-j DROP -i * -o * -s 192.168.125.20 ! --src-mac 02:42:c0:a8:7d:14 , pcnt=2 -- bcnt=56

105.8 arptables: commands, chains, policy and save

Terminal
arptables -I INPUT 1 --opcode 2 \  -i eth0 -j ACCEPTarptables -A INPUT -c 5 300 \  -s 192.168.125.30 -j DROParptables -L INPUT -n -v --line-numbersarptables -R INPUT 3 -s 192.168.125.40 -j DROParptables -D INPUT 1arptables -Z INPUTarptables -L INPUT -n -v --line-numbers
Output
$ arptables -L INPUT -n -v --line-numbersChain INPUT (policy ACCEPT 9 packets, 252 bytes)1 -j ACCEPT -i eth0 -o * --opcode 2 , pcnt=0 -- bcnt=02 -j DROP -i * -o * -s 192.168.125.20 ! --src-mac 02:42:c0:a8:7d:14 , pcnt=2 -- bcnt=563 -j DROP -i * -o * -s 192.168.125.30 , pcnt=5 -- bcnt=300$ arptables -L INPUT -n -v --line-numbersChain INPUT (policy ACCEPT 0 packets, 0 bytes)1 -j DROP -i * -o * -s 192.168.125.20 ! --src-mac 02:42:c0:a8:7d:14 , pcnt=0 -- bcnt=02 -j DROP -i * -o * -s 192.168.125.40 , pcnt=0 -- bcnt=0
Terminal
arptables -N arpcheckarptables -A arpcheck -l 6 --h-type 1 \  --proto-type 0x800 -j RETURNarptables -A INPUT -i eth0 -j arpcheckarptables -E arpcheck arpguardarptables -X arpguardarptables-savearptables -P INPUT DROPip neigh flush all# pc 192.168.125.20ping -c 2 -W 1 192.168.125.10 | tail -2# hostarptables -P INPUT ACCEPTarptables -F; arptables -X; arptables -L
Output
[host]$ arptables -X arpguardarptables v1.8.10 (nf_tables):  CHAIN_DEL failed (Resource busy): chain arpguard[host]$ arptables-save*filter:INPUT ACCEPT:OUTPUT ACCEPT:arpguard --A INPUT -j DROP -s 192.168.125.20 ! --src-mac 02:42:c0:a8:7d:14-A INPUT -j DROP -s 192.168.125.40-A INPUT -j arpguard -i eth0-A arpguard -j RETURN --proto-type 0x800[pc]$ ping -c 2 -W 1 192.168.125.10 | tail -22 packets transmitted, 0 received, 100% packet loss, time 1010ms[host]$ arptables -L INPUT -n -v | head -3Chain INPUT (policy DROP 6 packets, 168 bytes)
  • --opcode: 1 Request, 2 Reply, 3/4 RARP, 8 InARP, 9 ARP_NAK.
  • Targets: mangle (--mangle-ip-s/-d, --mangle-mac-s/-d), CLASSIFY --set-class, MARK --set-mark; kernel modules not loaded in this lab.
  • Policy DROP blocks all ARP to the host, so even the pc's ping fails.

105.9 Comparison: ebtables vs arptables vs iptables

Pointebtablesarptablesiptables
LayerL2 bridge framesARP onlyL3 IP packets
Chainsfilter/nat/brouteINPUT, OUTPUTINPUT, FORWARD, OUTPUT...
Sees ARPYes (arp match)YesNo
RewritesMAC NAT (snat/dnat)ARP fields (mangle)IP NAT
nftables familybridgearpip / ip6 / inet

105.10 Common mistakes

  • Expecting iptables to stop ARP spoofing: ARP never reaches iptables.
  • Using arptables for traffic forwarded between VMs: that needs ebtables FORWARD on the bridge.
  • Setting arptables policy DROP without allow rules: the host stops resolving everyone.
  • Deleting a user chain that is still referenced: Resource busy; remove the jump first.

105.11 Interview tips

  • ebtables = L2 bridge firewall (MAC, VLAN, STP, IP fields + MAC NAT); arptables = host INPUT/OUTPUT ARP filter + mangle.
  • Fake gateway ARP to the host -> arptables INPUT with ! --source-mac; VM traffic through a bridge -> ebtables FORWARD.
  • Both use iptables syntax and run on the nftables backend (bridge and arp families).
  • ebtables-translate shows the nft equivalent of any rule.