Category filter
Script to enable/disable Firewall in macOS devices
The built-in Firewall on macOS devices prevents authorized computers and servers from connecting to your Mac. Admins users have the option to manually configure Firewall settings through the Network panel in System Settings. Organizations enable the Firewall on their macOS devices to ensure network security. In some exceptional circumstances, they might also need to turn off the Firewall. This document provides you with firewall script templates that help you configure Firewall settings on macOS devices remotely. These can be executed using Hexnode’s Execute Custom Script feature.
Script to turn on Firewall on a Mac
1 |
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 1 |
Script to turn off Firewall on a Mac
1 |
sudo defaults write /Library/Preferences/com.apple.alf globalstate -int 0 |
Navigate to System Preferences > Security & Privacy > Firewall on the device to verify the change. Admin credentials are needed to modify the Firewall settings from the device end.
Script to check Firewall status on a Mac
1 |
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate |
Executing the above command will retrieve the current firewall status of the macOS device. The script will output if the firewall is enabled (State 1) or disabled (State 0).