.:[ the openbsd pf for SOHO users ]:. author: kisom 0x00 Introduction ================= A word of caution: this guide is based on OpenBSD 4.7. *** The pf syntax between previous versions of OpenBSD and 4.7 has changed DRASTICALLY in some cases. Therefore, besides the fact that it is just a good idea, I HIGHLY recommend you use the latest version of OpenBSD on your firewall system. *** OpenBSD is a phenomenal operating system guided by the philosophy of doing things right, local correctness, stability, and security. why use pf? what is pf? 0x01 hardware selection / sample hardware ========================================= A system running only pf and OpenBSD is a very lean system. The hardware required is therefore minimal. The Soekris net4501 is what I am currently using as my router / firewall - it features three 10/100 ethernet ports, a miniPCI and PCI port, a 133 MHz 486 processor, 64M of RAM, and a 4G CompactFlash card. You might consider using an older machine with as many NICs as you need segments - hard drive size is not important, and RAM can be in the range of 64M on up (128-256 is a comfortable range for most setups). Some quick terminology for labeling interfaces is in order. I use the following terms to describe interfaces: RED: connection to the outside world, aka the link to "the wild." GREEN: connection to the inside network, aka the link to your LAN. ORANGE: connection to machines inside your network that need access to the outside world, aka web servers and the like. This is commonly referred to as the DMZ. BLUE: connection to a wireless AP LAN - either a single AP plugged into here, or connected to a switch that the network of APs plugs into. I will be using my soekris as the reference hardware in this tutorial. I have a vpn1401 hardware crypto accelerator PCI card and a Intel PRO/Wireless 2200 802.11bg card added into mine, giving me the following network interfaces: iwi0: one of two RED interfaces; one of my network configurations requires I pull my WAN connection via wireless. sis0: GREEN sis1: ORANGE or BLUE sis2: the second of the two RED interfaces. Before you install OpenBSD on your firewall, you should answer the following questions: 1. What does my network architecture look like? 2. How many users will my firewall be supporting? Is my firewall hardware up to the task? Keeping state on a number of connections will increase your need for RAM, for example. 3. For any machines that will be in an ORANGE network, what are their MAC addresses and what IP addresses will they have? 4. Is the firewall machine going to have a monitor and keyboard attached, or will I be using a serial console? (Serial console set up in OpenBSD is covered in OpenBSD FAQ 7.6.) It might be wise to write up the dhcpd.conf that you will be using ahead of time, or at least plan it out, so that you have any fixed-address hosts set up. 0x02 pfctl and pf.conf ====================== The firewall is written up in /etc/pf.conf, and is controlled using the program pfctl. As usual, complete documentation may be found in the man pages; check out pf.conf(5) and pfctl(8). The important flags you will want to know at first for pfctl are -f specifies the pf.conf to use -e enable pf -d disable pf -n parse only to check for syntax errors -s show, which uses the following modifiers (I only list a few): queue : shows loaded queue rules rules : shows loaded filter rules states : shows the state tables info : shows filter information, such as stats and counters all : shows all the information pf has to show -F flush, which uses the same modifiers as show When you run pfctl, you will need to specify which file to use. The rc scripts are set up to automatically use /etc/pf.conf but any time you manually invoke pfctl, you will need to specify the file. For example, pfctl -f /etc/pf.conf will enable the firewall using /etc/pf.conf (note that the -e is optional), whereas to disable the firewall, pfctl -d /etc/pf.conf One of the things you will want to do often is check your pf.conf for proper syntax, which you would do with pfctl -n -f /etc/pf.conf pf.conf is a simple flat text file read from beginning to end. The last match for a rule or definition is the match that is used. 0x03 the initialization: macros and options =========================================== Much like computer languages allow the use of variables, OpenBSD allows the use of macros. (For those of you who speak perl, s/macros/shell variables/ as they are pretty much eqivalent, except that macros do not change during runtime.) These are extremely useful in defining the network interfaces: RED_IF="sis2" ORANGE_IF="sis1" GREEN_IF="sis0" There are some cool ways to use interface macros: ($RED_IF) will use the address of the interface $GREEN_IF:network will use the network attached to the interface $RED_IF:broadcast will use the broadcast address for the network attached to the interface Another use for macros might be to describe specific hosts: SSH_HOST="192.168.5.1" Lists are also allowed; a list is specified like such: "{ value0, value1, value2 }" Lists may be specified in a macro as well: ALLOWED_PORTS="{ ssh, dns, http, https }" All of these macro definitions should be at the top of the file, because they cannot be used until they have been defined. After defining the macros, you can specify any runtime options. Runtime options are set using set