In this tutorial, we will see how to ban an IP address on your VPS server under Linux. We will use the firewall iptables.
Install iptables
To install iptables, let's use the package manager. You must have administrator access.
Installing iptables on Ubuntu
To install iptables on Ubuntu:
sudo apt-get install iptables
Installing iptables on Debian
To install iptables on Debian:
apt-get install iptables
Installing iptables on CentOS
To install iptables on CentOS:
sudo yum install iptables
Displays the list of IP bans
To display the list of banned IPs on iptables:
iptables -L
Ban an IP address on iptables
In the case of an IP address that attacks a site and/or a server, here is the command:
iptables -A INPUT -s XXX.XXX.XXX.XXX -j DROP
Don't forget to replace the IP address with the one you want to block.
You can verify that the address is banned with iptables -L
.
Deban an ip address on iptables
To unban an IP address, use the DROP command:
iptables -D INPUT -s XXX.XXX.XXX.XXX -j DROP