编译获取CN.iv4 CN.iv6 for iptables
下面的操作均基于ubuntu 20.04。由于技术不过关,并不能保证这个教程完全准确或是没有遗漏,请根据实际报错自行调整
安装xtables-addons
xtables-addons的官网是 https://inai.de/projects/xtables-addons/ 从中找到git地址,我们git下拉代码
git clone https://git.inai.de/xtables-addons
cd xtables-addons
编译需要一些依赖包,安装一下
sudo apt install iptables-dev pkg-config
由于我是在编译OpenWRT的机器上完成的操作,因此之前还安装过其他依赖包,这里一起放上来
sudo apt install build-essential ccache ecj fastjar file g++ gawk \
gettext git java-propose-classpath libelf-dev libncurses5-dev \
libncursesw5-dev libssl-dev python python2.7-dev python3 unzip wget \
python3-distutils python3-setuptools python3-dev rsync subversion \
swig time xsltproc zlib1g-dev
额外的,geoip的csv文件可能也需要下载一下,地址是 https://mailfud.org/geoip-legacy/ ,下载GeoIP-legacy.csv.gz,解压缩更改名称后备用
wget https://mailfud.org/geoip-legacy/GeoIP-legacy.csv.gz
gunzip GeoIP-legacy.csv.gz
mv GeoIP-legacy.csv GeoIP.csv
编译
有依赖包的情况下,编译很简单,依次执行
./autogen.sh
.configure
make
sudo make install
为了完成编译,可能需要执行这两个命令,来实现读取csv文件的功能
sudo -i
/usr/bin/perl -MCPAN -e'install Text::CSV_XS'
/usr/bin/perl -MCPAN -e'install Net::CIDR::Lite'
exit
将 GeoIP.csv 复制到geoip文件夹,并完成最后的编译
mv GeoIP.csv geoip
cd geoip
mkdir ivs
./xt_geoip_dl
./xt_geoip_build -D ivs
cd ivs
最后生成的内容就在xtables-addons/geoip/ivs目录下,CN.iv4和CN.iv6都在,完全可以应用于iptables当中了。例如
iptables -t mangle -A TEST -j RETURN -m geoip --destination-country CN
参考内容
https://gist.github.com/wen-long/b4d5622c09e9be542660
https://stackoverflow.com/questions/8578181/using-the-pkg-config-macro-pkg-check-modules-failing
http://manpages.ubuntu.com/manpages/bionic/man1/xt_geoip_build.1.html