OpenBSD PF Logging and Monitoring - Beginner Guide

Contents
OpenBSD PF Logging and Monitoring - Beginner Guide
Why Logging Matters
Step 1: View Basic PF Logs
Step 2: View Detailed Logs
Step 2: Enable and Configure Logging
Step 3: Log Rotation
Step 4: Analyzing Logs

OpenBSD PF Logging and Monitoring - Beginner Guide

OpenBSD's PF firewall keeps logs of what it's blocking and allowing. Here's how to view and use those logs.

Why Logging Matters

Security monitoring: Logs show you what kind of attacks your firewall is blocking.
Troubleshooting: If something isn't working as expected, logs show why.
Audit trail: Logs keep a record of network activity for security analysis.

By default, OpenBSD enables logging in PF, so you don't need to configure much to get started.

Step 1: View Basic PF Logs

The easiest way to see PF activity:

pfctl -s log - show PF log summaries

You'll see output like:
blocking in on egress0 from 203.0.113.5 to 192.168.1.1 port 46826\n ... (snip many lines)\n blocking in on egress0 from 185.220.101.1 to 192.168.1.1 port 58972\n

This shows: Attempts to connect to your computer from specific IP addresses and ports.

pfctl -s rules - show current PF rules (for context of what's being blocked/allowed)

Step 2: View Detailed Logs

For more detailed information:

pfctl -s info - show PF information (states, statistics, etc.)

pftop - real-time graphical monitor of PF activity (requires X Window System or terminal support)

To exit pftop: Press q

Step 2: Enable and Configure Logging

PF logging is enabled by default, but you can control what's logged:

In /etc/pf.conf, add logging to your rules:

Example: Log SSH connections:

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

Example: Log all traffic:
pass in on egress proto tcp from any to any port { 22 80 443 } log


After editing: Apply changes:
pfctl -f /etc/pf.conf
pfctl -e (if PF isn't running)

Step 3: Log Rotation

Log files can grow very large. OpenBSD uses newsyslog to manage them.

The configuration file: /etc/newsyslog.conf

Default settings: Logs are rotated daily, kept for 7 days, compressed.

To manually rotate logs:
newsyslog -f /etc/newsyslog.conf

To view rotated logs: They're typically in /var/log with dates in filenames

Common log files:
/var/log/messages - general system messages
/var/log/security - security-related events
/var/log/pflog - PF firewall logs (the special one!)

Step 4: Analyzing Logs

View the PF log file directly:
cat /var/log/pflog - shows PF logs (use less or more for large files)

Search for specific things:
grep "blocking" /var/log/pflog - show only blocked connections
grep "192.168.1.100" /var/log/pflog - show connections from your IP
grep "port 22" /var/log/pflog - show SSH connection attempts

Count blocking attempts:
grep -c "blocking" /var/log/pflog - count how many times things were blocked

Top blocking IPs:
grep "blocking in" /var/log/pflog | grep -oP "from \K[0-9.]+" | sort | uniq -c | sort -rn | head

(This shows which IP addresses are trying to connect to your computer most frequently)

Advanced PF topics? Proceed to Lesson 23: PF Advanced Rules.

Next: OpenBSD SSH Hardening - 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

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: