A minimal XDP/eBPF firewall that filters packets at the driver level, bypassing the normal networking stack. Built for learning purposes only.
- Block all traffic from 8.8.8.8
- Allow only UDP port 53 (DNS), block all other UDP
- Block TCP port 80 (HTTP)
Compile the eBPF object file:
clang -O2 -g -target bpf -D__TARGET_ARCH_arm64 \
-I/usr/include \
-I/usr/include/bpf \
-c firewall.c -o firewall.oAttach the firewall to a network interface:
sudo ip link set dev <interface> xdp obj firewall.o sec firewallWatch dropped packets in realtime:
sudo cat /sys/kernel/debug/tracing/trace_pipeRemove the firewall:
sudo ip link set dev <interface> xdp off