How to block IP addresses

Category: Advanced (Command Line)  •  Est. reading time: 3 minutes

If a particular address is hammering your site with spam or bad traffic, you can block it so it never reaches you. How you do that depends on your setup. Here are the common routes, from easiest to most technical.

The Easy Way: cPanel IP Blocker

  1. Log in to cPanel and open IP Blocker in the Security section.
  2. Enter a single IP address or a range.
  3. Click Add. That address can no longer reach your site.

The .htaccess Way

On an Apache site you can block addresses in your .htaccess file with a line like Require not ip 203.0.113.5 inside your access rules. This is useful when you want the block to travel with your site’s files.

The Server Level

On a dedicated or self-managed server, a firewall such as CSF or iptables blocks traffic before it ever reaches your site. This is the most thorough option, and the one we manage for our server clients.

Careful not to lock yourself out. Never block a range that includes your own address, and double-check before blocking large blocks of IPs, since some legitimate visitors and services share addresses.

Under attack or seeing suspicious traffic? We will lock it down for you properly. Reach us at support@allydrez.com or 1-321-209-2004.

Ally Drez Web & IT Services home