運維人員20道必會iptables面試題


1、詳述iptales工作流程以及規則過濾順序?

iptables過濾的規則順序是由上至下,若出現相同的匹配規則則遵循由上至下的順序

 

2、iptables有幾個表以及每個表有幾個鏈?

Iptables有四表五鏈

 

3、iptables的幾個表以及每個表對應鏈的作用,對應企業應用場景?

    filter:INPUT  作用:for  packets destined  to  local  sockets

                FORWARD 作用:for packets  being  routed  through  the box

                OUTPUT 作用:for locally-generated packets

    nat:PREROUTING 作用:for altering packets  as  soon as they come in

            OUTPUT     作用:for altering locally-gener- ated packets before routing

            POSTROUTING 作用:for altering packets as they are about to go out

    mangle :PRE-ROUTING  (for  altering incoming packets before rout-ing) and OUTPUT (for altering locally-generated pack-ets  before  routing).   INPUT  (forpackets  coming  into  the  box itself), FORWARD (foraltering packets being routed through the  box),  and POSTROUTING  (for  altering packets as they are about to go out).

 

4、畫圖講解iptables包過濾經過不同表和鏈簡易流程圖並闡述。

5、請寫出查看iptables當前所有規則的命令。

     iptables -L -n --line-numbers

 

6、禁止來自10.0.0.188 ip地址訪問80端口的請求

     iptables -A INPUT -p tcp --dport 80 -j DROP

 

7、如何使在命令行執行的iptables規則永久生效?

    /etc/init.d/iptables save

    iptables save >>/etc/sysconfig/iptables

 

8、實現把訪問10.0.0.3:80的請求轉到172.16.1.17:80

     iptables -t nat -A PREROUTING -d 10.0.0.3 -p tcp --dport 80 -j DNAT --to-destination 172.16.1.6:80

 

9、實現172.16.1.0/24段所有主機通過124.32.54.26外網IP共享上網。

    iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -j SNAT --to-source 124.32.54.26

    iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -j MASQUERADE

10、描述tcp 3次握手及四次斷開過程?

11.詳細描述HTTP工作原理?

    1 ) 地址解析

    2)封裝HTTP請求數據包

    3)封裝成TCP包,建立TCP連接(TCP的三次握手)

    4)客戶機發送請求命令

    5)服務器響應

    6)服務器關閉TCP連接

12.請描述iptables的常見生產應用場景。

     端口映射

企業應用場景:
1) 把訪問外網IP及端口的請求映射到內網某個服務器及端口(企業內部);
2) 硬件防火牆,把訪問LVS/nginx外網VIP及80端口的請求映射到IDC 負載均衡服務器內部IP及端口上(IDC機房的操作) ;

    局域網共享上網

    iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j SNAT --to-source 120.43.61.124

 

13、請描述下面iptables命令的作用

iptables -N syn-flood            

iptables -A INPUT -i eth0 -syn -j syn-flood

iptables -A syn-flood -m limit -limit 5000/s -limit-burst 200 -j RETURN

iptables -A syn-flood -j DROP

 

防止syn-flood攻擊的

 

14、企業WEB應用較大並發場景如何優化iptables?

net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120

 

(二)企業運維經驗面試題:

15、寫一個防火牆配置腳本,只允許遠程主機訪問本機的80端口(奇虎360面試題)

   iptables -A INPUT -p tcp --dport 80 -j accept

   iptables -A INPUT -p tcp  -j DROP

 

16、請描述如何配置一個linux上網網關?

         route add -net 192.168.0.0/24 gw 10.0.0.253 dev eth1

 

17、請描述如何配置一個專業的安全的WEB服務器主機防火牆?

先將默認的INPUT鏈和Forward鏈關閉,只開放允許進入的端口

iptables -P OUTPUT ACCEPT
iptables -P  FORWARD DROP
iptables -P INPUT DROP



 

18、企業實戰題6:請用至少兩種方法實現!

寫一個腳本解決DOS攻擊生產案例

提示:根據web日志或者或者網絡連接數,監控當某個IP並發連接數或者短時內PV達到100,即調用防火牆命令封掉對應的IP,監控頻率每隔3分鍾。防火牆命令為:iptables -I INPUT -s 10.0.1.10 -j DROP。

方法一:
netstat  -na| grep  EST| awk  -F  "[ :]+"  '{print $6}' | sort | uniq  -c >> /tmp/a .log
  while  true
     do
     grep  EST a.log| awk  -F  '[ :]+'  '{print $6}' | sort | uniq  -c > /tmp/tmp .log
     exec  < /tmp/tmp .log
     while  read  line
     do
         ip=` echo  $line| awk  "{print $2}" `
         count=` echo  $line| awk  "{print $1}" `
         if  [  $count -gt 100 ] && [ `iptables -L -n| grep  $ip| wc  -l` -lt 1  ]
         then
             iptables -I INPUT -s $ip -j DROP      //-I  將其封殺在iptables顯示在第一條
             echo  "$line is dropped"  >> /tmp/dropip .log
         fi
     done
     sleep  180
     done
     
方法二: netstat  -na| grep  EST| awk  -F  "[ :]+"  '{print $6}' | awk  '{S[$1]++}END{for(i in S) print i,S[i]}'

 

 

 

19、/var/log/messages日志出現kernel: nf_conntrack: table full, dropping packet.請問是什么原因導致的?如何解決?

優化內核參數

net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
 

 

 

20、壓軸上機實戰iptables考試題

 

iptables -t nat -A POSTROUTING -s 10.0.0.253 -j SNAT -o eth0 --to-source 120.43.61.124

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

 

tcpdump ip host 10.0.0.253 and  10.0.0.6 或 tcpdump ip host 10.0.0.253 and  10.0.0.7

iptables -t nat -A PREROUTING -d 120.43.61.124 -p tcp --dport 80 -j DNAT --to-destination 172.16.1.6:80

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM