系統的INPUT和OUTPUT默認策略為DROP;
先把策略設置為DROP # iptables -t filter -P OUTPUT DROP # iptables -t filter -P INPUT DROP
1、限制本地主機的web服務器在周一不允許訪問;新請求的速率不能超過100個每秒;web服務器包含了admin字符串的頁面不允許訪問;web服務器僅允許響應報文離開本機;
周一不允許訪問: # iptables -t filter -I INPUT -d 192.168.0.130 -p tcp --dport 80 -m time ! --weekdays Mon -j ACCEPT # iptables -t filter -I OUTPUT -s 192.168.0.130 -p tcp --dport 80 -m time ! --weekdays Mon -j ACCEPT 請求速率最大為100個/秒: # iptables -t filter -R INPUT 1 -d 172.16.2.24 -p tcp --dport 80 -m connlimit ! --connlimit-above 100 -m time ! --weekdays Mon -j ACCEPT web服務器包含了admin字符串的頁面不允許訪問: # iptables -t filter -I OUTPUT 1 -s 172.16.2.24 -p tcp --sport 80 -m string --string "admin" --algo kmp -j REJECT web服務器僅允許響應報文離開本機:
2、在工作時間,即周一到周五的8:30-18:00,開放本機的ftp服務給172.16.0.0網絡中的主機訪問;數據下載請求的次數每分鐘不得超過5個;
# iptables -I INPUT 3 -s 172.16.0.0/16 -d 172.16.0.21 -p tcp --dport 21 -m limit --limit 5/minute -m time --timestart 08:30 --timestop 18:00 --weekdays Mon,Tus,Wed,Thu,Fri -j ACCEPT # iptables -I OUTPUT 3 -d 172.16.0.0/16 -s 172.16.0.21 -p tcp --dport 21 -m limit --limit 5/minute -m time --timestart 08:30 --timestop 18:00 --weekdays Mon,Tus,Wed,Thu,Fri -j ACCEPT
3、開放本機的ssh服務給172.16.x.1-172.16.x.100中的主機,x為你的座位號,新請求建立的速率一分鐘不得超過2個;僅允許響應報文通過其服務端口離開本機;
# iptables -I INPUT 4 -d 172.16.2.24 -p tcp --dport 22 -m iprange --src-range 172.16.2.1-172.16.2.100 -m limit --limit 2/minute -j ACCEPT
4、拒絕TCP標志位全部為1及全部為0的報文訪問本機;
# iptables -I INPUT 1 -p tcp --tcp-flags ALL ALL -j DROP # iptables -I INPUT 2 -p tcp --tcp-flags ALL NONE -j DROP
5、允許本機ping別的主機;但不開放別的主機ping本機;
# iptables -A OUTPUT -s 172.16.0.21 -p icmp --icmp-type 8 -jACCEPT # iptables -A INPUT -d 172.16.0.21 -p icmp --icmp-type 0 -jACCEPT
6、判斷下述規則的意義:
# iptables -N clean_in
新創建一條自定義鏈叫clean_in
# iptables -A clean_in -d 255.255.255.255 -p icmp -j DROP
# iptables -A clean_in -d 172.16.255.255 -p icmp -j DROP
丟棄所有同一物理網段或者子網以及172.16的icmp(或ping)協議包
# iptables -A clean_in -p tcp ! –syn -m state –state NEW -j DROP
丟棄tcp標記除syn以外所有連接狀態為新建的數據包
# iptables -A clean_in -p tcp –tcp-flags ALL ALL -j DROP
# iptables -A clean_in -p tcp –tcp-flags ALL NONE -j DROP
防止tcp NULL掃描
# iptables -A clean_in -d 172.16.100.7 -j RETURN
停止執行當前鏈中目標地址為172.16.100.7的后續Rules,并返回到調用鏈中
7、通過tcp_wrapper控制vsftpd僅允許172.16.0.0/255.255.0.0網絡中的主機訪問,但172.16.100.3除外;對所被被拒絕的訪問嘗試都記錄在/var/log/tcp_wrapper.log日志文件中;
# vim /etc/hosts.all 添加一行內容如下: vsftpd: 172.16. EXCEPT 172.16.100.3 # vim /etc/hosts.deny 添加一行內容如下: vsftpd: ALL : spawn /bin/echo `date` login attempt from %c to%s, %d >> /var/log/tcp_wrapper.log
原創文章,作者:Net19_口香糖,如若轉載,請注明出處:http://www.www58058.com/33499
寫的很好,排版也很棒,加油