pfctl cheat sheet

pfctl cheat sheet

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 but don’t load it)
pfctl -R -f /etc/pf.confLoad only the FILTER rules
pfctl -N -f /etc/pf.confLoad only the NAT rules
pfctl -O -f /etc/pf.confLoad only the OPTION rules

Clearing PF Rules & Counters #

Flushing rules does not influence or impact any already existing stateful connections
CommandDescription
pfctl -F allFlush ALL
pfctl -F rulesFlush only the RULES
pfctl -F queueFlush only QUEUE
pfctl -F natFlush only NAT
pfctl -F infoFlush all statistics that are not part of any rule
pfctl -zClear all 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 -v -s natShow NAT information and hit count
pfctl -s nat -i xl1Show NAT information for interface xl1
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

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 load -f /etc/pf.confLoad a new table definition
pfctl -t addvhosts -T show -viOutput stats for each IP address in table addvhosts
pfctl -t addvhosts -T zeroReset all counters for table addvhosts