Here we show how easy it is to set up port forwarding (80 to 8080) on Mac OSX using ipfw from the Terminal. IPFW
is the built-in firewall of Mac OSX, and we can quickly set up a firewall rule to allow port forwarding. The ipfw command is deprecated in OS X Mountain Lion and later, but it has not been removed from Mavericks. If you run man ipfw
, a message will appear saying: This utility is DEPRECATED. Please use pfctl(8)
instead. While you may want to do port forwarding with pfctl
to future proof your solution, these instructions showing how to use ipfw
to do port forwarding will still work on OS X Mavericks.
Step 1: View Current Firewall Rules
1 |
sudo ipfw show |
Step 2: Add Port Forwarding Rule (80 to 8080)
The default port that Tomcat runs on is 8080, so here we show the command to do port fowarding from port 80 to 8080 (Tomcat’s default port). Obviously, this works for other ports as well, and you’d just have to adjust the command accordingly.
1 |
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in |
This is a temporary change, and it will revert once you reboot. If you want to make it permanent, you can create a lauch deamon for it.
Optional Remove Rule
If you want to remove your firewall rules run:
1 |
sudo ipfw flush |
Port Forwarding Using PFCTL (aka PF) on Mac OS X
The setup for pfctl
is similar to ipfw. Github user kujon
has created a nice guide to show how to set up port forwarding from port 80 to another port using pfctl
.
Subscribe To Our Newsletter
Join our low volume mailing list to receive the latest news and updates from our team.