Sub topic 7
Stealth mode, blocking all incoming connections, and app rules
This chapter covers the three settings that tune the macOS application firewall after you turn it on: stealth mode, blocking all incoming connections, and per-app rules. It assumes you can navigate System Settings, have administrator access, and can run a command with sudo in Terminal. You should already know what the firewall does and how to enable it. This chapter is about what each option changes, when to use it, and where it stops helping.
Where these options live
In System Settings, open Network, then Firewall, and click Options. macOS asks for an administrator password or Touch ID. The Options sheet contains:
- A list of apps with an "Allow incoming connections" or "Block incoming connections" setting beside each one.
- Block all incoming connections
- Automatically allow built-in software to receive incoming connections
- Automatically allow downloaded signed software to receive incoming connections
- Enable stealth mode
Menu labels can differ slightly between macOS versions. The behavior described here applies to the application firewall in current releases.
The application firewall works at the level of apps, not ports. It decides whether a given program may accept incoming connections. It does not filter outgoing traffic, so it will not stop an app from contacting a server.
Stealth mode
Stealth mode makes your Mac stop answering probe traffic. Without it, a Mac that receives an ICMP ping or a connection attempt on a closed TCP or UDP port sends back a reply, such as an echo response or a "port closed" reset. Those replies tell a scanner that a machine is present at that address. With stealth mode on, the Mac stays silent on those probes.
What stealth mode changes:
- The Mac does not respond to ICMP ping requests.
- The Mac does not send "connection refused" replies for closed ports.
- Apps that are allowed to accept connections can still receive them.
What it does not change:
- It does not hide the Mac from local network discovery that Apple's services run on their own, such as Bonjour. A Mac advertising a shared service is still visible to its neighbors.
- It does not stop outgoing connections.
- It does not block traffic to an app you have explicitly allowed.
Stealth mode is most useful on networks you do not control, such as a café, hotel, or conference Wi-Fi. There, other devices on the same network can scan for hosts. It adds little on a home network behind a router that already hides your devices from the internet.
A practical side effect is that you cannot ping your own Mac from another device to test connectivity. If a colleague says your Mac "does not respond to ping", stealth mode is the likely cause.
Block all incoming connections
Block all incoming connections is the strictest setting. It refuses incoming connections to every app, including apps with an "Allow" rule. The exception is a short list of essential system services that macOS needs to work, such as DHCP (getting an IP address), Bonjour name handling, and IPsec.
Consequences of turning it on:
- File Sharing, Screen Sharing, Remote Login (SSH), and similar services stop accepting connections, even if switched on in Sharing settings.
- Per-app allow rules are ignored while the option is active.
- AirDrop and some Handoff or Continuity features may be affected on some versions, because they depend on incoming traffic.
- Normal browsing, email, and cloud apps keep working. They start the connection themselves, and the replies to them are not new incoming connections.
Use this option when you are on a hostile network and do not need to share anything, for example while traveling. Turn it off when you are home and want to use sharing features.
Per-app rules
The app list controls incoming connections app by app. Each entry is either Allow incoming connections or Block incoming connections.
How entries get added:
- When an app that is not signed or not covered by an automatic rule first tries to accept an incoming connection, macOS shows a dialog asking whether to allow it.
- You can add an app yourself with the + button, choosing it from Applications.
- You can remove an entry with the − button. The app then returns to the default behavior and macOS asks again next time.
The two automatic options
- Automatically allow built-in software to receive incoming connections lets Apple-supplied programs accept connections without a prompt.
- Automatically allow downloaded signed software to receive incoming connections lets apps with a valid code signature from a developer do the same.
Code signing proves who produced the app and that it has not been altered since. It does not prove the app is safe. A signed app can still be poorly written or malicious. If you want to see every request, turn this option off. You will then get a prompt for each new app, which is more work but gives you control.
Tying rules to the app's signature
The firewall stores each rule against the app's code signature. If an app is updated and its signature stays valid under the same developer identity, the rule normally continues to apply. If you modify an app yourself, or an app is re-signed with different credentials, macOS may treat it as a new program and ask again. If an unsigned app is modified, its rule can stop matching.
Using the command line
The socketfilterfw tool manages the same settings. Read-only checks need no special rights:
/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
/usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode
/usr/libexec/ApplicationFirewall/socketfilterfw --getblockallEach prints one line stating whether the setting is enabled or disabled. Changes need sudo:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setblockall offPer-app rules have their own flags. List the current rules, add an app, and then block or unblock it:
/usr/libexec/ApplicationFirewall/socketfilterfw --listapps
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /Applications/Safari.app
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --blockapp /Applications/Safari.app
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /Applications/Safari.appSafari is only a convenient example of an app path. Replace it with the app you are working on. --blockapp and --unblockapp set the rule for an app that is already in the list, so add it first.
The Terminal tool is useful for checking several Macs or for confirming that a setting took effect after you changed it in the interface. After you change firewall settings, run the --get commands again to confirm.
Choosing a configuration
| Situation | Stealth mode | Block all incoming | App rules |
|---|---|---|---|
| Home network, using file sharing or AirDrop | Optional | Off | Allow the apps you use |
| Public Wi-Fi, no sharing needed | On | On | Not used while block-all is on |
| Public Wi-Fi, one service must stay reachable | On | Off | Allow only that app |
| Development machine running a local server | Optional | Off | Allow the server binary, or accept the prompt |
A few general rules follow from the table:
- Turn on the firewall first. Stealth mode, block-all, and app rules only take effect when the firewall itself is on.
- Prefer the narrowest rule that does the job. Allowing one app is safer than leaving block-all off and allowing everything signed.
- Revisit the app list now and then. Remove entries for apps you uninstalled.
Common errors and edge cases
An app asks to accept connections on every launch. This often happens with unsigned tools or apps you built yourself. Each rebuild produces a new binary with a different identity, so the old rule no longer matches. Sign the build with a stable identity, or add the rule again after each build.
A sharing service does not work after enabling block-all. This is the expected result. Turn off block-all, or use a different network profile for these times.
Ping still works after enabling stealth mode. Check that the firewall is on with --getglobalstate. Also confirm that you are pinging the correct address. A VPN or a second network interface can mean the traffic arrives by a path you did not expect.
An app in the list is set to Allow but nothing connects. Check whether block-all is on. Also check that the app is actually listening. A firewall rule permits connections but does not start the service.
A command-line change does not show in System Settings. Close and reopen the Firewall pane, since it may not refresh while open.
A third-party firewall is also installed. Tools such as network filters and VPN clients can add their own rules. These work in addition to the macOS firewall and can produce results that neither tool explains alone. When diagnosing a problem, turn off one layer at a time.
What these options cannot do
- They do not control outgoing connections. Malware that connects out to a remote server is not stopped by any of these settings.
- They do not protect against phishing, malicious downloads, or a user who approves a harmful app.
- They do not help if the attacker has physical access to an unlocked Mac. Disk encryption and Find My cover the stolen-device case, which is why the firewall is one layer of three.
- Stealth mode hides a host from casual probing. It is not a substitute for turning off services you do not need.
Exercise
You are working at a conference and need to keep your Mac quiet on the Wi-Fi network. You do not need AirDrop or file sharing, but a colleague's ping to your Mac still gets replies. Which settings would you check and change, and what does each one do?
Show answer
First confirm the firewall is on with socketfilterfw --getglobalstate, because the other options only work when it is. Then turn on stealth mode so the Mac stops answering ping and closed-port probes, and check it with --getstealthmode. Because you need no sharing, you can also turn on Block all incoming connections, which refuses incoming connections to every app except essential system services and overrides any per-app Allow rules. Turn block-all off again when you return to a trusted network and want sharing back.
Exercise
A command-line tool you compile yourself keeps triggering the "accept incoming connections?" dialog even though you chose Allow last time. Why does this happen, and what can you do about it?
Show answer
Firewall rules are tied to the app's code signature. Each rebuild of an unsigned or ad hoc signed binary produces a different identity, so macOS no longer matches the earlier rule and prompts again. You can sign the tool with a stable signing identity so the rule keeps matching, or re-add the rule with sudo socketfilterfw --add and --unblockapp after each build.