Sub topic 6
Enabling the macOS firewall
This chapter assumes you can open System Settings, you have administrator access to your Mac, and you can run a command in Terminal with sudo. You do not need networking expertise. The chapter covers turning the application firewall on and checking that it is on. Stealth mode, blocking all incoming connections, and per-app rules are covered in the next chapter.
What the application firewall controls
A firewall decides which network connections your Mac accepts. The macOS application firewall works on incoming connections only. When another device on your network tries to connect to a program on your Mac, the firewall checks whether that program is allowed to accept the connection. It does not filter outgoing traffic. It also does not inspect the content of the traffic it allows.
The firewall is off by default on many Macs. A Mac with the firewall off still has protections such as sandboxed apps and a home router. Turning the firewall on adds a check at the Mac itself. That check matters most on networks you do not control, such as a café or a hotel.
Turn it on in System Settings
- Open System Settings from the Apple menu.
- Select Network in the sidebar.
- Select Firewall.
- Switch Firewall to on.
- Enter your administrator password or use Touch ID when asked.
The location of this setting has moved between macOS versions. On macOS Ventura and later it is under Network. On older versions it is under Security & Privacy. If you cannot find it, search for "Firewall" in the System Settings search field.
After you switch it on, the pane shows a status of on. The Options button opens the stealth mode, block-all, and per-app settings. Leave those at their defaults for now.
Check the state from Terminal
You can read the firewall state without opening System Settings. This command is read-only and needs no sudo.
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstateThe output is a sentence that says whether the firewall is enabled or disabled. The exact wording differs between macOS versions, so read the sentence instead of matching an exact string in a script.
If the firewall is off and you prefer Terminal, you can turn it on. This change needs administrator rights.
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate onRun the check command again afterward to confirm the change took effect.
What happens when an app wants to accept connections
With the firewall on, macOS may show a dialog the first time an app tries to accept incoming connections. The dialog asks whether to allow or deny that app.
| Your choice | Result |
|---|---|
| Allow | The app can accept incoming connections. macOS remembers the choice. |
| Deny | The app cannot accept incoming connections. The app may show errors for features that need them. |
Apps that are signed by a trusted developer or that ship with macOS are often allowed automatically. This is why you may see few prompts. An unsigned tool you build or download yourself is more likely to trigger a prompt.
Common errors
- The switch is greyed out. You are not signed in as an administrator, or a configuration profile from an employer or school manages the setting. Ask the administrator.
- A local server stops working for other devices. A development server or file-sharing app may have been denied. Open the firewall Options and change the rule for that app.
- The status says on, but you still see connections. The firewall allows signed apps and system services by default. That is expected behavior, not a fault.
- Assuming the firewall protects you everywhere. It does not stop malware you install yourself, phishing, or outgoing traffic. It addresses unwanted incoming connections only.
Exercises
Exercise
Which command reports whether the application firewall is enabled, and does it need sudo?
Show answer
Run /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate. It only reads the state, so it does not need sudo. Changing the state with --setglobalstate does need sudo.
Exercise
A colleague says the firewall will stop a malicious app on your Mac from sending your data to a remote server. Is that correct?
Show answer
No. The macOS application firewall filters incoming connections only. It does not filter outgoing traffic, so it does not stop an app that sends data out.