PF port forwarding not working

firewallNetwork

I have the following rule in a file in /etc/pf.anchors/

rdr pass on lo0 inet proto {udp,tcp} from any to self port 25 -> 127.0.0.1 port 1025

The intention is to forward all local traffic to port 25 onto port 1025, this is so sent emails can be captured before they are sent for testing email delivery on websites locally.

I then have added rdr-anchor "foo" and load anchor "foo" from "/etc/pf.anchors/foo" into /etc/pf.conf.

When I run pfctl -v -n -f /etc/pf.conf I get the following:

Loading anchor foo from /etc/pf.anchors/foo
rdr pass on lo0 inet proto udp from any to 127.0.0.1 port = 25 -> 127.0.0.1 port 1025
rdr pass on lo0 inet proto udp from any to 10.0.1.3 port = 25 -> 127.0.0.1 port 1025
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port = 25 -> 127.0.0.1 port 1025
rdr pass on lo0 inet proto tcp from any to 10.0.1.3 port = 25 -> 127.0.0.1 port 1025

So it looks as if it should be working, however if I run an nmap scan on the port it says closed, or if I send a test email with echo "This is the body of a text test-mail" | mail -s "Email test" test@test.com the email is not caught, but also doesn't seem to get sent.

The most strange thing is that I have pretty much the same configuration for pf on my work Mac and the forwarding works fine.

Any ideas would be great as I don't even really know how to debug this issue.

Best Answer

Turns out that I'm special and the issue wasn't with pf at all. The problem was that postfix wasn't started! It'd still be interesting to know a way to test port forwarding though if anybody knows a tool for that.