From 50b22bba7952498d5d3042adbbf842d923bc8631 Mon Sep 17 00:00:00 2001 From: Josh J Date: Thu, 12 Aug 2021 16:12:07 +0100 Subject: [PATCH] Init Commit --- Dockerfile | 17 +++++++++++++++++ entrypoint.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7b86183 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM debian:buster as stage +ARG PACKAGE_BASEURL=https://download.zerotier.com/debian/buster/pool/main/z/zerotier-one +ARG ARCH=amd64 +ARG VERSION=1.6.5 +RUN apt-get update -qq && apt-get install -qq --no-install-recommends -y ca-certificates=20200601~deb10u2 curl=7.64.0-4+deb10u2 +RUN curl -sSL -o zerotier-one.deb "${PACKAGE_BASEURL}/zerotier-one_${VERSION}_${ARCH}.deb" + +FROM debian:buster +COPY --from=stage zerotier-one.deb . +RUN apt-get update -qq && apt-get install -qq --no-install-recommends -y procps=2:3.3.15-2 iptables=1.8.2-4 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* +RUN dpkg -i zerotier-one.deb && rm -f zerotier-one.deb +RUN echo "${VERSION}" >/etc/zerotier-version +COPY entrypoint.sh /entrypoint.sh +RUN chmod 755 /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..bd8f0fc --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +grepzt() { + (find /proc -name exe | xargs -I{} readlink {}) 2>/dev/null | grep -q zerotier-one + return $? +} + +echo "starting zerotier" +setsid /usr/sbin/zerotier-one & + +while ! grepzt +do + echo "zerotier hasn't started, waiting a second" + sleep 1 +done + +echo "joining networks: $ZT_NETWORK" + +echo "joining $ZT_NETWORK" + +while ! zerotier-cli join "$ZT_NETWORK" +do + echo "joining $ZT_NETWORK failed; trying again in 1s" + sleep 1 +done + + +### Set IPTables to allow NATting +echo "setting up NATting" +sysctl -w net.ipv4.ip_forward=1 +PHY_IFACE=eth0; ZT_IFACE=$(ls /sys/class/net | grep ^zt) + +iptables -t nat -A POSTROUTING -o $PHY_IFACE -j MASQUERADE +iptables -A FORWARD -i $PHY_IFACE -o $ZT_IFACE -m state --state RELATED,ESTABLISHED -j ACCEPT +iptables -A FORWARD -i $ZT_IFACE -o $PHY_IFACE -j ACCEPT + +echo "iptables --list-rules" +echo "$(ip a)" + +sleep infinity \ No newline at end of file