如何安装和使用
安装lux仓库(该仓库包含xtables-addons所需的依赖环境) # wgethttp://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm # rpm
-ivh lux-release-7-1.noarch.rpm 安装xtables-addons。注意:必须先安装kmod-xtables-addons,再安装xtables-addons,因为后者依赖于前者。
#yum -y install kmod-xtables-addons # yum -y install xtables-addons 安装GeoIP数据库。目前,主要由2种获取GeoIP数据库的方式
(上面引用见末尾)
我下载源码 make总是报错,无奈找个上面仓库用现成的。
我安装了,服务器也重启了,iptables还是报错,lux仓库安装的xtables-addons不会生效(centos7)。
老实编译源码安装,我输入
iptables -I INPUT -m geoip --src-cc RU -j DROP
秒生效,把服务器干脱网了。
上面是阻止俄罗斯ip流量,奇怪成都服务器,整个国内ping失败。
VNC登录,执行:
sudo iptables -I INPUT -m geoip --src-cc CN -j ACCEPT
拯救成功!源码见下面
xtables-addons版本选择:
(Use xtables-addons-1.x if you need support for Linux < 3.7.
Use xtables-addons-2.x if you need support for Linux < 4.15.
Use xtables-addons<3.19 if you need support for Linux <=4.16.)
- 目前最新版本xtables-addons-3.27.tar.xz要求:
- iptables >= 1.6.0
- kernel-devel >= 5.4
- xtables-addons-2.15.tar:
- iptables >= 1.4.5
- kernel-devel >= 3.7
- xtables-addons-1.47.1.tar
- iptables >= 1.4.5
- kernel-devel >= 2.6.32
报错:
[root@VM-0-11-centos xtables-addons-2.15]# make install
Making install in extensions
make[1]: 进入目录"/root/spencer/xtables-addons-2.15/extensions"
Xtables-addons 2.15 - Linux 3.10.0-1160.119.1.el7.x86_64
if [ -n "/lib/modules/3.10.0-1160.119.1.el7.x86_64/build" ]; then make -C /lib/modules/3.10.0-1160.119.1.el7.x86_64/build M=/root/spencer/xtables-addons-2.15/extensions modules; fi;
make[2]: 进入目录"/usr/src/kernels/3.10.0-1160.119.1.el7.x86_64"
CC [M] /root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.o
/root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c: 在函数'tarpit_tcp4'中:
/root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c:295:3: 警告:传递'NF_HOOK'的第 3 个参数时在不兼容的指针类型间转换 [默认启用]
skb_dst(nskb)->dev, dst_output);
^
In file included from include/uapi/linux/netfilter_ipv6.h:11:0,
from include/linux/netfilter_ipv6.h:10,
from /root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c:45:
include/linux/netfilter.h:250:1: 附注:需要类型'struct sock *',但实参的类型为'struct sk_buff *'
NF_HOOK(uint8_t pf, unsigned int hook, struct sock *sk, struct sk_buff *skb,
^
/root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c:295:3: 警告:传递'NF_HOOK'的第 6 个参数时在不兼容的指针类型间转换 [默认启用]
skb_dst(nskb)->dev, dst_output);
^
In file included from include/uapi/linux/netfilter_ipv6.h:11:0,
from include/linux/netfilter_ipv6.h:10,
from /root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c:45:
include/linux/netfilter.h:250:1: 附注:需要类型'struct net_device ',但实参的类型为'int ( )(struct sk_buff *)'
NF_HOOK(uint8_t pf, unsigned int hook, struct sock *sk, struct sk_buff *skb,
^
/root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c :295:3: 错误:提供给函数'NF_HOOK'的实参太少
skb_dst(nskb)->dev, dst_output);
^
In file included from include/uapi/linux/netfilter_ipv6.h:11:0,
from include/linux/netfilter_ipv6.h:10,
from /root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c:45:
include/linux/netfilter.h:250:1: 附注:在此声明
NF_HOOK(uint8_t pf, unsigned int hook, struct sock *sk, struct sk_buff *skb,
[root@VM-0-11-centos xtables-addons-2.3]# makemake all-recursive
make[1]: 进入目录"/root/xtables-addons-2.3"
Making all in extensions
make[2]: 进入目录"/root/xtables-addons-2.3/extensions"
Xtables-addons 2.3 - Linux 3.10.0-1160.119.1.el7.x86_64
if [ -n "/lib/modules/3.10.0-1160.119.1.el7.x86_64/build" ]; then make -C /lib/modules/3.10.0-1160.119.1.el7.x86_64/build M=/root/xtables-addons-2.3/extensions modules; fi;
make[3]: 进入目录"/usr/src/kernels/3.10.0-1160.119.1.el7.x86_64"
CC [M] /root/xtables-addons-2.3/extensions/compat_xtables.o
CC [M] /root/xtables-addons-2.3/extensions/xt_CHAOS.o
/root/xtables-addons-2.3/extensions/xt_CHAOS.c: 在函数'xt_chaos_total'中:
/root/xtables-addons-2.3/extensions/xt_CHAOS.c :71:2: 错误:隐式声明函数'net_random' [-Werror=implicit-function-declaration]
if (!ret || hotdrop || (unsigned int)net_random() > delude_percentage)
^
cc1: some warnings being treated as errors
make[4]: *** [/root/xtables-addons-2.3/extensions/xt_CHAOS.o] 错误 1
make[3]: *** [module /root/xtables-addons-2.3/extensions] 错误 2
make[3]: 离开目录"/usr/src/kernels/3.10.0-1160.119.1.el7.x86_64"
make[2]: *** [modules] 错误 2
make[2]: 离开目录"/root/xtables-addons-2.3/extensions"
make[1]: *** [all-recursive] 错误 1
make[1]: 离开目录"/root/xtables-addons-2.3"
make: *** [all] 错误 2
我解决失败,那就直接关闭报错的模块:比如
注意到弹"错误""警告"都是同一个xt_TARPIT.c
关闭TARPIT模块再安装,即可。
/root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c:295:3: 警告
...
/root/spencer/xtables-addons-2.15/extensions/xt_TARPIT.c :295:3: 错误:提供给函数'NF_HOOK'的实参太少
skb_dst(nskb)->dev, dst_output);
先解压编译
bash
tar xvf xtables-addons-x.tar.xz
cd xtables-addons-x
./configure
然后编辑文件关闭TARPIT功能模块:
bash
vim ./mconfig
:/TARPIT 搜索
build_TARPIT=m 添加注释#
###build_TARPIT=m #关闭模块
vim使用搜索功能:
你可以使用 / 搜索特定的模式,然后使用 n 跳转到下一个匹配项,N 跳转到上一个匹配项
安装
make && make install
封禁陌生国家ip需要数据库下载:
$ cd geoip
$ ./xt_geoip_dl
#下载GeoIP数据库
使用旧版(比如2.x)如果提示失败
借用最新版3.27的脚本xt_geoip_dl
下载后继续用新版的处理脚本 xt_geoip_build
yum -y install perl-Text-CSV_XS #安装CSV格式转换器
mkdir -pv /usr/share/xt_geoip #创建数据库文件默认存储目录。使用RPM方式安装xtables-addons。必须将GeoIP数据存储在该路径下
./xt_geoip_build -D /usr/share/xt_geoip *.csv #进行格式转换
tree /usr/share/xt_geoip/ -L 1 #查询生成两个目录BE和LE,目录下保存的文件分别有.iv6和.iv4
/usr/share/xt_geoip/
├── BE └── LE
2 directories, 0 files
--------参考文献三
后面使用
sudo iptables -I INPUT -m geoip --src-cc CN -j ACCEPT
如果报错,按照提示把GeoIP数据库(/usr/share/xt_geoip里面)移动到相应目录即可
源码:
https://inai.de/projects/xtables-addons/
https://inai.de/projects/xtables-addons/geoip.php
很好的教程:
CentOS系统下配置xtables-addons来拒绝IP访问的方法
https://www.jb51.net/LINUXjishu/416836.html
二:https://www.cnblogs.com/hunttown/p/18322422
三:https://cloud.tencent.com/developer/article/1398920
工具:
或站长工具
报错:
- 一iptables类似这种提示
参考Centos 7 and spamassin installation.
终端执行
cpan -i IP::Country Mail::SpamAssassin::Plugin::Razor2 Razor2::Client::Agent Net::Ident Digest::SHA1 Geo::IP Net::CIDR::Lite Net::Patricia Net::DNS::Nameserver
嫌多就缺啥补啥 - 二
- 二