How can I turn on the macOS firewall from a script
I'm setting up a new Mac Mini and I am using a script assembled from commands that I've accumulated over the years to set defaults
, create directory structures, install software, and otherwise customize my Macs the way I want them. The first command--to turn on the firewall--is failing to do anything. How is the firewall currently turned on, in Catalina?
The command I'm using is
sudo defaults write /Library/Preferences/com.apple.alf globalstate -integer 1
This is the same thing I'm finding by Googling (or an alternate form with -int
instead of -integer
).
If it has not changed, what could be preventing it from working?
macOS now uses the pf
firewall (from OpenBSD). Since Mac OS X Lion (10.7) circa 2012, the firewall ipfw
was deprecated in favor of pf
The command to disable the pf
firewall is:
% sudo pfctl -d
For full command line options for pfctl
see man pfctl
.