1162485Sjulian# $FreeBSD$ 2162485Sjulian# 3162485Sjulian# See pf.conf(5) and /usr/share/examples/pf for syntax and examples. 4162485Sjulian# Required order: options, normalization, queueing, translation, filtering. 5162485Sjulian# Macros and tables may be defined and used anywhere. 6162485Sjulian# Note that translation rules are first match while filter rules are last match. 7162485Sjulian 8162485Sjulian# Macros: define common values, so they can be referenced and changed easily. 9162485Sjulian#ext_if="ext0" # replace with actual external interface name i.e., dc0 10162485Sjulian#int_if="int0" # replace with actual internal interface name i.e., dc1 11162485Sjulian#internal_net="10.1.1.1/8" 12162485Sjulian#external_addr="192.168.1.1" 13162485Sjulian 14162485Sjulian# Tables: similar to macros, but more flexible for many addresses. 15162485Sjulian#table <foo> { 10.0.0.0/8, !10.1.0.0/16, 192.168.0.0/24, 192.168.1.18 } 16162485Sjulian 17162485Sjulian# Options: tune the behavior of pf, default values are given. 18162485Sjulian#set timeout { interval 10, frag 30 } 19162485Sjulian#set timeout { tcp.first 120, tcp.opening 30, tcp.established 86400 } 20162485Sjulian#set timeout { tcp.closing 900, tcp.finwait 45, tcp.closed 90 } 21162485Sjulian#set timeout { udp.first 60, udp.single 30, udp.multiple 60 } 22162485Sjulian#set timeout { icmp.first 20, icmp.error 10 } 23162485Sjulian#set timeout { other.first 60, other.single 30, other.multiple 60 } 24162485Sjulian#set timeout { adaptive.start 0, adaptive.end 0 } 25162485Sjulian#set limit { states 10000, frags 5000 } 26162485Sjulian#set loginterface none 27162485Sjulian#set optimization normal 28162485Sjulian#set block-policy drop 29162485Sjulian#set require-order yes 30162485Sjulian#set fingerprints "/etc/pf.os" 31162485Sjulian 32162485Sjulian# Normalization: reassemble fragments and resolve or reduce traffic ambiguities. 33162485Sjulian#scrub in all 34162485Sjulian 35162485Sjulian# Queueing: rule-based bandwidth control. 36162485Sjulian#altq on $ext_if bandwidth 2Mb cbq queue { dflt, developers, marketing } 37162485Sjulian#queue dflt bandwidth 5% cbq(default) 38162485Sjulian#queue developers bandwidth 80% 39162485Sjulian#queue marketing bandwidth 15% 40162485Sjulian 41162485Sjulian# Translation: specify how addresses are to be mapped or redirected. 42162485Sjulian# nat: packets going out through $ext_if with source address $internal_net will 43162485Sjulian# get translated as coming from the address of $ext_if, a state is created for 44162485Sjulian# such packets, and incoming packets will be redirected to the internal address. 45162485Sjulian#nat on $ext_if from $internal_net to any -> ($ext_if) 46162485Sjulian 47162485Sjulian# rdr: packets coming in on $ext_if with destination $external_addr:1234 will 48162485Sjulian# be redirected to 10.1.1.1:5678. A state is created for such packets, and 49162485Sjulian# outgoing packets will be translated as coming from the external address. 50162485Sjulian#rdr on $ext_if proto tcp from any to $external_addr/32 port 1234 -> 10.1.1.1 port 5678 51162485Sjulian 52162485Sjulian# rdr outgoing FTP requests to the ftp-proxy 53162485Sjulian#rdr on $int_if proto tcp from any to any port ftp -> 127.0.0.1 port 8021 54162485Sjulian 55162485Sjulian# spamd-setup puts addresses to be redirected into table <spamd>. 56162485Sjulian#table <spamd> persist 57162485Sjulian#no rdr on { lo0, lo1 } from any to any 58162485Sjulian#rdr inet proto tcp from <spamd> to any port smtp -> 127.0.0.1 port 8025 59162485Sjulian 60162485Sjulian# Filtering: the implicit first two rules are 61162485Sjulian#pass in all 62162485Sjulian#pass out all 63162485Sjulian 64162485Sjulian# block all incoming packets but allow ssh, pass all outgoing tcp and udp 65162485Sjulian# connections and keep state, logging blocked packets. 66162485Sjulian#block in log all 67162485Sjulian#pass in on $ext_if proto tcp from any to $ext_if port 22 keep state 68162485Sjulian#pass out on $ext_if proto { tcp, udp } all keep state 69162485Sjulian 70162485Sjulian# pass incoming packets destined to the addresses given in table <foo>. 71162485Sjulian#pass in on $ext_if proto { tcp, udp } from any to <foo> port 80 keep state 72162485Sjulian 73162485Sjulian# pass incoming ports for ftp-proxy 74162485Sjulian#pass in on $ext_if inet proto tcp from any to $ext_if user proxy keep state 75162485Sjulian 76162485Sjulian# assign packets to a queue. 77162485Sjulian#pass out on $ext_if from 192.168.0.0/24 to any keep state queue developers 78162485Sjulian#pass out on $ext_if from 192.168.1.0/24 to any keep state queue marketing 79