使用 pfctl 屏蔽特定 ip

最近用一个软件的时候总是弹出更新,遂找了屏蔽更新 ip 的方法。

sudo vim /etc/pf.conf  # 编辑配置文件
#
# Default PF configuration file.
#
# This file contains the main ruleset, which gets automatically loaded
# at startup.  PF will not be automatically enabled, however.  Instead,
# each component which utilizes PF is responsible for enabling and disabling
# PF via -E and -X as documented in pfctl(8).  That will ensure that PF
# is disabled only when the last enable reference is released.
#
# Care must be taken to ensure that the main ruleset does not get flushed,
# as the nested anchors rely on the anchor point defined here. In addition,
# to the anchors loaded by this file, some system services would dynamically
# insert anchors into the main ruleset. These anchors will be added only when
# the system service is used and would removed on termination of the service.
#
# See pf.conf(5) for syntax.
#

#
# com.apple anchor point
#
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "debookee"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
anchor "debookee"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"

# 屏蔽ip
block drop from any to xxx.xx.xxx.x (要屏蔽的 ip)

最后使配置生效即可。

sudo pfctl -evf /etc/pf.conf