N25期–第十四周作业

系统的INPUTOUTPUT默认策略为DROP

# iptables -P INPUT DROP

# iptables -P OUTPUT DROP

1、 限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的页面不允许访问;web服务器仅允许响应报文离开本机;

 

#iptables -A INPUT -p
tcp –dport 80 -m time ! –weekdays Mon -j ACCEPT

 

#
iptables -A INPUT -p tcp –dport 80 -m limit –limit 100/s

#
iptables -A INPUT -p tcp –dport 80 -m string –algo bm –string ‘admin’ -j
REJECT

 

#
iptables -A OUTPUT -p tcp –sport 80 -m state –state ESTABLISHED -j ACCEPT

 

2、 在工作时间,即周一到周五的8:30-18:00,开放本机的ftp服务给172.16.0.0网络中的主机访问;数据下载请求的次数每分钟不得超过5个;

#
iptables –A INPUT –s 172.16.0.0/16 –p tcp –dport21 –m time –timestart 08:30 –timestop 18:00 –m time! –weekdays 6,7 -m limit –limit 5/minute
–m state –state NEW,ESTABLISHED –j ACCEPT

 

#
iptables –A INPUT –m state –state RELATED,ESTABLISHED –j ACCEPT

 

#
iptables –A OUTPUT –m d 172.16.0.0/16 –p tcp –m state –state ESTABLISHED –j ACCEPT

 

3、 开放本机的ssh服务给172.16.x.1-172.16.x.100中的主机,x为你的座位号,新请求建立的速率一分钟不得超过2个;仅允许响应报文通过其服务端口离开本机;

 

# iptables -A INPUT
-p tcp –dport 22 -m iprange –src-range 172.16.0.1-172.16.0.100 -m limit
–limit 2/m -j ACCEPT

 

#
iptables -A OUTPUT -p tcp –sport 22 -m iprange –dst-range
172.16.0.1-172.16.0.100 -m state –state ESTABLISHED -j ACCEPT

 

4、 拒绝TCP标志位全部为1及全部为0的报文访问本机;

#
iptables -A INPUT -p tcp –tcp-flags ALL ALL -j DROP

 

5、 允许本机ping别的主机;但不开放别的主机ping本机;

# iptables -A INPUT  -p icmp –icmp-type
0 -j ACCEPT

#
iptables -A OUTPUT  -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.255icmp

# 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 //指定流入报文接口为本地回环

# iptables -A OUTPUT -o lo -j ACCEPT //指定流出报文接口为本地回环

 

# 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 

//指定流入报文接口为eth0,协议为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除外;对所被被拒绝的访问尝试都记录在/var/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

原创文章,作者:victorli88,如若转载,请注明出处:http://www.178linux.com/71147

(0)
victorli88victorli88
上一篇 2017-04-10 15:11
下一篇 2017-04-10 19:20

相关推荐

  • passwd

    http://www.cnblogs.com/wzhuo/p/6706774.html

    Linux干货 2017-04-17
  • linux运维

    linux运维大纲,学习路线图

    Linux干货 2017-10-21
  • 软件包管理详解

      软件包管理器 1、功能: (1)将软件包打包成一个文件,其中包括: ①二进制程序 ②库文件 ③配置文件 ④帮助文件 (2)生成数据库,追中所安装的每一个文件。 2、软件包管理器的核心功能: (1)制作软件包 (2)安装、卸载、升级、查询、校验 3、不同发行版的不同的…

    2017-08-11
  • Nginx配置详解

    NginX 回顾http协议: 1.URL格式 URL:shceme://username:password@host:port/path;params?query#fram 2.http事务:     request:请求报文格式       reponse:响应报文…

    Linux干货 2016-10-25
  • shell脚本参数练习

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登陆shell(即用户的shell不是/sbin/nologin),分别这两类用户的个数;通过字符串比较来实现; !/bin/bash # login_user=0 nologin_user=0 for i in $(cat /etc/passwd | cut -d : -f 7);do if [ $…

    2017-09-17
  • RAID[Redundant Array of Independent Disks | 独立硬盘冗余阵列 ]

    前言 一个技术要知其然还要知其所以然 RAID 独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Array of Inexpensive Disks),简称磁盘阵列 RAID的基本思想 其基本思想就是把多个相对便宜的硬盘组合起来,成为一个硬盘阵列组,使性能达到…

    Linux干货 2016-05-20

评论列表(1条)

  • 马哥教育
    马哥教育 2017-05-04 14:48

    通过这次作业的练习,相信会对iptables的掌握有很大的帮忙。