linux/scripts/init/iptables

58 lines
790 B
Bash

#!/bin/sh
### BEGIN INIT INFO
# Provides: iptables
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: IP Tables as service
# X-Author: Adrian Kousz, 2014
### END INIT INFO
CONFIG=/etc/iptables.rules
start() {
iptables -F
iptables-restore -c < "$CONFIG"
echo 'Service started'
}
stop() {
iptables -F
echo 'Service stopped'
}
status() {
iptables -L -v
}
save() {
iptables-save -c > "$CONFIG"
echo 'Settings saved'
}
case "$1" in
start)
start
;;
stop)
save
if [ "$2" != "really" ]; then
echo 'Append "really" to disable iptables!' >&2
exit 1
fi
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac