Iptables防火墙string模块扩展匹配规则(防火墙开放ping端口)干货满满

随心笔谈11个月前发布 admin
96 0



String模块的作用是来匹配请求报文中指定的字符串,经常应用于拦截用户访问某些网站的场景,将防火墙当做路由器使用,例如上班时间不允许用户访问淘宝网站等等场景。

String模块的常用参数:

:指定要匹配的字符串。

:反向匹配。

:指定匹配的查询算法,有bm和kmp两种算法。

可以在参数前面加!号表示去反。

案例:当用户请求的数据报文中包含taobao.com,则拒绝通行,其余的正常放行。

用户通过防火墙流出然后访问目标端,因此需要在OUTPUT链添加规则。

1)首先来准备含有taobao.com数据报文的WEB网站。

1.安装httpd
[root@jxl-1 ~]# yum -y install httpd
[root@jxl-1 ~]# echo hahaha > /var/www/html/ha.html
[root@jxl-1 ~]# echo taobao.com > /var/www/html/taobao.html
[root@jxl-1 ~]# systemctl restart httpd
2.正常的两个页面
[root@jxl-1 ~]# curl 127.0.0.1/ha.html
hahaha
[root@jxl-1 ~]# curl 127.0.0.1/taobao.html
taobao.com

2)编写防火墙规则,拒绝数据包中包含taobao.com内容的数据包。

[root@jxl-1 ~]# iptables -t filter -I OUTPUT -p tcp -m string –string “taobao.com” –algo bm -j DROP

3)查看设置的防火墙规则。

[root@jxl-1 ~]# iptables -L -n -v –line-number
Chain INPUT (policy ACCEPT 7011 packets, 6693K bytes)
num pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 7310 packets, 11M bytes)
num pkts bytes target prot opt in out source destination
1 0 0 DROP tcp — * * 0.0.0.0/0 0.0.0.0/0 STRING match “taobao.com” ALGO name bm TO 65535

4)测试效果,发现hahaha的页面可以正常访问,taobao.com页面的请求将被拦截。

以上就是Iptables防火墙string模块扩展匹配规则的详细内容,更多关于Iptables防火墙string模块的资料请关注脚本之家其它相关文章!

您可能感兴趣的文章:Iptables防火墙自定义链表实现方式Iptables防火墙基本匹配条件应用详解Iptables防火墙四表五链概念及使用技巧详解Iptables防火墙iprange模块扩展匹配规则详解Iptables防火墙tcp-flags模块扩展匹配规则详解Iptables防火墙limit模块扩展匹配规则详解Iptables防火墙connlimit与time模块扩展匹配规则

© 版权声明

相关文章