马哥教育网络21期+第十四周练习博客

马哥教育网络21期+第十四周练习博客

1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的页面不允许访问;web服务器仅允许响应报文离开本机;
这里web服务器仅允许响应报文离开本机这里的响应报文为ESTABLISHED
[root@localhost ~]# iptables -A OUTPUT -s 172.16.0.46 -m state --state ESTABLISHED -j ACCEPT
[root@localhost ~]# iptables -A INPUT -d 172.16.0.46 -p tcp -m multiport --dport 80 -m time --weekdays 1 -m limit --limit 100/second -m string --algo bm --string 'admin' -j DROP
[root@localhost ~]# iptables -L -n
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            172.16.0.46         tcp dpt:22 
ACCEPT     tcp  --  0.0.0.0/0            172.16.0.46         tcp dpt:80 
ACCEPT     icmp --  0.0.0.0/0            172.16.0.46         icmp type 0 
DROP       tcp  --  0.0.0.0/0            172.16.0.46         multiport dports 80 TIME on Mon limit: avg 100/sec burst 5 STRING match "admin" ALGO name bm TO 65535 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  172.16.0.46          0.0.0.0/0           state ESTABLISHED 


2、在工作时间,即周一到周五的8:30-18:00,开放本机的ftp服务给172.16.0.0网络中的主机访问;数据下载请求的次数每分钟不得超过5个;
因为ftp服务属于被动模式下的服务需要放行2种报文
1,命令连接(NEW,ESTABLISHED)
2,数据连接(RELATED,ESTABLISHED)
[root@localhost ~]# iptables -A INPUT -d 172.16.0.46 -p tcp -m multiport --dports 21,22 -m iprange --src-range 172.16.0.1-172.16.0.254 -m time --weekdays 1,2,3,4,5 --timestart 8:30 --timestop 18:00 -m limit --limit-burst 5 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
[root@localhost ~]# iptables -L -n
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            172.16.0.46         tcp dpt:22 
ACCEPT     tcp  --  0.0.0.0/0            172.16.0.46         tcp dpt:80 
ACCEPT     icmp --  0.0.0.0/0            172.16.0.46         icmp type 0 
ACCEPT     tcp  --  0.0.0.0/0            172.16.0.46         multiport dports 21,22 source IP range 172.16.0.1-172.16.0.254 TIME from 08:30:00 to 18:00:00 on Mon,Tue,Wed,Thu,Fri limit: avg 3/hour burst 5 state NEW,RELATED,ESTABLISHED 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  172.16.0.46          0.0.0.0/0           state ESTABLISHED 

3、开放本机的ssh服务给172.16.x.1-172.16.x.100中的主机,x为你的座位号,新请求建立的速率一分钟不得超过2个;仅允许响应报文通过其服务端口离开本机;
[root@localhost ~]# iptables -A INPUT -d 172.16.0.46 -p tcp -m multiport --dport 22 -m iprange --src-range 172.16.0.1-172.16.0.100 -m limit --limit 2/minute -j ACCEPT
[root@localhost ~]# iptables -L -n
Chain INPUT (policy DROP)
 172.16.0.46         multiport dports 22 source IP range 172.16.0.1-172.16.0.100 limit: avg 2/min burst 5 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  172.16.0.46          0.0.0.0/0           state ESTABLISHED 

4、拒绝TCP标志位全部为1及全部为0的报文访问本机;
[root@localhost ~]# iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
[root@localhost ~]# iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
[root@localhost ~]# iptables -L -n
Chain INPUT (policy DROP)
target     prot opt source               destination         
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x3F 
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  172.16.0.46          0.0.0.0/0           state ESTABLISHED 


5、允许本机ping别的主机;但不开放别的主机ping本机;
这里我是使用ssh登录的远程的Linux服务器的,这里我先放开22号端口
[root@localhost ~]# iptables -L -n
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            172.16.0.46         tcp dpt:22 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  172.16.0.46          0.0.0.0/0           tcp spt:22
这时候发现除了22号端口以外其他的任意访问都无法访问:
ICMP包有很多种其中ping包问0和8需要放行出站的请求和入站的响应
 [root@localhost ~]# iptables -A INPUT -d 172.16.0.46 -p icmp --icmp-type 0 -j ACCEPT
[root@localhost ~]# iptables -A OUTPUT -s 172.16.0.46 -p icmp --icmp-type 8 -j ACCEPT
[root@localhost ~]# iptables -L -n
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            172.16.0.46         tcp dpt:22 
ACCEPT     icmp --  0.0.0.0/0            172.16.0.46         icmp type 0 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  172.16.0.46          0.0.0.0/0           tcp spt:22 
ACCEPT     icmp --  172.16.0.46          0.0.0.0/0           icmp type 8 


6、判断下述规则的意义:
  # iptables -N clean_in
    新建一个自定义链
  # iptables -A clean_in -d 255.255.255.255 -p icmp -j DROP
    在自定义链上来自目的为255.255.255.255 的icmp包全部拒绝
  # iptables -A clean_in -d 172.16.255.255 -p icmp -j DROP
    在自定义链上来自目的为172.16.255.255 的icmp包全部拒绝
  # 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 流出的tcp协议的端口为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流入端口为tcp1433,4899端口拒绝
  # iptables -A INPUT  -p icmp -m limit --limit 10/second -j ACCEPT
    icmp包流入不超过每秒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

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

(0)
wostopwostop
上一篇 2016-12-05 17:05
下一篇 2016-12-05 17:05

相关推荐

  • ​第五周作业

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@localhost ~]# grep  -E "^[[:space:]]+" /boot/grub/grub.conf  root (hd0,0) kernel&nbs…

    Linux干货 2017-02-05
  • 8月5日文本处理工具作业

    分析文本工具相关练习题 1 、找出ifconfig 命令结果中本机的所有IPv4 地址       ~]# ifconfig|tr -cs '[0-9].' '\n'|sort -ut '.…

    Linux干货 2016-08-06
  • Shell编程if语句

    Shell编程if语句 条件选择if语句(#if输入keywork) 选择执行: 注意:if语句可嵌套 单分支 if 判断条件(#如果为真执行下一条);then 条件为真的分支代码 fi(结尾) 双分支 if 判断条件; then 条件为真的分支代码 else 条件为假的分支代码 fi if 语句 多分支 if 判断条件1; then 条件为真的分支代码 e…

    2018-01-01
  • nginx配置(三)

    ngx_http_upstream_module模块     #分流The ngx_http_upstream_module module is used to define groups of servers that can be referenced by the proxy_pass, fastcgi_pass, uwsgi_pa…

    Linux干货 2017-05-08
  • Linux系统程序包管理之RPM

    rpm包概述 RPM 是 Red at Package Manager 的缩写,本意是Red Hat 软件包管理,顾名思义是Red Hat 贡献出来的软件包管理工具;在Fedora 、Redhat、Mandriva、SuSE、YellowDog等主流发行版本,以及在这些版本基础上二次开发出来的发行版采用。 RPM包里面都包含什么?里面包含可执行的二进制程序,…

    Linux干货 2016-08-24
  • phpMyAdmin安装部署

    phpMyAdmin安装部署 phpMyAdmin 是一个用PHP编写的软件工具,可以通过web方式控制和操作MySQL数据库。通过phpMyAdmin 可以完全对数据库进行操作,例如建立、复制和删除数据等等。如果使用合适的工具,MySQL数据库的管理就会变得相当简单。应用 MySQL 命令行方式需要对 MySQL 知识非常熟悉,对SQL语言也是同样的道理。…

    2017-06-13