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

相关推荐

  • 马哥教育21期网络班—第12周课程+练习—-LAMP练习下

    在LAMP架构中,请分别以fpm工作为独立守护进程的方式来支持http yum groupinstall "Development Tools" "Server Platform Development"——>安装包组1、编译安装Apacheht…

    Linux干货 2016-09-26
  • 文件查找(find)

                                  …

    2017-04-11
  • 计算机基础

    计算机组成 计算机发展史 采用电子管的第一代计算机(1946~1959年) 第一代计算机的内部元件使用的是电子管。第一代计算机主要用于科学研究和工程计算。 采用晶体管的第二代计算机(1960~1964年) 第二代计算机的内部元件使用的是晶体管,晶体管比电子管小得多,处理更迅速、更可靠。第二代计算机主要用于商业、大学教学和政府机关。 采用集成电路的第三代计算机…

    Linux干货 2017-12-03
  • Linux里的用户与组

    任何事务的进行都离不开管理,脱离了管理的系统将会是一团乱麻。今天就来讲讲Linux里的用户与组的管理 首先,用户与组不会凭空出现,必须得是系统本身或人为创建的 。     所以,系统创建的就叫系统用户.系统组,用户创建的就是普通用户.普通组。 useradd  创建用户 -u 创建用户并指定用户的UID -g…

    2017-07-30
  • 第十六周

    1、源码编译安装LNMP架构环境;  安装必要的包组和依赖的包 yum groupinstall “Development Tools” “Development Libraries”  yum install wget openssl-devel ncurses-devel cmake p…

    Linux干货 2017-08-15
  • openssh及基于ssl的https的配置

    openssh的简介             OpenSSH 是 SSH 协议的免费开源实现。SSH协议族可以用来进行远程控制, 或在计算机之间传送文件。 而实现此功能的传统方式,如telnet(终端仿真协议)、 rcp ftp、 rlogin、rs…

    Linux干货 2017-05-30

评论列表(1条)

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

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