OpenBSD Firewall Configuration - Beginner Guide

OpenBSD Firewall Configuration - Beginner Guide

OpenBSD's PF firewall protects your computer from unwanted network access. Here's how to configure it for beginners.

Understanding Default Protection

By default, OpenBSD's PF firewall:

block in all - blocks ALL incoming connections from the internet
pass out all - allows ALL outgoing connections from your computer
set skip on lo0 - allows traffic on the loopback (local) interface

What This Means for You

Good news: Your computer is already secure by default!

People from the internet cannot:
- Connect to your computer unsolicited - Access your web server, SSH, or other services
- See your computer on the network (unless you allow it)

When You Need to Configure PF

You only need to modify PF when you want to:

Allow incoming connections: For your web server, SSH, game server, etc.
Restrict access: Only allow specific IP addresses or networks
Set up networking: If you have multiple network interfaces

Default is usually fine: For most home/office users, don't change PF unless you have a specific reason.

Basic PF Configuration Steps

If you do need to configure PF, here's the basic process:

1. Edit the configuration file:
vi /etc/pf.conf

2. Add rules for services you want:

Example: Allow SSH from anywhere:

pass in on egress proto tcp from any to any port 22

Example: Allow web server (HTTP + HTTPS):
pass in on egress proto tcp from any to any port { 80 443 }

Example: Block specific countries (advanced):
# This requires additional configuration and tables


3. Apply the changes:
pfctl -f /etc/pf.conf - load new rules
pfctl -e - enable PF if it's not already running
pfctl -s rules - show current rules to verify

Common PF Rules Examples

Allow SSH only:

set skip on lo0
pass in on egress proto tcp from any to any port 22
block in all

Allow SSH + Web Server:
set skip on lo0
pass in on egress proto tcp from any to any port { 22 80 443 }
block in all

Restrict SSH to your home network only:
set skip on lo0
pass in on egress proto tcp from 192.168.1.0/24 to any port 22
block in all

Allow nothing (maximum security):
set skip on lo0
block in all

Testing Your Firewall

Check if PF is running:
pfctl -s rules - should show your rules
pfctl -d - disable PF (temporarily)
pfctl -e - enable PF

Test from another computer: Try to connect to your SSH (port 22) or Web (port 80/443).
- If you allowed it: Connection should work
- If you blocked it: Connection should be refused

Advanced firewall topics? Proceed to Lesson 37: PF Firewall Advanced.

Article author: Arthur Isaev