开启 macOS 防火墙隐身模式
用 socketfilterfw --setstealthmode 让 Mac 不响应 ping 和端口探测,公共 Wi-Fi 上更安全。
运行 sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on,再用 --getstealthmode 验证。
01命令
命令
$ sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on && sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode02作用说明
隐身模式下,macOS 应用防火墙会直接丢弃 ping、关闭端口探测等主动数据包,而不是回复“拒绝”,端口扫描器会以为这台机器不在线。它与按应用放行的规则互为补充:若防火墙尚未开启,可先用 --setglobalstate on 打开。命令末尾的 --getstealthmode 会输出当前状态,方便写进配置脚本做确认。
03风险
!注意: 开启隐身模式后 Mac 不会回应 ping,在可信的局域网里排查问题可能因此变麻烦。
04撤销
撤销
$ sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode off05来源
- socketfilterfw(8) man page依据: Man page for socketfilterfw listing the firewall verbs including --setstealthmode and --getstealthmode, alongside --setglobalstate for the application firewall.
- socketfilterfw(8) - application firewall utility依据: Mirrors the socketfilterfw man page with the setstealthmode/getstealthmode verbs for the macOS application firewall.
最后验证: 2026-09-19 · 分类: 安全与隐私