命令

  1. # 查看配置文件
  2. sudo vi /etc/pf.conf
  3. # 关闭
  4. sudo pfctl -d
  5. # 开启+刷新规则
  6. sudo pfctl -evf /etc/pf.conf
  7. # 只刷新 更新规则
  8. sudo pfctl -s rules
  9. # 如何在命令行中刷新 PF 规则/NAT/路由表
  10. pfctl -F all
  11. # 如何在命令行中仅刷新 PF 规则
  12. pfctl -F rules

配置文件

举例一:屏蔽某几个端口的tcp

  1. NoRoutePorts = "{8081,8082, 8042, 8088, 50070}"
  2. ExtIF = "{en0, en5}"
  3. block in quick on $ExtIF proto tcp from any to any port $NoRoutePorts

参考:
https://zhuanlan.zhihu.com/p/44655145
https://man.linuxde.net/pfctl
https://blog.csdn.net/shuishen49/article/details/77587527
https://www.gwduan.com/web/computer/work-env/common/pf.html
https://www.zhihu.com/question/58516863/answer/1321535087
https://man.openbsd.org/pf.conf