#!/bin/bash
PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH
function start(){
echo 'start iptables: [ok]'
iptables -F
iptables -X
iptables -Z
iptables-restore < /root/iptables.rules
}
function stop(){
echo 'stop iptables: [ok]'
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F
iptables -X
iptables -Z
}
function restart(){
stop
sleep 2
start
}
function status(){
RULES_COUNT=$(iptables -nL | wc -l)
if [ $RULES_COUNT -gt '8' ];then
echo 'iptables is running ...'
else
echo 'iptables is not running ...'
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo 'Usage:start|stop|restart'
;;
esac
本文转自 freeterman 51CTO博客,原文链接:http://blog.51cto.com/myunix/1289700,如需转载请自行联系原作者