Combine LAN and Zerotier Network

22nd March 2023, 15:00:00

Intro

Setting up a Zerotier network coupled with an Unraid server was in my opinion a bit tricky, and I couldn’t find a single website which mentions everything needed.

This tutorial allows you to connect from a Zerotier system to any LAN system, and from any LAN system to any Zerotier system.

Requirements

  • A linux installation with Zerotier installed. For Unraid I used the app from Spikhalskiy.
  • A router with static routes support (You can ignore this step if you only want Zerotier systems to connect to any LAN system but not the other way around)

Details

  • $LAN: 192.168.178.0/24
  • $ZEROTIER: 192.168.195.0/24
  • $UNRAID_LAN: 192.168.178.250 (static)
  • $UNRAID_ZEROTIOER: 192.168.195.250 (static ip)
  • $ZEROTIERINTERFACE: The interface name of the Zerotier interface

1. Setup a route in Zerotier

Open the Zerotier Dashboard and add a new route with the following settings:

  • Destionation: $LAN
  • Via: $UNRAID_ZEROTIOER

Screenshot of the managed routes settings

2. Setup a route in your router

Open your routers website and add a new route with the following settings:

  • Network / Destination: $ZEROTIER
  • Gateway / Via: $UNRAID_LAN

Screenshot of the routers routes settings

3. Add a user script in unraid

  • (Install the users script addon if you haven’t already)
  • Create a new user script and change it to run at startup
  • Open up a terminal and run ip addr, find the Zerotier interface and note the interface name. (Starts with ZT)
  • Open up the user script with nano and set its content to:

(Make sure to $ZEROTIERINTERFACE with the actual interface name)

1
2
3
4
5
#!/bin/bash

iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE
iptables -A FORWARD -i br0 -o $ZEROTIERINTERFACE -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $ZEROTIERINTERFACE -o br0 -j ACCEPT
  • Run the script

4. Test

Now you should be able to access any LAN system via Zerotier, and access any Zerotier system via your LAN network without needing to have Zerotier installed on any computer.