Created
May 22, 2013 02:33
-
-
Save tankywoo/5624887 to your computer and use it in GitHub Desktop.
iptables startup script, put it in /etc/init.d/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
### BEGIN INIT INFO | |
# Provides: iptables | |
# Required-Start: mountkernfs $local_fs | |
# Required-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Set up iptables rules | |
### END INIT INFO | |
if [ $(id -u) -ne 0 ] ; then | |
CMD_IPTABLES="sudo iptables" | |
else | |
CMD_IPTABLES="iptables" | |
fi | |
IPTABLES_RAW="${CMD_IPTABLES} -t raw" | |
CONF_DIR="/etc/iptables" | |
IPTABLES_RULES=${CONF_DIR}/iptables_rules | |
IPSET_RULES=${CONF_DIR}/ipset_rules | |
case "$1" in | |
start) | |
if [[ -f ${IPSET_RULES} && -f ${IPTABLES_RULES} ]]; then | |
ipset restore < ${IPSET_RULES} | |
iptables-restore < ${IPTABLES_RULES} | |
fi | |
;; | |
stop) | |
${CMD_IPTABLES} -F | |
${CMD_IPTABLES} -X | |
${CMD_IPTABLES} -Z | |
${IPTABLES_RAW} -F | |
${IPTABLES_RAW} -X | |
ipset destroy | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
echo "Filter Rules:" | |
echo "--------------" | |
${CMD_IPTABLES} -L -v | |
echo "" | |
echo "Raw Rules:" | |
echo "--------------" | |
${CMD_IPTABLES} -t raw -L -v | |
echo "" | |
echo "NAT Rules:" | |
echo "-------------" | |
${CMD_IPTABLES} -t nat -L -v | |
echo "" | |
echo "Mangle Rules:" | |
echo "----------------" | |
${CMD_IPTABLES} -t mangle -L -v | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thk!