Enable and verify the macOS built-in firewall from Terminal for a host that will expose services publicly.
Run from Terminal on the Mac:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate onThis turns on the application firewall (State = 1).
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setblockall off
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setallowsigned on--setblockall offkeeps inbound traffic blocked only by firewall policy, not globally dropped.--setstealthmode onhides host responses to unsolicited probes.
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getblockall
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getallowsignedExpected:
- Firewall is enabled. (State = 1)
- Firewall has block all state set to disabled.
- Firewall stealth mode is on
- Firewall allows signed applications to receive connections (or equivalent)
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setloggingmode on
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --listappsUse listapps to inspect what is currently allowed/blocked by app path in the firewall.
nmap -Pn <public-ip> -p 22,80,443,8080,9001For this project, you typically want only:
- 22 reachable for admin SSH
- 80/443 reachable for Caddy
- 8080/9001 not publicly reachable
macOS firewall is host-level only. If this Mac is behind provider networking (VPS firewall/security group), that layer still needs port policy set to match the same intent.