OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • General PFCTL Commands
        • Loading PF Rules
        • Clearing PF Rules & Counters
        • Output PF Information
        • Maintaining PF Tables

        pfctl cheat sheet

        Synopsis #

        Run administrative pfctl commands as root or with doas. Translation is part of the unified ruleset; use pfctl -sr to inspect it. Parse a candidate before loading it.

        General PFCTL Commands #

        CommandDescription
        pfctl -dDisable packet-filtering
        pfctl -eEnable packet-filtering
        pfctl -qRun quietly
        pfctl -vRun more verbose than normal
        pfctl -v -vRun even more verbose

        Loading PF Rules #

        CommandDescription
        pfctl -f /etc/pf.confLoad /etc/pf.conf
        pfctl -n -f /etc/pf.confTest the rules (parse /etc/pf.conf without loading it)
        pfctl -N -f /etc/pf.confLoad the ruleset without DNS name resolution

        Clearing PF Rules & Counters #

        Flushing only rules preserves existing states. `pfctl -F all` also flushes states and disrupts established connections; use it only with a deliberate recovery plan.
        CommandDescription
        pfctl -F allFlush ALL
        pfctl -F rulesFlush only the RULES
        pfctl -F infoFlush all statistics that are not part of any rule
        pfctl -zClear per-rule counters

        Output PF Information #

        CommandDescription
        pfctl -s rulesShow filter information
        pfctl -srShow filter information (alternative)
        pfctl -v -s rulesShow filter information with hit count
        pfctl -vvsrShow filter information with rule numbers
        pfctl -s queueShow QUEUE information
        pfctl -s labelShow LABEL information
        pfctl -s stateShow contents of the STATE table
        pfctl -s infoShow statistics for state tables and packet normalization
        pfctl -s allShow everything

        Use Troubleshoot PF, NAT, and Routing to work through connectivity failures.

        Maintaining PF Tables #

        CommandDescription
        pfctl -t addvhosts -T showShow table addvhosts
        pfctl -vvsTablesView global information about all tables
        pfctl -t addvhosts -T add 192.168.0.5Add entry to table addvhosts
        pfctl -t addvhosts -T add 192.168.0.0/16Add a network to table addvhosts
        pfctl -t addvhosts -T delete 192.168.0.0/16Delete network from table addvhosts
        pfctl -t addvhosts -T flushRemove all entries from table addvhosts
        pfctl -t addvhosts -T killDelete table addvhosts entirely
        pfctl -t addvhosts -T replace -f /etc/addvhostsReload table addvhosts on the fly
        pfctl -t addvhosts -T test 192.168.0.140Find IP address 192.168.0.140 in table addvhosts
        pfctl -t addvhosts -vT showOutput stats for each IP address in table addvhosts
        pfctl -t addvhosts -T zeroReset all counters for table addvhosts
        Report a bug
        • Synopsis
        • General PFCTL Commands
        • Loading PF Rules
        • Clearing PF Rules & Counters
        • Output PF Information
        • Maintaining PF Tables