Skip to content
Menu

Mac Firewall Is Off

Asks the macOS application firewall whether it is on and whether stealth mode is on, and alerts when the firewall is off or, by default, stealth mode is off or unreadable. Read-only.

Mac firewall is off is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Mac firewall is off. Tell other MSPs how it worked for you.

Write a Review

LanguageBash
Runs onmacOS 13+; runs as root or a user
Needsbash 3.2, socketfilterfw
Read-onlyReads, changes nothing

What It Does

The script asks the macOS application firewall, through socketfilterfw, whether it is on, whether stealth mode is on (the Mac does not answer pings or probes on closed ports), and whether block all incoming connections is set. It alerts when the firewall is off or, when REQUIRE_STEALTH_MODE is true, when stealth mode is off or its state cannot be read.

Block all is reported only. It is a stricter choice some Macs make on purpose, so it never raises an alert. A Mac whose firewall tool is missing, or whose firewall state cannot be read, is skipped and not alerted.

It changes nothing. Pair it with enable-mac-firewall, which turns the firewall and stealth mode on.

Before You Run It

  • Set REQUIRE_STEALTH_MODE to false if you do not want stealth mode required, for example when a monitor pings the Mac.
  • An exit of 1 means the firewall is off or required stealth mode was not confirmed on.
  • Treat a block-all row as a fact to read. It is not a fault.
  • To fix an alert, run enable-mac-firewall as a dry run first.

Type and Risk

  • Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: Under 5 seconds.
  • Example answer: "Firewall off; stealth mode off"
  • Tested before listing on macOS 27 (Apple silicon VM) with /bin/bash 3.2, run as root, against its own test cases.

Inputs

Pass an input as an argument (--input-name value), as an environment variable named as listed, which is how most RMMs pass script variables, or change its default in the DEFAULT_ lines near the top of the script. An argument wins over an environment variable, which wins over the default.

  • REQUIRE_STEALTH_MODE: Alert when stealth mode is off. Default true.

Every script also takes DRY_RUN, OUTPUT_FORMAT (Text, Answer, Json or Csv), EXPORT_PATH and RESULT_FIELD, which writes the answer to an RMM custom field, unless the list above words one differently.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

test-mac-firewall.sh · 548 lines · 23.7 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.