第十周作业

1、编写脚本selinux.sh,实现开启或禁用selinux功能

#!/bin/bash
 read -p "please input character set selinux for {start|stop} :" s
 se=$(sed -rn 's@^SELINUX=(.*)@\1@'p /etc/selinux/config)
 if [ $s == 'start' ];then
         if [ $se == 'enforcing' ];then
                 echo "selinux  status is enforcing"
         elif [ $se == 'disabled' ];then
                 sed -ri 's@^SELINUX=(.*)@SELINUX=enforcing@' /etc/selinux/config && echo "selinux is start "
         fi
 elif [ $s == 'stop' ];then
        if [ $se == 'disabled' ];then
                echo "selinux  status is disabled"
        elif [ $se == 'enforcing' ];then
                sed -ri 's@^SELINUX=(.*)@SELINUX=disabled@' /etc/selinux/config && echo "selinux is stop"
        fi
fi

在这里插入图片描述

2、统计/etc/fstab文件中每个文件系统类型出现的次数

 cat /etc/fstab|grep "^/" |awk  '{print $3}'|uniq -c

3、提取出字符串Yd$C@M05MB%9&Bdh7dq+YVixp3vpw中的所有数字

echo 'Yd$C@M05MB%9&Bdh7dq+YVixp3vpw' > ll.txt
cat ll.txt |grep -o [0-9]

结果:
在这里插入图片描述

4、解决DOS攻击生产案例:根据web日志或者或者网络连接数,监控当某个IP 并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频 率每隔5分钟。防火墙命令为:iptables -A INPUT -s IP -j REJECT

#!/bin/bash
cat /data/access_log | awk '{IP[$1]++}END{for(i in IP){print i,IP[i]}}' > /tmp/hosts.txt
while read  ip number;do
if [ $number -gt 100 ] ;then
iptables -A INPUT -s $ip -j REJECT
echo "from $ip  $number rejected" >> /tmp/reject.txt
fi
done < /tmp/hosts.txt

设定5分钟启动

crontab -e
*/5 * * * * /root/checkip.sh
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值