Block Access to Particular IP Address on Mac

Vyshakh Babji
RingCentral Developers
2 min readJul 2, 2019

Recently, I was testing my WebRTC SDK for Disaster Recovery. I hit a roadblock when I wanted to block access to a few IP addresses on the go while running the DR tests. Fortunately, I found out the solution after digging through several stack overflow articles and reading through the manual for OSX terminal.

Here is how you could block certain IP addresses on the fly if you are ever hit with this roadblock.

  1. You need to edit the PacketFilter Configuration file. You can find this file in the path /etc/pf.conf
$ sudo vim /etc/pf.conf

2. Add the IP Address you need to block

block drop from any to [IP ADDRESS] Example:  ### block ip addressblock drop from any to 192.168.1.1

3. Quit VIM and load the config file by running the below command:

$ pfctl -e -f /etc/pf.conf
  • e is for enabling the packet filter
  • -f is for loading the rules contained in the file

You have successfully blocked access to the IP address.

4. Now, if you want to disable the rule, just run this:

$ pfctl -d

That’s it. Now you are ready to rock and roll :)

If you’re looking to learn more- then here are some other resources you can check out:

1. Block list table (IP, Mac, email, name, username)
2. How to edit the hosts to block IP address?
3. Why is IP to MAC address translation needed?
4. How to Block 100,000+ Individual IP addresses

For more awesome tutorials checkout our blog, or to learn more about the RingCentral Developers Program and start building cool integrations with voice, SMS, team messaging, meetings fax, and more — visit https://developers.ringcentral.com/

--

--