Created
October 15, 2017 22:22
-
-
Save gardner/85ce47926db1e19ef8e60c807eaa34e0 to your computer and use it in GitHub Desktop.
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/sh | |
| # This file is part of netfilter-persistent | |
| # (was iptables-persistent) | |
| # Copyright (C) 2009, Simon Richter <sjr@debian.org> | |
| # Copyright (C) 2010, 2014 Jonathan Wiltshire <jmw@debian.org> | |
| # | |
| # This program is free software; you can redistribute it and/or | |
| # modify it under the terms of the GNU General Public License | |
| # as published by the Free Software Foundation, either version 3 | |
| # of the License, or (at your option) any later version. | |
| set -e | |
| rc=0 | |
| load_rules() | |
| { | |
| #load IPSet rules | |
| if [ ! -f /etc/iptables/rules.ipset ]; then | |
| echo "Warning: skipping IPSet (no rules to load)" | |
| else | |
| ipset restore -! < /etc/iptables/rules.ipset 2> /dev/null | |
| if [ $? -ne 0 ]; then | |
| rc=1 | |
| fi | |
| fi | |
| } | |
| save_rules() | |
| { | |
| #save IPSet rules | |
| #need at least ip_set loaded: | |
| /sbin/modprobe -q ip_set | |
| if [ -x /sbin/ipset ]; then | |
| touch /etc/iptables/rules.ipset | |
| chmod 0640 /etc/iptables/rules.ipset | |
| ipset save | grep -iv "f2b" > /etc/iptables/rules.ipset | |
| if [ $? -ne 0 ]; then | |
| rc=1 | |
| fi | |
| fi | |
| } | |
| flush_rules() | |
| { | |
| if [ -x /sbin/ipset ]; then | |
| ipset flush | |
| fi | |
| } | |
| case "$1" in | |
| start|restart|reload|force-reload) | |
| load_rules | |
| ;; | |
| save) | |
| save_rules | |
| ;; | |
| stop) | |
| # Why? because if stop is used, the firewall gets flushed for a variable | |
| # amount of time during package upgrades, leaving the machine vulnerable | |
| # It's also not always desirable to flush during purge | |
| echo "Automatic flushing disabled, use \"flush\" instead of \"stop\"" | |
| ;; | |
| flush) | |
| flush_rules | |
| ;; | |
| *) | |
| echo "Usage: $0 {start|restart|reload|force-reload|save|flush}" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| exit $rc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment