Mac OSX – How to open a port

Lets say you want to check if port 1234 is open, run the following command in the terminal. nmap is not available on mac osx by default.You can install it with Homebrew, my preferred package manager for mac osx. Visit homebrew site for instructions on Homebrew installation.

nmap -p 1234 localhost

This will output the status ..

Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).
PORT STATE SERVICE
1234/tcp closed ppp

To open this port, add the following line in /etc/pf.conf

sudo vim /etc/pf.conf

# Open port 1234 for TCP on all interfaces
pass in proto tcp from any to any port 1234
# You can limit the ip addresses .. replace any with allowed addresses ..

Save the file.

You can either restart the service of restart your mac.

sudo pfctl -f /etc/pf.conf

I restarted my mac and once I had the application running at port 1234, the status reported by nmap command (mentioned above) changed to ‘open’ and I was able to use my mac’s ip and port to access the application from another computer.

You can also use Network Utility – Port Scan to scan for open ports on your mac.

Advertisements

8 thoughts on “Mac OSX – How to open a port

  1. Am using El Capitan OSx version: 10.11.2.
    The commands above have not been successful.
    —-commands——-
    $ pass in proto tcp from any to any port 8000
    $nmap -p 8000 localhost

    —–Output—–
    Starting Nmap 7.31 ( https://nmap.org ) at 2017-02-20 18:07 EAT
    Nmap scan report for localhost (127.0.0.1)
    Host is up (0.00017s latency).
    Other addresses for localhost (not scanned): ::1
    PORT STATE SERVICE
    8000/tcp closed http-alt

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