zoukankan      html  css  js  c++  java
  • 判断iptables是否运行的一些探索

    现在有这么一个需求,要判断iptables是否开启。咋看比较难以入手,那么可以想,怎么启动iptables,redhat下很容易联想到/etc/init.d/iptabes start 。

    我们可以来看一下启动脚本:

    start() {
        # Do not start if there is no config file.
        [ ! -f "$IPTABLES_DATA" ] && return 6

        # check if ipv6 module load is deactivated
        if [ "${_IPV}" = "ipv6" ]
        && grep -qIsE "^install[[:space:]]+${_IPV}[[:space:]]+/bin/(true|false)" /etc/modprobe.conf /etc/modprobe.d/* ; then
        echo $"${IPTABLES}: ${_IPV} is disabled."
        return 150
        fi

        echo -n $"${IPTABLES}: Applying firewall rules: "

        OPT=
        [ "x$IPTABLES_SAVE_COUNTER" = "xyes" ] && OPT="-c"

        $IPTABLES-restore $OPT $IPTABLES_DATA
        if [ $? -eq 0 ]; then
        success; echo
        else
        failure; echo;
        if [ -f "$IPTABLES_FALLBACK_DATA" ]; then
            echo -n $"${IPTABLES}: Applying firewall fallback rules: "
            $IPTABLES-restore $OPT $IPTABLES_FALLBACK_DATA
            if [ $? -eq 0 ]; then
            success; echo
            else
            failure; echo; return 1
            fi
        else
            return 1
        fi
        fi
       
        # Load additional modules (helpers)
        if [ -n "$IPTABLES_MODULES" ]; then
        echo -n $"${IPTABLES}: Loading additional modules: "
        ret=0
        for mod in $IPTABLES_MODULES; do
            echo -n "$mod "
            modprobe $mod > /dev/null 2>&1
            let ret+=$?;
        done
        [ $ret -eq 0 ] && success || failure
        echo
        fi
       
        # Load sysctl settings
        load_sysctl

        touch $VAR_SUBSYS_IPTABLES
        return $ret
    }

    这个函数其实核心点就是iptables-restore  ,没有后台启动一个daemon程序那种, 因为iptables 是linux 的一个内核模块。这样就比较难判断了,因为不能用所谓的ps查进程的方式,当然末尾有个lock文件可以判断,但如果不是用启动脚本启动的,直接iptables-restore,则不会产生这个lock文件。

    至此,陷入一个难题中。

  • 相关阅读:
    mvc与springmvc
    mybatis一级与二级缓存详解
    resultType和resultMap的使用场景
    mybatis第一天学习总结
    linux常用命令(不断更新)
    SSH基本框架搭建的详细过程
    hibernate多条件组合查询的两种方式
    AJAX验证用户名是否被注册
    Vimrc
    关于window.open在不同浏览器的不同点
  • 原文地址:https://www.cnblogs.com/gqdw/p/4066985.html
Copyright © 2011-2022 走看看