Shell monitoring iptables rules are changed

Source: Internet
Author: User
Tags sleep iptables

System: CentOS 5.x
Script content:

The code is as follows Copy Code

#!/bin/bash
if [!-F. Count];then
Iptables-l-n|md5sum|awk ' {print $} ' > ~/.count
Exit 1
Else
Iptables-l-n|md5sum|awk ' {print $} ' >~/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

and throw it in the crontab. Check every 3 minutes.

The code is as follows Copy Code

chmod +x/root/check_iptables.sh
*/3 * * * */bin/sh/root/check_iptables.sh

Of course you can also add an email alert to inform iptables that the rules have changed.

Original link: blog.slogra.com/post-533.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.