datocp
2022-05-04 12:16:56 +08:00
这几年踩过的坑,一般家用还算好用的是 nat ,但是如果没有 openwrt 这种完全定制化的固化,很多安全防护是很难做到的
1.iptables -P INPUT DROP
防火墙入方向要先拒绝,然后一个个允许。这问题当时在使用 vps 时傻眼了,默认 ACCEPT 怎么可以连接到基于公网的 ip
2.强制所有的 DNS 查询都经过网关,这样才可以做一些基于 dnsmasq 的访问限制
-A prerouting_rule -s 192.168.0.0/16 -p udp -m udp --dport 53 -j DNAT --to-destination 192.168.99.253
3.syn flood 抑制,这个 openwrt 默认就有了
iptables -F syn_flood
iptables -N syn_flood
iptables -A syn_flood -m limit --limit 100/s --limit-burst 50 -j RETURN
iptables -A syn_flood -j DROP
4.动态封禁扫描,可以用 hacker iptables recent 搜索一下,之前介绍的文章是用 iptables recent 模块实现,后来因为有了 ipset ,事情就更简单了,所有踩中陷阱的源 ip ,统统封禁 3 分钟。
iptables -I INPUT 3 -i eth0.2 -m set --match-set banned_hosts src -j DROP
iptables -I INPUT 4 -i eth0.2 -p udp -m multiport --dports 80,161,1863,5060 -j SET --add-set banned_hosts src
iptables -I INPUT 5 -i eth0.2 -p tcp -m multiport --dports 20,23,25,110,135,137:139,161,445,1080,2323,3128,3306,3389 -j SET --add-set banned_hosts s
ipset destroy banned_hosts
ipset -N banned_hosts hash:net timeout 180
5.集成 softether ,vpn 到内网再访问服务是个好习惯。避免突然有天发现端口被 ISP 封禁了。。。