Skip to content

Instantly share code, notes, and snippets.

@Flushot
Created August 21, 2018 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flushot/4707cbf1f0a10012af044905d2271c2c to your computer and use it in GitHub Desktop.
Save Flushot/4707cbf1f0a10012af044905d2271c2c to your computer and use it in GitHub Desktop.
Block IP addresses with macOS/BSD PF firewall
#
# Blocks list of IP addresses using macOS/BSD PF firewall.
#
# Enable: sudo pfctl -ef ./pf_block.conf
#
# Disable: sudo pfctl -d (completely disable firewall)
# sudo pfctl -f /etc/pf.conf (reset rules)
#
blocked_ips = "{ \
1.2.3.4 \
5.6.7.8 \
}"
set block-policy return
block out proto tcp to { $blocked_ips } port { 80, 443 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment