aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/firewall.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/firewall.sh b/scripts/firewall.sh
new file mode 100755
index 0000000..0669e7f
--- /dev/null
+++ b/scripts/firewall.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+allow_proto_port() {
+ sudo iptables -I INPUT -p $1 --dport $2 -j ACCEPT;
+ sudo ip6tables -I INPUT -p $1 --dport $2 -j ACCEPT;
+}
+
+allow_port() {
+ [[ $# != 1 ]] && echo "Invalid command: firewall allow <port>" && exit 1;
+ allow_proto_port tcp $1;
+ allow_proto_port udp $1;
+}
+
+restore_table() {
+ sudo iptables-restore < ~/dump/iptables-backup;
+}
+
+cmd="$1"; shift;
+
+case "$cmd" in
+ allow) allow_port "$@" ;;
+ restore) restore_table ;;
+ *) echo "Invalid command" && exit 1 ;;
+esac;
+