Open a port in OSX Mavericks’ Firewall

FirewallThe new firewall in Mavericks is great. For the common user. For a developer, not so much. If you are a Java developer like me, and you just need to open one port (say, 8080) so that the web application you’re working on is accessable from another computer, you can’t. I disabled the Firewall altogether for a few days, but it didn’t feel right.

I googled around and to make a long story short, here’s how to open port 8080 on any interface to any application on your OSX Mavericks installation in 3 steps:

sudo vim /etc/pf.conf

Then add the following lines at the end of the file:

# Open port 8080 for TCP on all interfaces
pass in proto tcp from any to any port 8080

Test (and, according to the documentation, load) your edits with:

sudo pfctl -vnf /etc/pf.conf

Reboot.

(I have found at least 5 pieces of voodoo to make the Firewall restart and reload, but none of them seemed to work reliably, so pardon the reboot)

You can close it by commenting out the lines in pf.conf and reboot again. If anybody knows of an easier way to do this, preferably in one terminal command, and without rebooting, let me know.

Hope this helps.

Advertisements

10 Responses to Open a port in OSX Mavericks’ Firewall

  1. Derek says:

    When I ran this command:

    sudo pfctl -vnf /etc/pf.conf

    It said there was bad syntax on this line:

    pass in proto tcp from any to any port 8080

  2. Joyce Babu says:

    Restarting the firewall via “System Preferences > Security & Privacy > Firewall > Turn Off Firewall” worked for me.

  3. […] had the same issue under OS X Yosemite (10.10.3). Found this blog post that provides clear instructions. We can’t use ipfw any more, as it’s deprecated. […]

  4. […] may help rolfje.wordpress.com/2014/05/10/… – mark setchell may 31 ’15 @ […]

  5. Julie Jones says:

    El Capitan: whole lotta no workie

  6. Rohit says:

    How do I add a line to the pf.conf. I am a newbie to mac

  7. rolfje says:

    The very first command in the article opens “vim”, an arcane text editor very commonly seen on Unix systems. You can use your arrow keys to move to the last line of the editor.

    To add the line, press “Shift-A” (your cursor should now be at the end of the last line. press “Enter” and Copy/Paste the lines from the article in your terminal window.

    To save the file and exit the editor, press “Esc”, then type “:wq” and hit “Enter”.

    If this doesn’t work please find a good vim tutorial online, there are quite a few good ones out there.

    (By the way I use vim regularly, but I’m not a fan. https://rolfje.wordpress.com/2008/04/05/the-vi-religion/ )
    😉

    Good luck!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s