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
          • Run FreeBSD on OpenBSD with vmd
          • 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 Handbook Style Guide
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Introduction
        • Logging Packets
        • Reading a Log File
        • Filtering Log Output

        PF Logging

        Introduction #

        When a packet is logged by PF, a copy of the packet header is sent to a pflog interface along with some additional data such as the interface the packet was transiting, the action that PF took (pass or block), etc. The pflog interface allows user-space applications to receive PF’s logging data from the kernel. If PF is enabled when the system is booted, the pflogd daemon is started. By default, pflogd listens on the ‘pflog0’ interface and writes all logged data to the ‘/var/log/pflog’ file.

        Logging Packets #

        Use the ’log’ keyword to log packets passing through PF. The ’log’ keyword causes all packets that match the rule to be logged. In the case where the rule is creating state , only the first packet seen (the one that causes the state to be created) will be logged.

        The options that can be given to the ’log’ keyword are:

        all

        Causes all matching packets, not just the initial packet, to be logged. Useful for rules that create state.

        to pflogN

        Causes all matching packets to be logged to the specified pflog interface. For example, when using spamlogd(8) , all SMTP traffic can be logged to a dedicated pflog interface by PF. The spamlogd daemon can then be told to listen on that interface. This keeps the main PF logfile clean of SMTP traffic which otherwise would not need to be logged. Use ifconfig to create pflog interfaces. The default log interface ‘pflog0’ is created automatically.

        user

        Causes the user ID and process ID associated with the local socket that the packet is sourced from/destined to (whichever socket is local) to be logged along with the standard log information.

        Options are given in parenthesis after the ’log’ keyword; multiple options can be separated by a comma or space.

        pass in log (all, to pflog1) on egress inet proto tcp to egress port 22
        

        Reading a Log File #

        The log file written by pflogd is in binary format and cannot be read using a text editor. tcpdump(8) must be used instead.

        To view the log file:

        doas tcpdump -n -e -ttt -r /var/log/pflog
        

        Reading the pflog file with tcpdump(8) does not show packets in real time. Read the ‘pflog0’ interface for a live view:

        doas tcpdump -n -e -ttt -i pflog0
        

        NOTE: When examining the logs, special care should be taken with tcpdump’s verbose protocol decoding (activated via the ‘-v’ command line option). tcpdump’s protocol decoders do not have a perfect security history. At least in theory, a delayed attack could be possible via the partial packet payloads recorded by the logging device. It is recommended practice to move the log files off of the firewall machine before examining them in this way.

        Additional care should also be taken to secure access to the logs. By default, pflogd will record 160 bytes of the packet in the log file. Access to the logs could provide partial access to sensitive packet payloads.

        Filtering Log Output #

        Because pflogd logs in tcpdump binary format, the full range of tcpdump features can be used when reviewing the logs. For example, to only see packets that match a certain port:

        doas tcpdump -n -e -ttt -r /var/log/pflog port 80
        

        This can be further refined by limiting the display of packets to a certain host and port combination:

        doas tcpdump -n -e -ttt -r /var/log/pflog port 80 and host 192.168.1.3
        

        The same idea can be applied when reading from the ‘pflog0’ interface:

        doas tcpdump -n -e -ttt -i pflog0 host 192.168.4.2
        

        Note that this has no impact on which packets are logged to the pflogd log file; the above commands only display packets as they are being logged.

        In addition to using the standard tcpdump filter rules, the tcpdump filter language has been extended for reading pflogd output:

        • ‘ip’ - address family is IPv4.
        • ‘ip6’ - address family is IPv6.
        • ‘on int’ - packet passed through the interface int.
        • ‘ifname int’ - same as ‘on int’.
        • ‘ruleset name’ - the ruleset/anchor that the packet was matched in.
        • ‘rulenum num’ - the filter rule that the packet matched was rule number num.
        • ‘action act’ - the action taken on the packet. Possible actions are ‘pass’ and ‘block’.
        • ‘reason res’ - the reason that ‘action’ was taken. Possible reasons are ‘match’, ‘bad-offset’, ‘fragment’, ‘short’, ’normalize’, ‘memory’, ‘bad-timestamp’, ‘congestion’, ‘ip-option’, ‘proto-cksum’, ‘state-mismatch’, ‘state-insert’, ‘state-limit’, ‘src-limit’ and ‘synproxy’.
        • ‘inbound’ - packet was inbound.
        • ‘outbound’ - packet was outbound.

        Example:

        doas tcpdump -n -e -ttt -i pflog0 inbound and action block and on wi0
        

        This displays blocked inbound packets on the wi0 interface in real time.

        Report a bug
        • Introduction
        • Logging Packets
        • Reading a Log File
        • Filtering Log Output