Created
July 8, 2012 18:58
-
-
Save miebach/3072327 to your computer and use it in GitHub Desktop.
/etc/init.d/iptables
This file contains hidden or 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 | |
| # see http://serverfault.com/a/363745/45819 | |
| start() { | |
| echo "Starting iptables." | |
| EXT="eth0" | |
| TUNNELS="tun+" | |
| iptables -F | |
| iptables -X | |
| iptables -P INPUT DROP # set policy which is applied at the end. | |
| # note that outgoing connections are not affected in this script! | |
| # allow everything on loopback-device | |
| iptables -A INPUT -i lo -p all -j ACCEPT | |
| # allow established connections | |
| iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT | |
| # open ssh and http | |
| iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT | |
| iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT | |
| # Allow incoming pings | |
| iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT | |
| # no more rules can be added to the INPUT chain after this: | |
| iptables -A INPUT -j DROP | |
| } | |
| stop() { | |
| echo "Stopping iptables." | |
| iptables -F | |
| iptables -X | |
| iptables -P INPUT ACCEPT | |
| } | |
| status() { | |
| iptables -L -vn | |
| } | |
| case "$1" in | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| restart) | |
| stop | |
| start | |
| ;; | |
| status) | |
| status | |
| ;; | |
| *) | |
| echo "Usage: $0 start|stop|restart|status" | |
| exit 1 | |
| ;; | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment