centos7 配置iptables 防火墙,防DDOS和CC攻击

香港云服务器

安装iptables
yum install iptables

安装iptables-services
yum install iptables-services

编辑iptables配置表
vi /etc/sysconfig/iptables

配置表内的内容
# Generated by iptables-save v1.4.21 on Sat Apr 17 19:43:29 2021
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
# Completed on Sat Apr 17 19:43:29 2021
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp –syn –dport 20021 -m connlimit –connlimit-above 30 –connlimit-mask 0 -j DROP
-A INPUT -p tcp –syn –dport 20013 -m connlimit –connlimit-above 30 –connlimit-mask 0 -j DROP
-A INPUT -m state –state NEW -m tcp -p tcp –dport 0:65535 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p udp –dport 0:65535 -j ACCEPT

重启服务

service network restart

命令参考

-A INPUT -p tcp –syn –dport 22 -m connlimit –connlimit-above 50 –connlimit-mask 0 -j DROP
说明输入的目标端口是22,也就是访问sftp本机22端口的流量,如果连接数大于50,则DROP流量,connlimit-above这个是连接数的统计,

上一篇
下一篇