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

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值