Method of configuring xtables addons to deny IP access under CentOS system

Time:2020-10-31

Sometimes, the IP address of some countries has been trying to login or attack the server. It is necessary to analyze the suspicious IP first and then seal it with iptables. Delay is time-consuming and laborious. Now you can use xtables addons to block the source IP.
1. Preconditions
iptables >= 1.4.5
kernel-devel >= 3.7
2. Install the dependency package

Copy code

The code is as follows:

# yum install gcc gcc-c++ make automake unzip zip xz kernel-devel-`uname -r` iptables-devel perl-Text-CSV_XS

3. Install xtables addons

Copy code

The code is as follows:

# wget http://sourceforge.net/projects/xtables-addons/files/Xtables-addons/2.3/xtables-addons-2.3.tar.xz/download
# wget http://sourceforge.net/projects/xtables-addons/files/Xtables-addons/2.3/xtables-addons-2.3.tar.xz/download
# xz -d xtables-addons-2.3.tar.xz
# tar xvf xtables-addons-2.3.tar
# cd xtables-addons-2.3
# ./configure
# make
# make install

4. Geoip related packages

Copy code

The code is as follows:

# cd geoip
# ./xt_geoip_dl
# ./xt_geoip_build GeoIPCountryWhois.csv
# mkdir -p /usr/share/xt_geoip/
# cp -rp {BE,LE} /usr/share/xt_geoip/

5. Write iptables rules. If IP in Taiwan is rejected

Copy code

The code is as follows:

# iptables -I INPUT -m geoip –src-cc TW -j DROP