I am running MacOS Mojave. I am wondering if there is an easy way to block an IP address.

For example, I can ping and telnet 53. Now, I want to block all access to so ping and telnet should both fail.

Btw, I’m not looking to use dns to this host. I can block it easily in /etc/hosts file but not all apps and services respect dns and hosts override. I’m looking for a non DNS block to implement.


1 Answer 1


Finally, I found a solution by using PF.

(1) edit PF configuration

sudo vim /etc/pf.conf

Append the following line to the file:

block drop from any to <IP Address>

For example: block drop from any to

(2) Load the config by running

sudo pfctl -f /etc/pf.conf

(3) Enable PF by running:

sudo pfctl -e

(*) If you want to disable PF, run:

sudo pfctl -d
  • Quick follow-up question: when I load the config, I get a warning that "pfctl: Use of -f option, could result in flushing of rules present in the main ruleset added by the system at startup. See /etc/pf.conf for further details." This is just enough to be alarming, but not enough for me to know if this problem applies or if in this case I am always reloading the main ruleset (your step 2), so everything is copacetic. Apr 13, 2022 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .