I am looking to implement a rule like the following iptables rule on my Mac, to redirect traffic from my development workstation (hosting a development copy of a Ruby on Rails project) to another host on my LAN that is running the PostgreSQL database server. Without having to change the database.yml config file on my local copy of the code:

iptables -t nat -I PREROUTING -d -p tcp --destination-port 5432 -j DNAT --to-destination

After some brief googling, I came up with this, which seems to work great.

echo "rdr pass on lo0 inet proto tcp from any to port 5432 -> port 5432" | sudo pfctl -ef -

I am not sure that it is the best way, which is why I am posting here. I would love to learn the best way to do this on Mac.

I did get this warning, though I don't know that it actually flushed any rules:

pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.

No ALTQ support in kernel
ALTQ related functions disabled
pfctl: pf already enabled

From the man page, -f is just telling it to parse the file, which I am sending in via stdin.

Any discussion, improvements, or hints would be great!

|improve this answer|||||

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .