前提:INPUT和OUTPUT默认策略为DROP,最好在策略条目设定完后再设定;设定服务器主机IP地址为172.16.103.1。
1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的页面不允许访问;web服务器仅允许响应报文离开本机;
# iptables -A INPUT -d 172.16.103.1 -p tcp --dport 80 -m time --weekdays Mon -j REJECT # iptables -A INPUT -d 172.16.103.1 -p tcp --dport 80 -m string --algo kmp --string "admin" -j DROP # iptables -A INPUT -d 172.16.103.1 -p tcp --dport 80 -m state --state NEW -m limit --limit 100/second -j ACCEPT # iptables -A OUTPUT -s 172.16.103.1 -m state --state ESTABLISHED -j ACCEPT
2、在工作时间,即周一到周五的8:30-18:00,开放本机的ftp服务给172.16.0.0网络中的主机访问;数据下载请求的次数每分钟不得超过5个;
# iptables -A INPUT -d 172.16.103.1 -p tcp --dport 21 -m time --timestart 08:30 --timestop 18:00 --weekdays Mon,Tue,Wed,Thu,Fri -s 172.16.0.0/16 -m state --state NEW -j ACCEPT # iptables -A INPUT -d 172.16.103.1 -p tcp --dport 21 -m state --state RELATED -m limit --limit 5/minute -j ACCEPT # iptables -A INPUT -d 172.16.103.1 -p tcp --dport 21 -m state --state ESTABLISHED -j ACCEPT # iptables -A OUTPUT -s 172.16.103.1 -m state --state ESTABLISHED,RELATED -j ACCEPT
3、开放本机的ssh服务给172.16.x.1-172.16.x.100中的主机,x为你的座位号,新请求建立的速率一分钟不得超过2个;仅允许响应报文通过其服务端口离开本机;
# iptables -A INPUT -d 172.16.103.1 -p tcp --dport 22 -m iprange --src-range 172.16.4.1-172.16.4.100 -m state --state NEW -m limit --limit 2/minute -j ACCEPT # iptables -A INPUT -d 172.16.103.1 -m state --state ESTABLISHED -j ACCEPT # iptables -A OUTPUT -s 172.16.103.1 -m state --state ESTABLISHED -j ACCEPT
4、拒绝TCP标志位全部为1及全部为0的报文访问本机;
# iptables -A INPUT -d 172.16.103.1 -p tcp --tcp-flags all all -j DROP # iptables -A INPUT -d 172.16.103.1 -p tcp --tcp-flags all none -j DROP
5、允许本机ping别的主机;但不开放别的主机ping本机;
# iptables -A INPUT -d 172.16.103.1 -p icmp --icmp-type 0 -j ACCEPT # iptables -A OUTPUT -s 172.16.103.1 -p icmp --icmp-type 8 -j ACCEPT
设置默认策略:
# iptables -P INPUT DROP # iptables -P OUTPUT DROP # iptables -P FORWARD DROP