开启 macOS 防火墙隐身模式

用 socketfilterfw --setstealthmode 让 Mac 不响应 ping 和端口探测,公共 Wi-Fi 上更安全。

macOSmacOS网络安全加固安全中风险
运行 sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on,再用 --getstealthmode 验证。

01命令

命令
$ sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode on && sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode

02作用说明

隐身模式下,macOS 应用防火墙会直接丢弃 ping、关闭端口探测等主动数据包,而不是回复“拒绝”,端口扫描器会以为这台机器不在线。它与按应用放行的规则互为补充:若防火墙尚未开启,可先用 --setglobalstate on 打开。命令末尾的 --getstealthmode 会输出当前状态,方便写进配置脚本做确认。

03风险

风险中风险
使用条件Application Firewall present on all modern macOS; sudo.
!注意: 开启隐身模式后 Mac 不会回应 ping,在可信的局域网里排查问题可能因此变麻烦。

04撤销

撤销
$ sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode off

05来源

  • socketfilterfw(8) man page
    Xcode Man Pages (keith.github.io) · technical · 2026-09-17
    依据: Man page for socketfilterfw listing the firewall verbs including --setstealthmode and --getstealthmode, alongside --setglobalstate for the application firewall.
  • socketfilterfw(8) - application firewall utility
    ManPagez · technical · 2026-09-17
    依据: Mirrors the socketfilterfw man page with the setstealthmode/getstealthmode verbs for the macOS application firewall.

最后验证: 2026-09-19 · 分类: 安全与隐私

06相关方案