iptable分三种情况,
在这台机器上做的限制是限制它本地的请求还是外面对它的请求,还有就是:它是否是一个转发的服务器,不同的话,就有input,output,forward,
当然端口也就有--dport ,--sport 区别
先开放你想让进入的 再drop 所有进入的
iptables -A INPUT -s 192.168.20.0/24 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j DROP
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP
iptables -A FORWARD -j DROP
---------------------------------------------------------------
#!/bin/sh
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/iptables -F -t filter
/sbin/iptables -F -t nat
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD DROP
/sbin/iptables -t nat -P PREROUTING ACCEPT
/sbin/iptables -t nat -P POSTROUTING ACCEPT
/sbin/iptables -t nat -P OUTPUT ACCEPT
/sbin/iptables -A OUTPUT -j ACCEPT
/sbin/iptables -A FORWARD -j ACCEPT
# ALLOW ALL in PRIVATE NET
/sbin/iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A INPUT -i eth1 -j ACCEPT
# NAT
/sbin/iptables -t nat -A POSTROUTING -s 172.1.0.0/24 -j SNAT --to-source 192.168.0.8
# SQUID
/sbin/iptables -A PREROUTING -t nat -p tcp -s 172.0.0.0/24 --dport 80 -j DNAT --to 172.0.0.1:3128
# External -->;Internal
#lj /sbin/iptables -A FORWARD -p tcp --dport 21 -j ACCEPT
#lj /sbin/iptables -A FORWARD -p udp --dport 53 -j ACCEPT
#lj /sbin/iptables -A FORWARD -p tcp --dport 80 -j ACCEPT
#lj /sbin/iptables -A FORWARD -p udp --dport 8000 -j ACCEPT
#lj /sbin/iptables -A FORWARD -p tcp --dport 25 -j ACCEPT
#lj /sbin/iptables -A FORWARD -p tcp --dport 110 -j ACCEPT
#lj /sbin/iptables -A FORWARD -p tcp --dport 4899 -j ACCEPT
#lj /sbin/iptables -A FORWARD -p tcp --dport 1863 -j ACCEPT
/sbin/iptables -A FORWARD -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A FORWARD -p tcp --dport 443 -j ACCEPT
/sbin/iptables -A FORWARD -p icmp -j ACCEPT
#=============Services(external-->;internal)===============
#SSH
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#======================Deny others=========================
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A INPUT -j DROP
# allow the third handshake
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
# exchange the other packets' "SOURCE" and "TARGET", and SEND it !!!
/sbin/iptables -A INPUT -j MIRROR
#===========================================================
#Dos
iptables -t filter -A INPUT -p icmp -m icmp --icmp-type 8 -m limit --limit 6/minute --limit-burst 2 -j ACCEPT
iptables -t filter -A INPUT -p icmp -m icmp --icmp-type 8 -j REJECT --reject-with icmp-port-unreachable
#syn-flood protection
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
#furtibe port scanner protection
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
阅读(1309) | 评论(0) | 转发(0) |