Packet Filter (PF) is OpenBSD’s system for filtering TCP/IP traffic and doing Network Address Translation. PF is also capable of normalizing and conditioning TCP/IP traffic and providing bandwidth control and packet prioritization.

To enable PF, we have to edit /etc/rc.conf.


To be able to do NAT, we have to edit /etc/sysctl.conf as well.


The main pf configuration file is /etc/pf.conf. We can use shorthands for interfaces, port numbers and addresses we use in this file, e.g.


services_tcp="{ 22, 53, 80 }"
services_udp="{ 53 }"

non_routeable_ips="{,,,, }"

Assume we have two interfaces, one of which is connected to the Internet, the other connected to a LAN. Performing NAT for the machines on the LAN is done like this.

nat on $internet_if from $lan_net to any -> $internet_ip

By default, we can deny all traffic. Specifying more specific rules later in the configuration file gives us the opportunity to allow certain traffic. For example, we may want to allow traffic from and to our LAN.

block all

pass in quick on $fixed_if from $fixed_net to any keep state
pass out quick on $fixed_if from any to $fixed_net keep state
Packet Filter (PF)
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *