summarylogtreecommitdiffstats
path: root/wgiptables.sh
diff options
context:
space:
mode:
authorNebulosa20072023-10-15 21:26:23 +0300
committerNebulosa20072023-10-15 21:26:23 +0300
commitf2de24686ce70a398352fae9b5c2b2aa2e6b2c09 (patch)
tree2202b5e37f94e0128d354693521bc8fe83cd3d22 /wgiptables.sh
downloadaur-f2de24686ce70a398352fae9b5c2b2aa2e6b2c09.tar.gz
Initial commit
Diffstat (limited to 'wgiptables.sh')
-rw-r--r--wgiptables.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/wgiptables.sh b/wgiptables.sh
new file mode 100644
index 000000000000..55f0f12c4582
--- /dev/null
+++ b/wgiptables.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# From: https://github.com/angristan/wireguard-install
+
+SERVER_WG_NIC="wg0" #Default interface
+SERVER_PUB_NIC=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | head -1)
+SERVER_PORT=$(grep -Po '(?<=ListenPort = )(\S+)' "/etc/wireguard/"$SERVER_WG_NIC".conf")
+
+if [ "$1" == "up" ]; then
+ iptables -I INPUT -p udp --dport $SERVER_PORT -j ACCEPT
+ iptables -I FORWARD -i $SERVER_PUB_NIC -o $SERVER_WG_NIC -j ACCEPT
+ iptables -I FORWARD -i $SERVER_WG_NIC -j ACCEPT
+ iptables -t nat -A POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE
+ ip6tables -I FORWARD -i $SERVER_WG_NIC -j ACCEPT
+ ip6tables -t nat -A POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE
+fi
+
+if [ "$1" == "down" ]; then
+ iptables -D INPUT -p udp --dport $SERVER_PORT -j ACCEPT
+ iptables -D FORWARD -i $SERVER_PUB_NIC -o $SERVER_WG_NIC -j ACCEPT
+ iptables -D FORWARD -i $SERVER_WG_NIC -j ACCEPT
+ iptables -t nat -D POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE
+ ip6tables -D FORWARD -i $SERVER_WG_NIC -j ACCEPT
+ ip6tables -t nat -D POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE
+fi