Going deep into IPFW as FreeBSD's alternative packet filter: rule-number based syntax, tables, and loading kernel modules with kldload. You will also compare pf vs IPFW vs ipfilter, then use tcpdump, ngrep, and netstat for packet analysis and network troubleshooting.

In the previous episode 12, you mastered pf and NAT. Now we explore alternative packet filtering: IPFW, plus a comparison with pf and ipfilter. Not every requirement is the same, and choosing the right tool is part of an administrator's craft.
IPFW has a long history in FreeBSD and is known for its highly precise, rule-number based syntax. This episode also introduces packet analysis tools — tcpdump, ngrep, and netstat — which become your eyes on the network layer.
IPFW manages traffic with numbered rules. The number determines evaluation order — small numbers are evaluated first. These rules live in the kernel and are managed with the ipfw command.
IPFW is a kernel module that needs to be loaded:
kldload ipfw
kldstat | grep ipfwTo load it automatically at boot, add it to /etc/rc.conf:
sysrc firewall_enable="YES"
sysrc firewall_type="open"Warning
When the ipfw module is loaded, by default all traffic is blocked until rules are added. Make sure permissive rules already exist, or you'll be cut off from your administrative session. Use firewall_type="open" first as a safe starting point while learning.
ipfw add 100 allow ip from any to any via lo0
ipfw add 200 allow tcp from any to me dst-port 22
ipfw add 300 allow ip from me to any
ipfw add 400 deny ip from any to anyEach rule has a unique number. The rule allow tcp from any to me dst-port 22 opens SSH, and deny ip from any to any at the end becomes the default that denies.
View active rules, add them, and remove them:
ipfw list
ipfw add 500 count ip from any to any
ipfw delete 500
ipfw flushipfw flush removes all rules — use it very carefully because it can cut the network.
Danger
ipfw flush without replacement rules will lock down all connections. Before flushing, prepare a rules file that can be reloaded: ipfw -q flush then ipfw -q -f /etc/ipfw.rules.
IPFW also supports tables for dynamic address lists:
ipfw table 1 create type addr
ipfw table 1 add 203.0.113.7
ipfw add 1000 deny ip from table\(1\) to anyIPFW tables are updated at runtime without reloading rules — a useful pattern for dynamic blacklists, like pf tables.
| Aspect | pf | IPFW | ipfilter |
|---|---|---|---|
| Syntax | Declarative, macros | Rule numbers | AT&T-like |
| Origin | OpenBSD (adopted) | FreeBSD native | External |
| Ease of use | High | Moderate | Moderate |
| Stateful | Yes, built-in | Via keep-state | Via state |
| NAT | nat/rdr | nat via fwd | map |
| Best for | General firewalls | Complex sequential policies | Legacy/compatibility |
Info
For new projects, pf is the most comfortable and fully supported choice. IPFW remains relevant for environments already using rule numbers that need explicit ordering control. ipfilter fits better for compatibility with existing configurations.
tcpdump is the standard packet analysis tool. Examples of its use:
tcpdump -i em0 -n
tcpdump -i em0 -n port 80
tcpdump -i em0 -n host 192.168.1.100-i selects the interface, -n disables name resolution, and filters like port or host narrow down the capture.
Success
tcpdump -n -i pflog0 is the perfect partner for pf: the firewall log contains details of rejected connections. The combination drastically speeds up security troubleshooting.
ngrep searches for patterns in packet payloads — like grep for network traffic:
ngrep -d em0 "GET /"
ngrep -d em0 -W byline "password"ngrep is useful for verifying protocol contents, for example confirming the HTTP request you sent is correct.
netstat displays connection tables, interface statistics, and routing:
netstat -an
netstat -Lan
netstat -rnnetstat -Lan lists listening sockets — a quick way to check which services are open. netstat -rn displays the routing table.
Info
netstat -Lan gives a complete list of open ports on the system. Compare it with your firewall rules to find services accidentally exposed to the public.
When there's a connection problem, follow this order of tools:
ifconfig em0 — make sure the interface and IP are correct.netstat -rn — make sure the routing makes sense.ping and traceroute — test the path.tcpdump -i em0 — see the packets actually traveling.ifconfig em0
netstat -rn
ping -c 3 8.8.8.8
tcpdump -n -i em0 icmpIn this episode 13, you learned IPFW with its rule-number syntax and tables, compared pf vs IPFW vs ipfilter, and covered the packet analysis tools tcpdump, ngrep, and netstat. You now have two built-in firewalls in your arsenal, plus the ability to analyze what's happening on the network.
Key takeaways:
ipfw list for inspection.kldload or firewall_enable in rc.conf.tcpdump and ngrep are your eyes; netstat -Lan maps open ports.In the next episode, episode 14, we'll cover OpenSSL, TLS & certificates — creating certificates with openssl, managing the trust store with ca_root_nss, hardening SSH with ed25519, and tunneling for secure access. Transport-layer security starts here.