OSX and unix like systems use pf instead of iptables and tc. Here are my frequently used commands. 

pfctl
sudo pfctl -F all -ef /etc/pf.anchors/dhval.pf 
  • -e = Enable PF
  • -d = Disable PF
  • -F all = Flush all rules
  • -s all | nat | rules = Info, all | nat | rules
  • -p = name of the program

Create a pflog interface and monitor all packets logged on it
ifconfig pflog create 
tcpdump -nn -e -ttt -i pflog0
tcpdump -nn -ttt -i en0 src port 22
 pf  does not forward packets between interfaces.  
sysctl -a | grep forwarding
sysctl -w net.inet.ip.forwarding=1   # Enable fwd

net.inet.ip.forwarding=1
net.inet6.ip6.forwarding=1 

sudo sysctl -w net.inet.ip.forwarding=1
sudo sysctl -w net.inet6.ip6.forwarding=1

Forward any connection to google.com:22 to localhost:22

rdr only accepts incoming packets. First route those packets to lo0, then add a rdr rule there (which will catch them as they will be routed in from "somewhere") to send them to your local ssh server.

keep state information allows return traffic for those connections to pass back
Order of rules                                     Scrub > NAT > RDR > PASS

The order is necessarily rdr stuff, then filter stuff (like pass), but chronologically the 2nd rule will hit first (on $Out),
which will then activate the first rule (on lo0).
# Output interface
Out = en0
Packets = "proto tcp from $Out to any port 22"

Step "2". Rdr those same packets that were routed to lo0 below

rdr pass log on lo0 $Packets -> 127.0.0.1

Step "1". Route new IPv4 TCP connections leaving $Out to lo0

pass out on $Out route-to lo0 inet $Packets keep state

Forward requests from 192.168.99.100:80 to 127.0.0.1:8000. This is how I'd do it in linux using iptables
iptables -t nat -A OUTPUT -p tcp --dport 80 -d 192.168.99.100 -j DNAT --to-destination 127.0.0.1:8000

Re-routing packets using pf. 

rdr pass on vnic0 inet proto tcp from any to 10.211.55.2 port 49201 -> 127.0.0.1 port 49201

pass out on en1 route-to lo0 proto tcp to justin.tv port {80, 443} keep state

In Mac you need to manually configure an alias for each ip address

sudo ifconfig lo0 10.0.0.1 alias
sudo ipfw add fwd 127.0.0.1,9090 tcp from me to 10.0.0.1 dst-port 80

(The alias to lo0 seems to be the missing part)

If you'd like a (fake) domain to point to this new alias then make sure /etc/hosts contains the line:

10.0.0.1 www.your-domain.com


http://help.unc.edu/help/how-to-configure-a-firewall-for-mac-os-x-ipfw-for-snow-leopard/

PF vs IPTABLES 

In IPFW and iptables, the first rule in a ruleset what matches a packet "wins" - and next rulesets are not evaluated. In the PF the packet is matched with all rules and the last rule that matches the packet "wins".

in PF the default state is "deny everything". You add rules step-by-step allowing passing some packets. In contrast in IPFW, the default state is open and the "deny everything is usually the last rule”. 

PF or packet filter is used in bad world after licensing conflict with ipfw. It is like a programmatic language where you have scheduler class and queues, combination of tc (transmission control)  & iptables. 

Iptables has various tables at play, each with different chains that packets traverse, whereas pf just processes the packets straight down to the config file. Only if a rule contains the “quick” option does pf stop the actual processing and take action before hitting the end of the set of rules. On the other hand if a packet makes it all the way to the end of the config file, the last action specified from a rule that matched this packet is taken.

With iptables things are different, packets are processed by various “chains” in different order, depending on the source and destination in the actual packet. For example, normal outgoing packets are processed by the output chain on the table. Rules within this chain can create processing to jump over to a different set of rules on a user-defined chain for example, or might even take such an action on a packet. When a packet matches a rule, processing on that chain stops without hesitation and the action is taken into effect. 


GUI frontends
References :

https://calomel.org/pfconfig.html
http://www.openbsd.org/faq/pf/filter.html
http://www.freebsd.org/doc/handbook/firewalls-pf.html
http://home.nuug.no/~peter/pf/en/index.html
http://blog.scottlowe.org/2013/05/15/using-pf-on-os-x-mountain-lion/
https://discussions.apple.com/thread/5685827
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/pf.conf.5.html
http://murusfirewall.com/Documentation/OS%20X%20PF%20Manual.pdf

Forward packet between interfaces :-

<a href="http://jurjenbokma.com/ApprenticesNotes/redirectingsshthroughpf.html">http://jurjenbokma.com/ApprenticesNotes/redirectingsshthroughpf.html
http://serverfault.com/questions/421261/os-x-10-8-redirecting-locally-initiated-ssh-connections-to-localhost22
http://www.openbsd.org/faq/pf/rdr.html
http://superuser.com/questions/473039/pfctl-port-forwarding-in-mac-osx


<a href="http://www.onlamp.com/pub/a/bsd/2003/03/06/ssnopenbsd.html?page=2">http://www.onlamp.com/pub/a/bsd/2003/03/06/ssn_openbsd.html?page=2
https://support.apple.com/en-us/HT200188
http://kfigiela.github.io/2014/11/07/using-native-os-x-nat-with-virutalbox/
https://forums.openvpn.net/topic11401.html
https://discussions.apple.com/thread/6645172