作業 linux防火牆作業

2021-10-09 14:18:11 字數 3264 閱讀 5544

說明:以下練習input和output預設策略均為drop

1、限制本地主機的web伺服器在周一不允許訪問;新請求的速率不能超過100個每秒;web伺服器包含了admin字串的頁面不允許訪問;web伺服器僅允許響應報文離開本機

[root@centos7 ~]# iptables -a input -d 10.0.0.7 -p tcp --dport 80 -m time ! --weekdays 1 -m limit --limit 100/second -m string --algo bm --from 62 ! --string "admin" -j accept 

[root@centos7 ~]# iptables -a input -m state --state established -j accept

[root@centos7 ~]# iptables -a output -s 10.0.0.7 -p tcp --sport 80 -j accept

[root@centos7 ~]# iptables -a input -s 172.16.0.0/24 -p tcp --dport 21 -m time --timestart 0:30 --timestop 10:00 --weekdays 1,2,3,4,5 -m connlimit --connlimit-upto  5 -j accept
3、開放本機的ssh服務給172.16.x.1-172.16.x.100中的主機,x為你的學號,新請求建立的速率一分鐘不得超過2個;僅允許響應報文通過其服務埠離開本機

[root@centos7 ~]# iptables -a input -d 10.0.0.7 -p tcp --dport 22 -m iprange --src-range 172.16.16.1-172.16.16.100 -m limit --limit 2/min -j accept

[root@centos7 ~]# iptables -a output -s 10.0.0.7 -p tcp --sport 22 -j accept

4、拒絕tcp標誌位全部為1及全部為0的報文訪問本機

[root@centos7 ~]# iptables -a input -d 10.0.0.7 -p tcp --tcp-flags syn,ack,fin,rst syn,ack,fin,rst -j reject

或[root@centos7 ~]# iptables -a input -d 10.0.0.7 -p tcp --tcp-flags all all -j reject

[root@centos7 ~]# iptables -a input -d 10.0.0.7 -p tcp --tcp-flags syn,ack,fin,rst none -j reject

或[root@centos7 ~]# iptables -a input -d 10.0.0.7 -p tcp --tcp-flags all none -j reject

5、允許本機ping別的主機;但不開放別的主機ping本機

[root@centos7 ~]# iptables -a input -s 10.0.0.1/32 -j accept

[root@centos7 ~]# iptables -a input -i lo -j accept

[root@centos7 ~]# iptables -a input -d 10.0.0.7/32 -p icmp -m icmp --icmp-type 0 -j accept

[root@centos7 ~]# iptables -a input -j reject --reject-with icmp-port-unreachable

[root@centos7 ~]# iptables -a output -s 10.0.0.7/32 -p icmp -m icmp --icmp-type 8 -j accept

6、判斷下述規則的意義

#新增自定義鏈 clean_in

iptables -n clean_in

#在自定義鏈中新增規則:丟棄icmp的廣播包

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

#在自定義鏈中新增規則:丟棄新請求且第一次握手的包

iptables -a clean_in -p tcp ! --syn -m state --state new -j drop

#丟棄tcp狀態全為1的包

iptables -a clean_in -p tcp --tcp-flags all all -j drop

#丟棄tcp狀態全為0的包

iptables -a clean_in -p tcp --tcp-flags all none -j drop

#表示匹配完自定義鏈後繼續回到主鏈進行匹配

iptables -a clean_in -d 172.16.100.7 -j return

#將自定義鏈加入到input鏈,使其能被呼叫

iptables -a input -d 172.16.100.7 -j clean_in

#允許本地回環口能訪問

iptables -a input -i lo -j accept

iptables -a output -o lo -j accept

#丟棄網絡卡中的tcp埠號為53,873,135,137,139,445的包

iptables -a input -i eth0 -m multiport -p tcp --dports 53,873,135,137,139,445 -

j drop

#丟棄網絡卡中的udp埠號為53,873,135,137,139,445的包

iptables -a input -i eth0 -m multiport -p udp --dports 53,873,135,137,139,445 -

j drop

丟棄網絡卡中的tcp埠號為1433,3389的包

iptables -a input -i eth0 -m multiport -p tcp --dports 1433,3389 -j drop

#允許icmp收發報文的速率為每秒10個

iptables -a input -p icmp -m limit --limit 10/second -j accept

防火牆 防火牆安全

作為計算機的第一道屏障,防火牆的重要性不言而喻,儘管防火牆在面臨網路攻擊時仍有很大的缺陷,不如無法阻止自內而外的攻擊,對複雜多變的網路攻擊攻擊無法預警和像ids所做的那樣。但防火牆依然是伺服器乃至個人機的一道不可或缺的屏障。木桶原理 本文將對防火牆做乙個初步的簡介,顯然像我們知道的那樣,防火牆是一款...

linux防火牆新增埠並開閉防火牆

安裝 yum install firewalld 啟動 systemctl start firewalld 檢視狀態 systemctl status firewalld 禁用,禁止開機啟動 systemctl disable firewalld 開機啟用 systemctl enable fire...

Linux防火牆配置

重啟後生效 開啟 chkconfig iptables on 關閉 chkconfig iptables off 2 即時生效,重啟後失效 開啟 service iptables start 關閉 service iptables stop 需要說明的是對於linux下的其它服務都可以用以上命令執行...