linux监听是否被访问,Shell脚本实现监控iptables规则是否被修改

最近看了一篇通过nagios实现MD5实时监控iptables状态的文章,就想是否可以用shell也做到监控iptables规则改变,经过实验,就有了下面这个脚本.

系统:centos 5.x

脚本内容:

cat check_iptables.sh

#!/bin/bash

if [ ! -f .count ];then

iptables -L -n|md5sum|awk '{print $1}' > ~/.count

exit 1

else

iptables -L -n|md5sum|awk '{print $1}' >~/1.txt

difffile=`diff ~/.count ~/1.txt|wc -l`

if [[ $difffile = 0 ]];then

echo "file is ok!"

sleep 1

rm -f ~/1.txt

else

echo "file is no ok!"

cat ~/1.txt >~/.count

sleep 1

rm -f ~/1.txt

fi

fi

然后丢到crontab里.以每隔3分钟检测一次.

chmod +x /root/check_iptables.sh

*/3 * * * * /bin/sh /root/check_iptables.sh

当然你也可以加上邮件报警来通知iptables规则有改变.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值