feat: support multiple zt network joins

feat: add ZT_BRIDGE to control bridge functionality
This commit is contained in:
2021-08-13 12:31:24 +01:00
parent 64e4a473e7
commit 556195cd64
2 changed files with 27 additions and 14 deletions

View File

@@ -14,6 +14,7 @@ services:
volumes:
- zt_config:/var/lib/zerotier-one
environment:
- ZT_NETWORK=NETWORK_ID_HERE
- ZT_NETWORKS=NETWORK_ID_1 NETWORK_ID_2 NETWORK_ID_3
- ZT_BRIDGE=true
volumes:
zt_config:

View File

@@ -14,24 +14,36 @@ do
sleep 1
done
#echo "joining networks: $ZT_NETWORK"
# Set IPTables to allow NATting
sysctl -w net.ipv4.ip_forward=1 > /dev/null
echo "joining $ZT_NETWORK"
echo "joining networks: $ZT_NETWORKS"
while ! zerotier-cli join "$ZT_NETWORK"
do
echo "joining $ZT_NETWORK failed; trying again in 1s"
for n in $ZT_NETWORKS
do
echo "joining $n"
while ! zerotier-cli join "$n"
do
echo "joining $n failed; trying again in 1s"
sleep 1
done
if [ "$ZT_BRIDGE" = "true" ]
then
echo "iptables on $(zerotier-cli get $n portDeviceName)"
PHY_IFACE=eth0; ZT_IFACE=$(zerotier-cli get $n portDeviceName)
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
fi
done
# Give ZT a second realise it's online
sleep 10
# Print Client Info
echo "$(zerotier-cli info)"
# Set IPTables to allow NATting
sysctl -w net.ipv4.ip_forward=1 > /dev/null
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
sleep infinity