iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -m connlimit --connlimit-above 10 -j REJECT
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
# 可以使用ab命令并发测试
ab -n 10000 -c 9 http://10.10.10.32/
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -s 10.10.10.3 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 10.10.10.0/24 -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
- 只允许除了10.10.10.3的主机外都能进行SSH连接
iptables -A INPUT -s ! 10.10.10.3 -p tcp --dport 22 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o eh0 -j ACCEPT
iptables -A FORWARD -p TCP ! --syn -m state --state NEW -j DROP
- 处理IP碎片数量,防止DDOS攻击,允许每秒100个
iptables -A FORWARD -f -m limit --limit 100/s --limit-burst 100 -j ACCEPT
- 设置ICMP包过滤, 允许每秒1个包, 限制触发条件是10个包
iptables -A FORWARD -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state INVALID -j DROP
iptables -A FORWARD -m state --state INVALID -j DROP
iptables-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables-A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -s 10.0.0.0/8 -j DROP
iptables -t nat -A PREROUTING -i eth0 -s 172.16.0.0/12 -j DROP
iptables -t nat -A PREROUTING -i eth0 -s 10.10.10.0/16 -j DROP
iptables -t nat -A PREROUTING -d 20.20.20.22 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 21 -j DROP
- 只禁用20.20.20.22地址的FTP连接,其他连接可以进行。
iptables -t nat -A PREROUTING -p tcp --dport 21 -d 20.20.20.22 -j DROP
iptables -A INPUT -p tcp -m multiport --dport 25,80,110,143 -j ACCEPT
iptables -A INPUT -p tcp --dport 20: -j ACCEPT
iptables -A INPUT -p tcp --dport 20:100 -j ACCEPT
iptables -A INPUT -p tcp --dport :20 -j ACCEPT
- 允许192.168.4.21-192.168.4.28段的ip
iptables -A FORWARD -p tcp -m iprange --src-range 192.168.4.21-192.168.4.28 -j ACCEPT
# 固定公网IP
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to-source 218.29.30.31
# 非固定IP
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
# 开启路由转发
echo 1 >/proc/sys/net/ipv4/ip_forward
# 修改/etc/sysctl.conf
net.ipv4.ip_forward = 1
# 直接转换ip
iptables -t nat -A PREROUTING -i eth0 -d 218.29.30.31 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.6
# 转换ip和端口
iptables -t nat -A PREROUTING -i eth0 -d 218.29.30.31 -p tcp --dport 2346 -j DNAT --to-destination 192.168.1.6:22