BAN ip by iptables
-- Create banlist.txt
root@hosting:/home/hunzo/script# more banlist.txt
104.131.147.112
216.244.66.198
216.244.66.239
216.244.66.205
46.229.168.0/24
54.36.148.0/24
54.36.149.0/24
163.172.71.0/24
-- Check iptables rules
root@hosting:/home/hunzo/script# iptables -L -v -n
Chain INPUT (policy ACCEPT 322K packets, 19M bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 125K packets, 742M bytes)
pkts bytes target prot opt in out source destination
-- Create Script
root@hosting:/home/hunzo/script# ban=$(more banlist.txt)
root@hosting:/home/hunzo/script# for i in $ban; do echo iptables -A INPUT -s $i -j DROP ; done
iptables -A INPUT -s 104.131.147.112 -j DROP
iptables -A INPUT -s 216.244.66.198 -j DROP
iptables -A INPUT -s 216.244.66.239 -j DROP
iptables -A INPUT -s 216.244.66.205 -j DROP
iptables -A INPUT -s 46.229.168.0/24 -j DROP
iptables -A INPUT -s 54.36.148.0/24 -j DROP
iptables -A INPUT -s 54.36.149.0/24 -j DROP
iptables -A INPUT -s 163.172.71.0/24 -j DROP
-- exec script
root@hosting:/home/hunzo/script# for i in $ban; do iptables -A INPUT -s $i -j DROP ; done
-- check iptables rules
root@hosting:/home/hunzo/script# iptables -L -v -n
Chain INPUT (policy ACCEPT 322K packets, 19M bytes)
pkts bytes target prot opt in out source destination
0 0 DROP all -- * * 104.131.147.112 0.0.0.0/0
0 0 DROP all -- * * 216.244.66.198 0.0.0.0/0
0 0 DROP all -- * * 216.244.66.239 0.0.0.0/0
0 0 DROP all -- * * 216.244.66.205 0.0.0.0/0
0 0 DROP all -- * * 46.229.168.0/24 0.0.0.0/0
0 0 DROP all -- * * 54.36.148.0/24 0.0.0.0/0
0 0 DROP all -- * * 54.36.149.0/24 0.0.0.0/0
0 0 DROP all -- * * 163.172.71.0/24 0.0.0.0/0
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 126K packets, 742M bytes)
pkts bytes target prot opt in out source destination
root@hosting:/home/hunzo/script#
@2018-02-26 11:15
root@hosting:/home/hunzo/script# iptables -L -v -n
Chain INPUT (policy ACCEPT 412K packets, 25M bytes)
pkts bytes target prot opt in out source destination
0 0 DROP all -- * * 104.131.147.112 0.0.0.0/0
0 0 DROP all -- * * 216.244.66.198 0.0.0.0/0
0 0 DROP all -- * * 216.244.66.239 0.0.0.0/0
0 0 DROP all -- * * 216.244.66.205 0.0.0.0/0
3502 210K DROP all -- * * 46.229.168.0/24 0.0.0.0/0
309 18540 DROP all -- * * 54.36.148.0/24 0.0.0.0/0
120 7200 DROP all -- * * 54.36.149.0/24 0.0.0.0/0
0 0 DROP all -- * * 163.172.71.0/24 0.0.0.0/0
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 169K packets, 1024M bytes)
pkts bytes target prot opt in out source destinat
-- drop rules
'iptables -D INPUT -s 1.2.3.4 -j DROP'
1.2.3.4 = ip address