Sub topic 5
What a firewall does and does not do
This chapter assumes you can open System Settings, run a command in Terminal, and use sudo. It covers the concept only. The next chapter walks through turning the macOS firewall on.
The working model: incoming connections
A network connection is a conversation between two programs. One program starts it (the client), and the other waits for it (the server). A program that waits is said to listen on a port, a numbered door on your Mac. For example, File Sharing listens on port 445, and Remote Login (SSH) listens on port 22.
A firewall is software that decides which incoming connections are allowed to reach those listening programs. Your Mac is usually a client. It opens connections out to websites and mail servers. The firewall matters when something else, such as a device on the same Wi-Fi network, tries to open a connection to your Mac.
What the macOS firewall does
The macOS application firewall works per application, not per port. You tell it whether a given app may accept incoming connections. When an unlisted app tries to listen, macOS can ask you to allow or deny it. Apps signed by Apple or by a trusted developer can be allowed automatically, depending on your settings.
This design has a practical effect. You manage a short list of apps, such as "Allow incoming connections for this app", instead of a list of port numbers.
What a firewall does not do
The most common mistake is to treat a firewall as general protection. It is not. Here are its main limits.
| Situation | Does the firewall help? |
|---|---|
| A stranger on café Wi-Fi tries to connect to a service on your Mac | Yes. Incoming connections are the firewall's job. |
| You open a malicious attachment, and the program connects out to an attacker | No. The firewall is built around incoming connections, and the macOS application firewall does not filter outgoing ones. |
| You enter your password on a phishing site | No. The firewall cannot tell a real site from a fake one. |
| Someone steals your Mac and reads the disk | No. That is a data-at-rest problem, which FileVault addresses. |
| A trusted app has a bug that attackers can exploit | Limited. If you allowed the app to accept connections, the firewall lets them through. |
Two points are worth remembering:
- Allowed means allowed. If you permit an app to receive connections, the firewall passes that traffic through. It does not inspect what the traffic contains.
- No listener, nothing to block. On a default Mac with most sharing services turned off, few programs are listening at all. The firewall is a second barrier in front of services that you may turn on later, deliberately or by accident.
Seeing what is listening
You can see which programs are waiting for connections. This command lists TCP listeners and the programs that own them:
sudo lsof -iTCP -sTCP:LISTEN -n -PEach row shows a program name, its process ID, and the port in the NAME column, for example *:22 (LISTEN). A listener on * accepts connections from any address. One on 127.0.0.1 accepts only connections from your own Mac, which the outside network cannot reach.
If the list is short and every entry is something you recognize, your exposure is small. An entry you cannot explain is worth looking up before you decide to allow or block it.
Where it fits
Each of the three features in this tutorial covers a different risk. FileVault protects data if the Mac is stolen. Find My helps you locate or lock a missing Mac. The firewall limits what the network can reach while you are using the Mac. None of them replaces the others, and none of them stops phishing or malware you install yourself.
Exercise
You are on hotel Wi-Fi and have File Sharing turned on. Another guest tries to connect to your Mac. Separately, malware you installed yourself connects out to a remote server. Which of these can the macOS application firewall help with, and why?
Show answer
It can help with the guest's attempt, because that is an incoming connection to a listening service, which the firewall controls. It does not help with the malware's outgoing connection, because the macOS application firewall filters incoming connections only. The better fix for the first case is to turn off File Sharing when you do not need it.