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.


The sample scripts provided below are adapted from third-party open-source sites.

Script to turn on Firewall on a Mac

Firewall enabled using the firewall script on a mac

Script to turn off Firewall on a Mac

Firewall disabled using the firewall script on a mac

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

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).


  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository