N21沉舟14周作业

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

iptables -P INPUT DROP
iptables -P OUTPUT DROP

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

iptables -A INPUT -d 192.168.50.30 -p tcp --dport 80 -m time --weekdays mon -m limit --limit 100/second -m string --algo kmp --string "admin" -j DROP
iptables -A OUTPUT -s 192.168.50.30 -p tcp --sport 80 -m limit --limit 100/second -m string --algo kmp --string "admin" -j DROP
iptables -a OUTPUT -m state --state ESTABLISHED -j ACCEPT

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

iptables -I INUT - p tcp -d 172.16.0.0 -m time --weekdays 1,2,3,4,5 --timestart 8:30 --timestop 18:00 -m limit --limit-burst 5 -m multiport --dports 20,21 -m state --state NEW,ESTABLISHED -j ACCEPT

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

iptables -I INPUT -p tcp --dport 22 -m iprange -src-range 172.16.100.1-172.16.100.100 -m limit --limit 2/minute -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHD -j ACCEPT

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

iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
iptables -A INPUT -P TCP --tcp-flags ALL none -j DROP

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

iptables -A INPUT -p imcp --imcp-type 0 -j ACCEPT
iptables -A OUTPUT -p imcp --imcp-type 8 -j ACCEPT

6、判断下述规则的意义: 

# iptables -N clean_in
新建名为clean_in的自定义链
# iptables -A clean_in -d 255.255.255.255 -p icmp -j DROP
在新链上增加禁止本机发送ICMP广播
# iptables -A clean_in -d 172.16.255.255 -p icmp -j DROP
禁止本机到172.16.0.0网段收发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 
增加规则,在clean_in链中找不到匹配规则时返回主链
# 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
经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
设置icmp入站请求为10次每秒,即限制ping为每秒10次

7、通过tcp_wrapper控制vsftpd仅允许172.16.0.0/255.255.0.0网络中的主机访问,但172.16.100.3除外;对所被被拒绝的访问尝试都记录

##在/var/log/tcp_wrapper.log日志文件中;
#编辑/etc/hosts.allow,新增一行
vsftpd:172.16.0.0/255.255.0.0 EXCEPT 172.16.100.3
#编辑/etc/hosts.deny,新增一行
vsftpd:ALL :spawn /bin/echo `date` login attempt from %c to %s, %d >> /var/log/tcp_wrapper.log

原创文章,作者:N21-沉舟,如若转载,请注明出处:http://www.178linux.com/57391

(0)
N21-沉舟N21-沉舟
上一篇 2016-11-14
下一篇 2016-11-14

相关推荐

  • fstab配置文件详解

    /etc/fstab配置文件详解 /etc/fstab:记录了计算机上硬盘分区的相关信息,启动Linux时,检查分区的fsck命令,挂载分区的mount命令,都需要fstab这个文件的信息,来正确的检查和挂载硬盘,而且这个硬盘需要root用户权限才能编辑 详解: 设备名称   挂载点  分区的类型  挂载选项  dump选项  fsck选项 设备名称: 可以…

    Linux干货 2017-04-23
  • Linux三剑客之grep伐木累(正则表达式)

    一、Linux文本处理三剑客     Linux上有三种常用的文本处理工具,分别为:grep(egrep、fgrep)、sed、awk。今天主要给大家介绍一下三剑客中的第一剑:grep伐木累。 二、grep是什么?     grep 全称(Globally search a Re…

    Linux干货 2016-03-09
  • TCP连接的状态详解以及故障排查

    我们通过了解TCP各个状态,可以排除和定位网络或系统故障时大有帮助。(总结网络上的内容) 1、TCP状态 linux查看tcp的状态命令: 1)、netstat -nat  查看TCP各个状态的数量 2)、lsof  -i:port  可以检测到打开套接字的状况 3)、 &nbs…

    Linux干货 2015-04-03
  • 编译安装httpd2.4-centos6

    centos6编译安装httpd2.4 默认是不支持,需自己动手进行编译 apr-1.4+ apr-util-1.4+ :需提前进行编译安装这两个软件 编辑安装httpd2.4实例 1、#安装开发包 [root@www ~]# yum groupinstall “Development Tools” “Server Pla…

    Linux干货 2017-05-17
  • 第四周作业

    Linux系统文件管理使用案例 1、 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 首先,利用cp命令将/etc/skel目录复制为/home/tuser1: [root@localhost ~]# cp -r /etc/skel /home/tuser1 随后通过chmo…

    Linux干货 2018-03-24
  • 学习shell scripts

    1. 为什么要学习shell编程?          许多人会问,为什么要学习shell脚本编程?我学的是linux,又不是编程,其实对于个人用户可能用处不是很大,但是当你在为公司的成千上完的服务器做维护时,可能没有shell编程的话可能把人累死也无法完成任务,一千台服务器要做相…

    Linux干货 2016-08-18

评论列表(1条)

  • 马哥教育
    马哥教育 2016-11-16 15:51

    写的很好,如果能总结一下iptables的话会更好