基本的iptables

1.iptables工作流程以及规则顺序
iptables过滤的规则顺序是由上而下,匹配即停止。
2.iptables的四表五链
四表: filter数据过滤、nat地址转换、raw状态跟踪、mangle包标记
五链:input 入站规则、output 出站规则、forward 转发规则、 prerouting 路有前规则、 portrouting 路由后规则。
3.iptables的常见生产应用
1.端口映射
2.把访问外网ip及端口映射到内网的某个服务端口
3.把访问LVS/nginx的外网vip及80端口请求映射到IDC负载均衡内部的ip及端口上。
4.大并发场景的iptables优化
net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_建立= 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_net_wait_=60
net_netfilter.nf_conntrack_tcp_timeout_time_wait_120
5.解决DDOS攻击的案例脚本

netstat -na|grep EST|awk -F “[ :]+” ‘{print $6}’|sort|uniq -c >>/tmp/a.log
while true
do
grep EST a.log|awk -F ‘[ :]+’ ‘{print $6}’|sort|uniq -c >/tmp/tmp.log
exec </tmp/tmp.log
while read line
do
ip=echo $line|awk "{print $2}"
count=echo $line|awk "{print $1}"
if [ $count -gt 100 ] && [ iptables -L -n|grep $ip|wc -l -lt 1 ]
then
iptables -I INPUT -s ipjDROP//Iiptablesecho"ip -j DROP //-I 将其封杀在iptables显示在第一条 echo "line is dropped" >>/tmp/dropip.log
fi
done
sleep
done
netstat -na|grep EST|awk -F “[ :]+” ‘{print $6}’|awk ‘{S[$1]++}END{for(i in S) print i,S[i]}’

posted @ 2020-09-01 20:45  zhanxiang-qq  阅读(129)  评论(0)    收藏  举报