If you have just one IP address that you want to block you can use the following method:
# iptables -I INPUT -s 122.174.12.228 -j DROP
This command will add an entry into your iptables configuration file, instructing it to drop any packets that come from the IP 122.172.9.222. If you face numerous attacks you are better of using a slightly more automated method to add the IPs from your ban list. To do that create the following script:
#!/bin/sh
for i in $(< banned_IPs.cfg) ; do
iptables -I INPUT -i eth1 -s "$i" -j DROP
done
for i in $(< banned_IPs.cfg) ; do
iptables -I INPUT -i eth1 -s "$i" -j DROP
done
Save the script into a file named something like banned_IPs.sh and grant it executable privileges:
# chmod +x banned_IPs.sh
Now create a file called banned_IPs.cfg and enter the list of IP addressed you want to block, each in a new line:
122.174.12.228
129.122.10.23
111.154.84.130
Now run the script banned_IPs.sh to have the IP addresses you want blocked added to the list of banned IPs in iptables:
# ./banned_IPs.sh
No comments:
Post a Comment