马哥教育网络第21期-第十四周课程练习

系统的INPUT和OUTPUT默认策略为DROP;

iptables -P INPUT DROP
iptables -P OUTPUT DROP

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

[root@node3 ~]# iptables -A INPUT -d 192.168.1.116 -p tcp --dport 80 -m time --weekdays Mon -m limit --limit 100/second
 -m string --algo kmp --string 'admin' -j DROP
[root@node3 ~]# iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
[root@node3 ~]# iptables -L -v
Chain INPUT (policy ACCEPT 56 packets, 3716 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       tcp  --  any    any     anywhere             node3               tcp dpt:http TIME on Mon limit: avg 100/sec burst 5 STRING match "admin" ALGO name kmp TO 65535 

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   31  2728 ACCEPT     all  --  any    any     anywhere             anywhere            state ESTABLISHED 
[root@node3 ~]# 

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

[root@node3 ~]# iptables -A INPUT -d 172.16.0.0 -p tcp -m multiport --dports 20,21 -m time --weekdays 1,2,3,4,5 --timestart 
8:30 --timestop 18:30 -m limit --limit 5/minute -j ACCEPT
[root@node3 ~]# iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
[root@node3 ~]# iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       tcp  --  any    any     anywhere             node3               tcp dpt:http TIME on Mon limit: avg 100/sec burst 5 STRING match "admin" ALGO name kmp TO 65535 
    0     0 ACCEPT     tcp  --  any    any     anywhere             172.16.0.0          multiport dports ftp-data,ftp TIME from 08:30:00 to 18:30:00 on Mon,Tue,Wed,Thu,Fri limit: avg 5/min burst 5 
   18  1260 ACCEPT     all  --  any    any     anywhere             anywhere            state ESTABLISHED 

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  721 75904 ACCEPT     all  --  any    any     anywhere             anywhere            state ESTABLISHED 
[root@node3 ~]# 

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

[root@node3 ~]# iptables -A INPUT -p tcp --dport 22 -m iprange --src-range 172.16.1.1-172.16.1.100 -m limit --limit
 2/minute -j ACCEPT
[root@node3 ~]# iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT

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

[root@node3 ~]# iptables -A INPUT -d 192.168.1.116 -p tcp --tcp-flags ALL ALL -j DROP
[root@node3 ~]# iptables -A INPUT -d 192.168.1.116 -p tcp --tcp-flags ALL NONE -j DROP

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

[root@node3 ~]# iptables -A INPUT -d 192.168.1.116 -p icmp --icmp-type 0 -j ACCEPT
[root@node3 ~]# iptables -A INPUT -s 192.168.1.116 -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.255的包
  # 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
  添加新规则,指定流入报文接口为lo
  # iptables -A OUTPUT -o lo -j ACCEPT
  添加新规则,指定流出报文接口为lo


  # 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
  丢弃流入报文接口为eht0,协议为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除外;对所被被拒绝的访问尝试都记录在/va
r/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

以上

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

(0)
N21_619463772N21_619463772
上一篇 2016-12-26
下一篇 2016-12-26

相关推荐

  • DNS和openssl

    本文主要讲述ssl以及使用openssl创建CA,DNS服务器的搭建  一.数据在互联网上传输存在各种各样的分险,数据在传输的过程中可能会被篡改,被截取等,于是就不得不解决这些安全问题,为了解决这些问题,ssl协议也就诞生了,ssl(Secure Socket Layer),首先,它是一中协议,专用于对数据进行加密与解密,是一个应用层协议,该协议提…

    Linux干货 2016-12-11
  • history命令详解

       有效地使用命令历史机制将会使效率获得极大提升。history:   保存你输入的命令历史。 可以用它来重复执行命令。   history [-c] [-d offset] [n]   history -anrw [filename]   history …

    2017-03-26
  • N25-第四周作业

    第四周作业 1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 ~]#cp -r /etc/skel /home/tuser1 ~]#chmor 700 /home/tuser1 2、编辑/etc/group文件,添加组hadoop。 ~]#echo "h…

    Linux干货 2017-01-03
  • 一起学DHCP系列(二)三种途径

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jeffyyko.blog.51cto.com/28563/162176 《一起学DHCP》系列第二节。      和WINS服务类似,DHCP大体上也由两部分组成,DHC…

    Linux干货 2015-03-25
  • 文件搜索者-find命令详解

    1. 文件查找:          在linux系统中由于文件的众多,往往需要在众多的文件当中查找某一个文件,如果时间一长,很难记得文件存放至何处,不过,这一点,你不比担心,因为开发人员为我们提供了强大的文件搜索工具,下面将介绍两款常用的文件查找工具locate,和find,这两…

    Linux干货 2016-08-15
  • 第四周小结

    这周我们主要学习了写脚本的简单语法,写了一些简单的脚本,下面就由我来简单介绍一下: 第一步使用文本编辑来创建脚本: 创建好后在里面写想要运行的脚本即可,然后按Esc—wq退出保存即可。也可以按q不保存退出;q!不保存强制退出;wq!保存强制退出。 第二步运行脚本,给予执行权限,在命令行上指定脚本的相对路径和绝对路径 对了,当在脚本里输入内容时,要Ese&#8…

    2017-08-06

评论列表(1条)

  • Nelda
    Nelda 2017-04-24 03:57

    My Mandarin is limited to about 10 wohdr/psrases. I have a personal assistant and that spoils me! It’s a fascinating place, full of lots of places to see… the winter was AWFUL and almost did me in, but the sun came out a few days ago and the flowers are blooming and life is semi back to normal