MacOS – Command Line Firewall

command linefirewallmacosSecurityterminal

I have decided to add a firewall to my computer and have heard of applications such as 'Little Snitch' which help to give me control of inbound and outbound connections on my mac running macOS Sierra. Is there (free) application which would allow me to configure the settings via the command line? The default firewall is also an option, however, I would like to determine the ports myself and preferably the server address that is sending or receiving data from my computer like little snitch allows.

To review what I want, Is there an application which would allow me to block ingoing and outbound connections on my mac through the command-line while allowing me to say what ports and addresses are allowed to communicate on my computer? It would also be good if the application is free.

Best Answer

There is, and it comes with macOS by default.

Little Snitch is an application firewall, that's a whole different story. It blocks applications from accessing the network.

Assuming you want to block ports and servers, just configure pf from the command line to do what you want. Start by reading through "man pfctl", or e.g. How to block abusive IP addresses with pf in OpenBSD?

If you want to have a GUI after all, you might want to check out the (free) IceFloor to configure pf.

To determine the ports yourself and preferably the server address that is sending or receiving data from your computer use the build in command "nettop".