In order to block an IP or a class of IPs on your Linux server you need to use iptables tools (administration tool for
IPv4 packet filtering and NAT) and netfilter firewall. First you need to log into shell as root user.
To block an IP address you need to type the command as follows:
You can also unblock an IP by suppling -r parameter:
Here’s the code for the script: