iptables 通用

通用:
iptables :
//nmap-xmas
iptables -I INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP

//nmap-push
iptables -I INPUT  -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP

// Null
iptables -I INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables -I INPUT  -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
iptables -I INPUT  -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP



iptables防止ssh暴力猜解
基于端口,使用iptables的connlimit模块
iptables -I INPUT -p tcp - -syn - -dport 22 -m connlimit - -connlimit-above 2 -j REJECT
一条指令即可以搞掂, - -connlimit-above 2表示只允许一个客户开启二个会话,与sshd_config 设置的区别,sshd_config只能设定一个用户最多尝试几次密码
用putty测试,开启到第三次,显示网络不可用


同样也可以设定web服务访问设限
iptables -I INPUT -p tcp - -syn - -dport 80 -m connlimit - -connlimit-above 30 -j REJECT
这样即可



丢弃无效数据包
 iptables -I INPUT -m conntrack --ctstate INVALID -j DROP

 端口转发
 iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 25 -j REDIRECT --to-port 2525

 屏蔽HTTP服务Flood攻击
 iptables -I INPUT -p tcp --dport 80 -m limit --limit 100/minute --limit-burst 200 -j ACCEPT

 防止SYN Flood (拒绝服务攻击)
 iptables -I FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT

 iptables -A INPUT -p icmp -i eth0 -j DROP    禁止ping
 iptables -A INPUT -p icmp -icmp-type echo-request -i eth1 -j DROP   #死ping

 允许访问回环网卡
 iptables -A INPUT -i lo -j ACCEPT
 iptables -A OUTPUT -o lo -j ACCEPT

 限制并发连接数
 iptables -A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 3 -j REJECT

iptables -t nat -A POSTROUTING -o eth1 -s 192.168.0.226 -j MASQUERADE
#允许 192.168.0.226通过eth1 IP伪装出外网

iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.4 -p tcp --dport 25 -j MASQUERADE
#允许 192.168.0.4通过eth0 伪装访问外网的 25端口



posted @ 2019-10-29 14:21  walkersss  阅读(168)  评论(0编辑  收藏  举报