aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/autotunnel/example.conf9
-rwxr-xr-xscripts/autotunnel21
-rw-r--r--system/autotunnel@.service11
3 files changed, 41 insertions, 0 deletions
diff --git a/config/autotunnel/example.conf b/config/autotunnel/example.conf
new file mode 100644
index 0000000..3a348b4
--- /dev/null
+++ b/config/autotunnel/example.conf
@@ -0,0 +1,9 @@
+# Configuration file for autotunnel
+
+# Define a host to connect to
+# Must be resolvable or better even set up in /root/.ssh/config
+HOST=<hostname>
+
+# Define a tun device number to use
+# Make sure the same device is not used elsewhere on localhost and the machine to connect to!
+TUN_DEVICE=<a number>
diff --git a/scripts/autotunnel b/scripts/autotunnel
new file mode 100755
index 0000000..2a1f17b
--- /dev/null
+++ b/scripts/autotunnel
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+if [ -z "$SERVER_ALIVE_INTERVAL" ];then
+ SERVER_ALIVE_INTERVAL=45
+fi
+
+if [ -z "$SERVER_ALIVE_COUNT_MAX" ];then
+ SERVER_ALIVE_COUNT_MAX=2
+fi
+
+if [ -z "$MONITORING_PORT" ];then
+ MONITORING_PORT=0
+fi
+
+/usr/bin/autossh -M "$MONITORING_PORT" \
+ -NCTv \
+ -o ServerAliveInterval="$SERVER_ALIVE_INTERVAL" \
+ -o ServerAliveCountMax="$SERVER_ALIVE_COUNT_MAX" \
+ -o TCPKeepAlive=yes \
+ -w $TUN_DEVICE:$TUN_DEVICE \
+ $HOST
diff --git a/system/autotunnel@.service b/system/autotunnel@.service
new file mode 100644
index 0000000..405a7d7
--- /dev/null
+++ b/system/autotunnel@.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=AutoSSH managed SSH tunnel to predefined host
+After=network.target
+
+[Service]
+Environment="AUTOSSH_GATETIME=0"
+EnvironmentFile=/etc/autotunnel/%I.conf
+ExecStart=/usr/lib/systemd/scripts/autotunnel
+
+[Install]
+WantedBy=multi-user.target