OpenBSD PF Firewall - Beginner Guide

Contents
OpenBSD PF Firewall - Beginner Guide
How PF Works
Basic PF Configuration
Enabling and Disabling PF
Common Beginner Mistakes

OpenBSD PF Firewall - Beginner Guide

PF (Packet Filter) is OpenBSD's built-in firewall. It's enabled by default and blocks all incoming connections for your security.

How PF Works

By default, OpenBSD's PF firewall:
block in all - blocks all incoming connections
pass out all - allows all outgoing connections
This means: You can surf the web, send email, etc., but nobody can connect to your computer from the internet unless you explicitly allow it.

Basic PF Configuration

The main configuration file is /etc/pf.conf. Let's look at a simple example:

Example: Allow SSH Only

This configuration allows only SSH (port 22) connections from the internet, and allows everything else on your local network.

# /etc/pf.conf - simple SSH-only configuration
set skip on lo0  # Skip loopback interface
 
# Allow established connections and related traffic
pass in quick on egress proto tcp from any to any port 22  # Allow SSH
 
# Block everything else incoming
block in all
Example: Allow SSH + Web Server

This allows SSH (port 22) and web server (ports 80 and 443) from the internet.

# /etc/pf.conf - SSH and web server
set skip on lo0
 
# Allow established connections
pass in quick on egress proto tcp from any to any port { 22 80 443 }
 
# Block everything else
block in all

Enabling and Disabling PF

PF is enabled by default on OpenBSD boot.
To disable temporarily: pfctl -d
To re-enable: pfctl -e
To check status: pfctl -s rules - shows current rules
To reload configuration: pfctl -f /etc/pf.conf

Common Beginner Mistakes

Mistake 1: block in all without allowing SSH first.
Result: You lock yourself out! You can't connect via SSH.
Fix: Always allow SSH before adding block in all, or use a console cable.

Mistake 2: Syntax error in /etc/pf.conf.
Result: PF may not start, or rules won't work properly.
Fix: Use pfctl -n -f /etc/pf.conf to check for errors without loading.

Mistake 3: Forgetting to apply changes.
Result: Old rules still active.
Fix: Always run pfctl -f /etc/pf.conf after editing.

Want to see PF advanced rules? Proceed to Lesson 11: PF Advanced Rules.

Next: OpenBSD SSH Configuration - Beginner Guide

Article author: Arthur Isaev

Related articles
UNIX
OpenBSD
OpenBSD course
Architecture Compatibility
Prepare Installation Media
BIOS Installation
UEFI Installation
Disk Partitioning
Base System Installation
Configure Network
Disable Firewall Temporarily
OpenSSH Server
Update System
Security Basics
Frequently Asked Questions
Virtualization Overview
Docker Containers
Kubernetes
PF NAT Configuration
PF Suppression
IPsec VPN
WireGuard VPN
Advanced Cron
Systemd Compatibility
PF Firewall Introduction
Shells
Environment Variables
Sudoers Configuration
/etc/fstab
Group Management
Password Security
Issue and Banner
PAM Configuration
TCP Wrappers
Intrusion Detection
PF Advanced Rules
Log Analysis
Advanced Backup
Kernel Update
Certificate Management
Access Control Lists (ACLs)
User Security Settings
Vulnerability Management
Security Audit Tools
Security Parameter Tuning
SSH Key Authentication
sudo vs doas
Users and Groups
PostgreSQL Introduction
Services Management
Web Server Overview
Install Apache Web Server
Install Nginx Web Server
Database Setup
Install PHP
Firewall Configuration
SSL/TLS Certificate
Firewall Configuration
Install PHP
Install PHP
Advanced SSL/TLS Configuration
User Management Advanced
PF Logging and Monitoring
Custom Kernel compilation
Advanced doas Configuration
Resource Limits
DHCP Server
Mail Server
SSH Hardening
System Logging
Disk Encryption
Window Managers
Text Editors
Package Management
Cron Jobs
System Monitoring
PF Firewall Advanced
SSH Configuration
Services Management
PHP and Web Stack
Advanced User Management
Swap and Memory
Kernel Parameters
Boot Process
Mounting Filesystems
UFS Filesystem
Softraid
Disk Management
DNS Configuration
Hosts File
Network Statistics
Routing
Network Bridging
System Upgrade
Backup Strategies
Log Rotation
GCC Compiler
Make Build System
Debugging
System Call Tracing
FIPS 140-2
Audit System
Security Compliance
Virtual Machines
LXC Containers
HTTP API
Advanced Monitoring
SELinux (Ported)
Course Conclusion
OpenBSD Architecture - Beginner Guide
OpenBSD Installation Media - Beginner Guide
OpenBSD Disk Partitioning - Beginner Guide
OpenBSD System Updates - Beginner Guide
OpenBSD PF Firewall - Beginner Guide
OpenBSD SSH Configuration - Beginner Guide
OpenBSD User Management - Beginner Guide
OpenBSD Web Server - Beginner Guide
OpenBSD PostgreSQL Database - Beginner Guide
OpenBSD PF Logging and Monitoring - Beginner Guide
OpenBSD SSH Hardening - Beginner Guide
OpenBSD Package Management - Beginner Guide
OpenBSD Firewall Configuration - Beginner Guide
OpenBSD Backup Strategies - Beginner Guide
OpenBSD GCC Compiler - Beginner Guide
OpenBSD Virtual Machines - Beginner Guide
OpenBSD Course Conclusion - Beginner Guide
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: