How to block an IP address?

Solution 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 8.8.8.8

(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