AboutBlogContact
DevOps & InfrastructureJune 30, 2002 2 min read 127Updated: June 22, 2026

OpenBSD: Optimizing Packet Filter (PF) Rules (2002)

AunimedaAunimeda
📋 Table of Contents

OpenBSD: Optimizing Packet Filter (PF) Rules

When OpenBSD replaced IPFilter with PF in 3.0, the world changed. PF's syntax is cleaner, but its power lies in how it handles large rulesets. If you have 500 lines in your pf.conf, you're likely killing your throughput.

Use Tables, Not Lists

The biggest mistake is using long lists of IP addresses in rules. Every time a packet arrives, PF has to iterate through that list.

The Wrong Way:

block in quick on ext_if from 1.2.3.4 to any
block in quick on ext_if from 5.6.7.8 to any
block in quick on ext_if from 9.10.11.12 to any

The Right Way (Tables): Tables use Radix trees, allowing for O(log n) lookups. Even with 100,000 IPs, the performance hit is negligible.

table <spammers> persist file "/etc/spammers"
block in quick on ext_if from <spammers> to any

State Modulation and Optimization

PF is stateful. Once a packet matches, subsequent packets in that flow skip the ruleset entirely. You can optimize how states are handled:

set optimization aggressive
set limit states 20000

# Keep state but optimize for high-traffic web servers
pass in on ext_if proto tcp from any to any port 80 \
    flags S/SA modulate state

By using modulate state, PF provides high-quality initial sequence numbers for the connection, shielding older or poorly implemented TCP stacks from hijacking. PF isn't just a firewall; it's a security-hardened traffic shaper.


Aunimeda provides DevOps engineering and infrastructure services - CI/CD pipelines, containerization, cloud deployments, and monitoring setups.

Contact us to discuss your infrastructure needs. See also: DevOps Services, Custom Software Development

Read Also

Docker Multi-Stage Builds: Slimming Down Your Production Images (2019)aunimeda
DevOps & Infrastructure

Docker Multi-Stage Builds: Slimming Down Your Production Images (2019)

Shipping a 1GB Node.js image is so 2017. In 2019, we use multi-stage builds to separate our build environment from our runtime environment, resulting in tiny, secure images.

FreeBSD Jail: Containers Before They Were Cool (1998)aunimeda
DevOps & Infrastructure

FreeBSD Jail: Containers Before They Were Cool (1998)

Forget chroot. FreeBSD 4.0 brings us Jails-real process isolation that keeps your services locked down and your host secure.

Docker Compose vs Kubernetes: What Small Teams Actually Need in 2026aunimeda
DevOps & Infrastructure

Docker Compose vs Kubernetes: What Small Teams Actually Need in 2026

Kubernetes is powerful and over-engineered for most small products. Docker Compose is simple and hits its limits faster than you'd think. Here's where the actual boundary is, with real configs for both.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

DevOps Services

Get Consultation All articles