=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- title: Blocking IP Addresses with Caddy date: 2026-02-17 16:30:00 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Did you know that there's a Wikipedia page [0] that lists all of the assigned `/8` IPV4 address blocks? A person, if they were so inclined, could take this list (or a subset of it [1]) and block all of those IP addresses from accessing their website using Caddy's `remote_ip` matcher (or whatever the equivalent is in your web server of choice). As an example, let's say that we want to block all of the IP addresses that are assigned to the United States Department of Defense for no [2] particular [3] reason [4] whatsoever. To do that, we can add the following lines to our Caddyfile: ```caddy @blocked_ips { remote_ip 6.0.0.0/8 7.0.0.0/8 11.0.0.0/8 21.0.0.0/8 22.0.0.0/8 26.0.0.0/8 28.0.0.0/8 29.0.0.0/8 30.0.0.0/8 33.0.0.0/8 55.0.0.0/8 214.0.0.0/8 215.0.0.0/8 } handle @blocked_ips { respond 403 } ``` If we want to be really cheeky (as the cartoon dogs my kids are obsessed with like to say), we could even redirect them to another website: ```caddy handle @blocked_ips { redir https://www.archives.gov/founding-docs/constitution-transcript 302 } ``` Before I get emails about how pointless this probably is, I already know. It won't prevent someone from accessing your site—or cause anyone to *care* about your site—if they use a VPN or Tor or their home network or their smartphone, but for a few lines of config, it's nothing if not a statement that I'd argue is worth making these days. --- [0]: https://en.wikipedia.org/wiki/List_of_assigned_/8_IPv4_address_blocks [1]: https://en.wikipedia.org/wiki/List_of_assigned_/8_IPv4_address_blocks#List_of_/8_blocks_assigned_to_the_United_States_Department_of_Defense [2]: https://apnews.com/article/immigration-enforcement-minnesota-4d1499fc5962ab880f3816259e04bdbf [3]: https://apnews.com/article/minnesota-immigration-enforcement-shooting-crackdown-surge-173e00fa7388054e98c3b5b9417c1e5a [4]: https://apnews.com/article/immigration-minnesota-boy-father-detained-342f319fafb766d13afe07f5bcc1f112 --- EOF