View Other Checks


View Other Checks

How to Configure macOS Firewall to Block Unauthorized Connections

The macOS firewall comes disabled by default, but should be enabled whenever possible.

What Is the macOS Application Firewall?

Since 2007, all Macs have come with a built-in application layer firewall that is capable of blocking incoming connections unless they have been explicitly permitted by the end-user.

The firewall can be turned on within the sharing section in System Preferences

To turn on the Firewall simply unlock the pane and click Turn off Firewall

Once enabled, if a previously unknown process attempts to accept incoming connections you will be prompted with an alert that looks like the following:

Why Should the macOS Firewall Be Enabled?

The macOS firewall comes disabled by default. This is because by default, Apple does not ship any high-risk services that listen for connections on the public internet.

That said, over time, most users (especially technical users like developers) do install software or use macOS features that can listen and respond to connections on public networks. We believe it is important to enable the firewall to block outsiders from making incoming connections to your device, which can undermine its security.

How to Programmatically Determine the macOS Firewall State

There are two methods you can use to programmatically determine the macOS Firewall state. The first approach utilizes built-in macOS CLI tools and the terminal, whereas the second approach uses the osquery open-source project.

Using the Terminal

  1. Open the Terminal
  2. Type the command /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate --getblockall --getallowsigned --getstealthmode
  3. The output is self-explanatory, and demonstrated below:
$ /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate --getblockall --getallowsigned --getstealthmode
Firewall is enabled. (State = 1)
Block all DISABLED!
Automatically allow signed built-in software ENABLED
Automatically allow downloaded signed software ENABLED
Stealth mode disabled

Using Osquery

You can also use an open-source tool like osquery to determine the status of the macOS Firewall.

allow_signed_enabled = 1
     firewall_unload = 0
        global_state = 1
     logging_enabled = 1
      logging_option = 0
     stealth_enabled = 0
             version = 1.6

Additionally, osquery is capable of enumerating the apps, processes, and services that have been allowed to pinhole through the firewall.

SELECT path FROM alf_exceptions WHERE path LIKE '/Applications/%';
| path                                                                  |
| /Applications/                                             |
| /Applications/ |
| /Applications/                                              |

Kolide’s endpoint agent includes osquery’s functionality and automatically stores all information about Remote Login and other macOS settings as part of its built-in Inventory. Using Kolide, you can easily enumerate all the devices with this feature enabled.

How to Programmatically Enable the macOS Firewall

While we generally don’t recommend forcing the firewall to be on for all users (more on that later), there are two approaches should you decide to remotely manage this setting.

With the Command Line

If you can run scripts across your Macs, you can use the aforementioned socketfilterfw utility to programmatically set the firewall state.

Here is an example of a script that includes our recommended configuration.


echo " Enable Firewall"
sudo /usr/libexec/ApplicationFirewall/socketfilterfw \
  --setblockall off \
  --setallowsigned on \
  --setallowsignedapp on \
  --setloggingmode on \
  --setstealthmode on \
  --setglobalstate on

With Mobile Device Management (MDM)

If you use an MDM product like Apple Business Essentials, you can disable the entirety of the Sharing section in SystemPreferences with a .mobileconfig profile (using the payload below).

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
            <string>Configures Firewall settings</string>
    <string>Enable Firewall and ensuring logging/stealth mode is also enabled</string>
    <string>Enable Firewall</string>

End User Impacts of Forcing the Firewall To Be Enabled

While these are both effective ways of enabling the firewall, they can create new and more nuanced problems. For example, developers are often concerned that the firewall may be causing connectivity issues with important services, like those which run inside Virtual Machines or Docker containers.

If you force the firewall to be enabled at all times you may prevent a software engineer from correctly troubleshooting a pressing issue, forcing them to work around the instructions (disabling the MDM) or using their personal devices.

When you use the MDM to lock-out the end user from settings they can get frustrated and begin using their personal device

This is why Kolide recommends an approach where end users are reminded (not forced) to turn on the firewall if they’ve left it off too long.

How Does Kolide Remediate This Problem?

Automatically remediating this issue isn't necessarily the best way to go. Instead, consider following the Honest Security approach by blocking devices from authenticating to SaaS apps until they've fixed the problem.

Kolide's Okta Integration does exactly that. Onece integrated in your sign-in flow, Kolide will automatically associate devices with your users' Okta identities. From there, it can block any device that exhibits this problem and then provide the user, step-by-step instructions on how to fix it. Once fixed, Kolide immediately unblocks their device. Watch a demo to find out more.

Share this story:

Related Device Checks:

Block iCloud Private Relay

vpn, networking

Ensure Windows' Ransomware Protection is Enabled

ransomware, malware, windows-security-center

Find Unencrypted SSH Keys and Encrypt Them

ssh, developers, unencrypted-credentials, no-mdm-resolution
View More of Kolide's Checks
Book A Demo
Book A Demo