Iptables防火墙connlimit模块扩展匹配规则

Iptables防火墙connlimit模块扩展匹配规则

connlimit模块的作用是限制请求报文对特定服务的并发连接数限制的,例如Telnet服务,默认情况下没有并发连接数的限制,可以允许n个客户端同时连接,如果应用了connlimit模块,可以对并发连接数进行限制。

connlimit模块常用参数:

  • --connlimit-upto:如果现有连接数小于或等于设置的并发连接数值,那么就放行。
  • --connlimit-above:如果现有连接数大于设置的并发连接数值,那么就放行。

案例:每个客户端主机仅允许同时对本机发起两个ssh连接。

数据流入的操作,在INPUT链的filter表添加相应的规则。

1)编写具体的防火墙规则

[root@jxl-1 ~]# iptables -t filter -I INPUT -p tcp --dport 22 -m connlimit --connlimit-above 2 -j REJECT

2)查看设置的规则

[root@jxl-1 ~]# iptables -L -n -v --line-number 
Chain INPUT (policy ACCEPT 52358 packets, 43M bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 REJECT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22 #conn src/32 > 2 reject-with icmp-port-unreachable

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 52598 packets, 68M bytes)
num   pkts bytes target     prot opt in     out     source               destination 

3)测试效果

同时登陆两个ssh没问题,第三个时就提示无法连接了。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44953658/article/details/125689857