系統的INPUT和OUTPUT默認策略為DROP; iptables -P INPUT DROP iptables -P OUTPUT DROP 1、限制本地主機的web服務器在周一不允許訪問;新請求的速率不能超過100個每秒;web服務器包含了admin字符串的頁面不允許訪問; web服務器僅允許響應報文離開本機; [root@node3 ~]# iptables -A INPUT -d 192.168.1.116 -p tcp --dport 80 -m time --weekdays Mon -m limit --limit 100/second -m string --algo kmp --string 'admin' -j DROP [root@node3 ~]# iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT [root@node3 ~]# iptables -L -v Chain INPUT (policy ACCEPT 56 packets, 3716 bytes) pkts bytes target prot opt in out source destination 0 0 DROP tcp -- any any anywhere node3 tcp dpt:http TIME on Mon limit: avg 100/sec burst 5 STRING match "admin" ALGO name kmp TO 65535 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 31 2728 ACCEPT all -- any any anywhere anywhere state ESTABLISHED [root@node3 ~]# 2、在工作時間,即周一到周五的8:30-18:00,開放本機的ftp服務給172.16.0.0網絡中的主機訪問;數據下載請求的次數每分鐘不得超過5個; [root@node3 ~]# iptables -A INPUT -d 172.16.0.0 -p tcp -m multiport --dports 20,21 -m time --weekdays 1,2,3,4,5 --timestart 8:30 --timestop 18:30 -m limit --limit 5/minute -j ACCEPT [root@node3 ~]# iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT [root@node3 ~]# iptables -L -v Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 DROP tcp -- any any anywhere node3 tcp dpt:http TIME on Mon limit: avg 100/sec burst 5 STRING match "admin" ALGO name kmp TO 65535 0 0 ACCEPT tcp -- any any anywhere 172.16.0.0 multiport dports ftp-data,ftp TIME from 08:30:00 to 18:30:00 on Mon,Tue,Wed,Thu,Fri limit: avg 5/min burst 5 18 1260 ACCEPT all -- any any anywhere anywhere state ESTABLISHED Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 721 75904 ACCEPT all -- any any anywhere anywhere state ESTABLISHED [root@node3 ~]# 3、開放本機的ssh服務給172.16.x.1-172.16.x.100中的主機,x為你的座位號,新請求建立的速率一分鐘不得超過2個;僅允許響應報文通過其服務端 口離開本機; [root@node3 ~]# iptables -A INPUT -p tcp --dport 22 -m iprange --src-range 172.16.1.1-172.16.1.100 -m limit --limit 2/minute -j ACCEPT [root@node3 ~]# iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT 4、拒絕TCP標志位全部為1及全部為0的報文訪問本機; [root@node3 ~]# iptables -A INPUT -d 192.168.1.116 -p tcp --tcp-flags ALL ALL -j DROP [root@node3 ~]# iptables -A INPUT -d 192.168.1.116 -p tcp --tcp-flags ALL NONE -j DROP 5、允許本機ping別的主機;但不開放別的主機ping本機; [root@node3 ~]# iptables -A INPUT -d 192.168.1.116 -p icmp --icmp-type 0 -j ACCEPT [root@node3 ~]# iptables -A INPUT -s 192.168.1.116 -p icmp --icmp-type 8 -j ACCEPT 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.255.255的包 # iptables -A clean_in -p tcp ! --syn -m state --state NEW -j DROP 添加新規則,丟棄新的規則鏈上syn標志位為1的包 # iptables -A clean_in -p tcp --tcp-flags ALL ALL -j DROP 添加新規則,丟棄tcp協議標志位全為1的包 # iptables -A clean_in -p tcp --tcp-flags ALL NONE -j DROP 添加新規則,丟棄tcp協議標志位全為0的包 # iptables -A clean_in -d 172.16.100.7 -j RETURN 添加新規則,將來自172.16.100.7的包返回到主鏈 # iptables -A INPUT -d 172.16.100.7 -j clean_in 添加新規則,將172.16.100.7的包交給clean_in處理 # iptables -A INPUT -i lo -j ACCEPT 添加新規則,指定流入報文接口為lo # iptables -A OUTPUT -o lo -j ACCEPT 添加新規則,指定流出報文接口為lo # iptables -A INPUT -i eth0 -m multiport -p tcp --dports 53,113,135,137,139,445 -j DROP 丟棄流入報文接口為eth0,協議為tcp,端口號為53,113,135,137,139,445的包 # iptables -A INPUT -i eth0 -m multiport -p udp --dports 53,113,135,137,139,445 -j DROP 丟棄流入報文接口為eth0,協議為udp,端口號為53,113,135,137,139,445的包 # iptables -A INPUT -i eth0 -p udp --dport 1026 -j DROP 丟棄流入報文接口為eht0,協議為udp,端口號為1026的包 # iptables -A INPUT -i eth0 -m multiport -p tcp --dports 1433,4899 -j DROP 丟棄流入報文接口為eth0,協議為tcp,端口號為1433,4899的包 # iptables -A INPUT -p icmp -m limit --limit 10/second -j ACCEPT 允許ping命令速率為每秒10次 7、通過tcp_wrapper控制vsftpd僅允許172.16.0.0/255.255.0.0網絡中的主機訪問,但172.16.100.3除外;對所被被拒絕的訪問嘗試都記錄在/va r/log/tcp_wrapper.log日志文件中; vim /etc/hosts.allow vsftpd:172.16.0.0/255.255.0.0 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 以上
原創文章,作者:N21_619463772,如若轉載,請注明出處:http://www.www58058.com/57247
My Mandarin is limited to about 10 wohdr/psrases. I have a personal assistant and that spoils me! It’s a fascinating place, full of lots of places to see… the winter was AWFUL and almost did me in, but the sun came out a few days ago and the flowers are blooming and life is semi back to normal