#!/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