Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
ZeroTier
https://github.com/zerotier/docs
Admin
ZeroTier docs site
Tokens:
43,882
Snippets:
406
Trust Score:
9.5
Update:
1 year ago
Context
Chat
Benchmark
67.81
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Cloud-init Configuration Example Source: https://github.com/zerotier/docs/blob/main/docs/cloud-init.md This example demonstrates a basic cloud-init configuration for setting up a cloud instance. It configures the hostname, adds a user, installs packages, updates the package list, installs ZeroTier, joins a ZeroTier network, and restarts the SSH service. It requires `cloud-init` to be installed and configured on the cloud instance. ```yaml #cloud-config hostname: "devbox" users: - name: wrankles shell: /bin/bash disable_root: 1 ssh_pwauth: 0 packages: - htop - tcpdump runcmd: - apt-get update #- mkdir -p /var/lib/zerotier-one #- echo "1234567890:0:..." > /var/lib/zerotier-one/identity.secret #- echo "1234567890:0:..." > /var/lib/zerotier-one/identity.public - curl -s https://install.zerotier.com | bash - zerotier-cli join cfb8bf9836c2fc3a - systemctl restart ssh ``` -------------------------------- ### Run TUN Script Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Execute the TUN setup script to create the `/dev/net/tun` interface. This command manually triggers the script to create the TUN interface. ```sh /usr/local/etc/rc.d/tun.sh ``` -------------------------------- ### ZeroTier network setup and join Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Sets up a ZeroTier node, initializes it with a storage path, starts the node, and joins a specified ZeroTier network. It waits for the node to come online and the network transport to become ready before declaring the join successful. It requires the ZeroTier library and uses `ZeroTierNode` and `ZeroTierNative` classes. ```Java Context ctxt = this.getApplicationContext(); String storagePath = ctxt.getFilesDir().getAbsolutePath(); long nwid = Long.parseLong("0123456789abcdef", 16); String remoteAddr = "10.147.19.37"; int port = 8090; // ZeroTier setup ZeroTierNode node = new ZeroTierNode(); node.initFromStorage(storagePath); node.start(); Log.d(TAG, "Waiting for node to come online..."); while (! node.isOnline()) { ZeroTierNative.zts_util_delay(50); } Log.d(TAG, "Node ID: " + String.format("%010x", node.getId())); Log.d(TAG, "Joining network..."); node.join(nwid); Log.d(TAG, "Waiting for network..."); while (! node.isNetworkTransportReady(nwid)) { ZeroTierNative.zts_util_delay(50); } Log.d(TAG, "Joined"); ``` -------------------------------- ### Set TUN Script Permissions Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Set executable permissions on the TUN setup script. This allows the script to be executed during system startup. ```sh chmod a+x /usr/local/etc/rc.d/tun.sh ``` -------------------------------- ### Installing ZeroTier SDK with Pip Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Install the ZeroTier SDK using pip, the Python package installer. ```python pip install libzt ``` -------------------------------- ### Installing ZeroTier SDK with Brew Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Install the ZeroTier SDK using the Homebrew package manager on macOS. ```sh brew install zerotier/tap/libzt ``` -------------------------------- ### VLC server setup for streaming Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Sets up a VLC media server to stream a video file over HTTP. The first command installs VLC, and the second command starts VLC, loops the video, and streams it to port 8090. ```Shell sudo apt install vlc ``` ```Shell vlc mst3k.mp4 --loop --sout="#std{access=http, mux=ts, dst=:8090/sample}" ``` -------------------------------- ### Create TUN Script Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Create a shell script that will set up the `/dev/net/tun` interface on startup. This script ensures that the TUN interface is available after each reboot. ```sh echo -e '#!/bin/sh -e \ninsmod /lib/modules/tun.ko' > /usr/local/etc/rc.d/tun.sh ``` -------------------------------- ### Installing ZeroTier SDK with PowerShell Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Install the ZeroTier Sockets package using the PowerShell package manager. ```powershell Install-Package ZeroTier.Sockets ``` -------------------------------- ### ZeroTier Socket Usage Summary in Java Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Illustrates the basic steps to start a ZeroTier node, join a network, and create a ZeroTier socket in Java. ```java import com.zerotier.sockets.*; // ... ZeroTierNode node = new ZeroTierNode(); node.start(); // ... node.join(0x1234567890abcdef); // ... ZeroTierSocket socket = new ZeroTierSocket(remoteAddr, port); ``` -------------------------------- ### JSON Configuration Example Source: https://github.com/zerotier/docs/blob/main/docs/example.md This JSON snippet demonstrates a virtual network configuration with upstream role, try addresses, and a blacklist. It shows the structure for defining virtual network settings. ```json "virtual": { "feedbeef12": { "role": "UPSTREAM", "try": [ "10.10.20.1/9993" ], "blacklist": [ "192.168.0.0/24" ] } } ``` -------------------------------- ### ZeroTier Socket Usage Summary in C Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Illustrates the basic steps to start a ZeroTier node, join a network, create and connect a socket, and stop the node in C. ```c #include <ZeroTierSockets.h> // ... zts_node_start(); zts_net_join(0x1234567890abcdef); // ... int s = zts_socket(ZTS_AF_INET, ZTS_SOCK_STREAM, 0); zts_connect(s, in4, adddrlen); // ... zts_node_stop(); ``` -------------------------------- ### Python Script Example Source: https://github.com/zerotier/docs/blob/main/docs/example.md A simple Python script that imports a module and prints "ok" to the console. It demonstrates basic Python syntax. ```python import something print("ok") ``` -------------------------------- ### ZeroTier Socket Usage Summary in Python Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Illustrates the basic steps to start a ZeroTier node, join a network, create and connect a socket in Python. ```python import libzt # ... node = libzt.ZeroTierNode() node.node_start() # ... node.net_join(0x1234567890abcdef) # ... client = libzt.socket(libzt.ZTS_AF_INET, libzt.ZTS_SOCK_STREAM, 0) client.connect((remote_ip, remote_port)) ``` -------------------------------- ### Starting ZeroTier Service on Linux Source: https://github.com/zerotier/docs/blob/main/docs/controller.md Starts the ZeroTier service on Linux using systemctl. This command restarts the service after the controller configurations have been deleted. ```sh systemctl start zerotier-one ``` -------------------------------- ### Show Running Docker Containers Source: https://github.com/zerotier/docs/blob/main/docs/synology.md List all running Docker containers. This command helps verify that the ZeroTier container is running. ```sh docker ps ``` -------------------------------- ### Starting a ZeroTier Node Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This snippet shows how to start a ZeroTier node in different languages. The ZeroTier library will automatically generate a new identity if one is not provided. The node must be started before it can join networks or use sockets. ```c // No "node object" creation necessary in C zts_node_start(); ``` ```python node = libzt.ZeroTierNode() node.start() ``` ```rust let node = libzt::node::ZeroTierNode {}; node.start(); ``` ```csharp ZeroTier.Core.Node node = new ZeroTier.Core.Node(); node.Start(); ``` ```java ZeroTierNode node = new ZeroTierNode(); node.start(); ``` -------------------------------- ### ZeroTier Socket Usage Summary in C# Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Illustrates the basic steps to start a ZeroTier node, join a network, create and connect a socket, and stop the node in C#. ```csharp using ZeroTier; // ... ZeroTier.Core.Node node = new ZeroTier.Core.Node(); node.Start(); // ... node.Join(0x1234567890abcdef); // ... ZeroTier.Sockets.Socket sender = new ZeroTier.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sender.Connect(remoteServerEndPoint); // ... node.Stop(); ``` -------------------------------- ### Starting the local development server Source: https://github.com/zerotier/docs/blob/main/README.md Starts a local development server using the `make start` command. This allows for live previewing of changes without requiring a server restart. ```console make start ``` -------------------------------- ### Starting ZeroTier Service on macOS Source: https://github.com/zerotier/docs/blob/main/docs/controller.md Starts the ZeroTier service on macOS using launchctl. This command restarts the service after the controller configurations have been deleted. ```sh sudo launchctl load /Library/LaunchDaemons/com.zerotier.one.plist ``` -------------------------------- ### ZeroTier Socket Usage Summary in Rust Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Illustrates the basic steps to start a ZeroTier node, join a network, and connect a TCP stream in Rust. ```rust use libzt; use libzt::tcp::{TcpListener, TcpStream}; // ... let node = libzt::node::ZeroTierNode {}; node.start(); node.net_join(net_id); // ... TcpStream::connect(remote_addr); // ... node.stop(); ``` -------------------------------- ### Run ZeroTier Docker Container Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Create and run a ZeroTier Docker container with necessary configurations. This command sets up the ZeroTier container with device access, network settings, and volume mounts for persistent storage. ```sh docker run -d \ --name zt \ --restart=always \ --device=/dev/net/tun \ --net=host \ --cap-add=NET_ADMIN \ --cap-add=SYS_ADMIN \ -v /var/lib/zerotier-one:/var/lib/zerotier-one zerotier/zerotier-synology:latest ``` -------------------------------- ### Installing ZeroTier One Source: https://github.com/zerotier/docs/blob/main/docs/docker.md This command downloads and executes the ZeroTier One installation script using curl. It installs the ZeroTier One package and attempts to start the service. Note that starting the service may fail inside a Docker container without a proper init system. ```sh [root@5b88595860bc /]# curl https://install.zerotier.com/ | bash ``` -------------------------------- ### Install code-server Source: https://github.com/zerotier/docs/blob/main/docs/code-server.md Downloads and executes the installation script for code-server. ```sh curl -fsSL https://code-server.dev/install.sh | sh ``` -------------------------------- ### Installing ZeroTier via Command Line Source: https://github.com/zerotier/docs/blob/main/docs/faq-windows.md This command installs ZeroTier using the Windows command line. It requires administrative privileges and the correct path to the ZeroTier One MSI installer. ```sh msiexec /i "C:\Path\To\ZeroTier One.msi" ``` -------------------------------- ### Enter Docker Container Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Enter the ZeroTier Docker container to execute commands directly. This command provides a shell session inside the `zt` container. ```sh docker exec -it zt bash ``` -------------------------------- ### Check for TUN Interface Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Verify that the `/dev/net/tun` interface has been successfully created. This command lists the contents of the `/dev/net/` directory and confirms the existence of the `tun` device. ```sh ls /dev/net/tun /dev/net/tun ``` -------------------------------- ### Serving DNS with ZeroNSD Source: https://github.com/zerotier/docs/blob/main/docs/dns.md This snippet demonstrates how to start serving DNS for a specific ZeroTier network using ZeroNSD. Replace the example network ID with your own. It supervises the network, starts the zeronsd service, and enables the service. ```sh sudo zeronsd supervise -t /var/lib/zerotier-one/token -w -d beyond.corp af78bf94364e2035 sudo systemctl start zeronsd-af78bf94364e2035 sudo systemctl enable zeronsd-af78bf94364e2035 ``` -------------------------------- ### List ZeroTier Networks Source: https://github.com/zerotier/docs/blob/main/docs/synology.md List the ZeroTier networks that the node is currently connected to. This command displays the network status and configuration. ```sh docker exec -it zt zerotier-cli listnetworks ``` -------------------------------- ### Start, stop, or check ZeroTier service status Source: https://github.com/zerotier/docs/blob/main/docs/ubiquiti.md Manages the ZeroTier service on the Ubiquiti device using systemctl. This allows the user to check the status, start, or stop the ZeroTier service. ```sh sudo systemctl status|start|stop zerotier-one.service ``` -------------------------------- ### Gain Root Privileges via Sudo Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Escalate privileges to the root user. This is required to perform the subsequent configuration steps. ```sh sudo -i ``` -------------------------------- ### Start ZeroTier Service on Linux (systemctl) Source: https://github.com/zerotier/docs/blob/main/docs/faq.md This command starts the ZeroTier service on Linux systems using systemctl. It requires sudo privileges to execute. ```sh sudo systemctl start zerotier-one ``` -------------------------------- ### code-server config.yaml Example Source: https://github.com/zerotier/docs/blob/main/docs/code-server.md Example configuration for code-server, setting the bind address, authentication method, password, and disabling the certificate. ```yaml bind-addr: 10.241.208.61:8080 auth: password password: correcthorsebatterystaple cert: false ``` -------------------------------- ### List Docker Containers Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Lists all running Docker containers to identify the ZeroTier container's ID. This is a preliminary step to identify the container that needs to be upgraded. ```sh docker ps ``` -------------------------------- ### Join ZeroTier Network Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Join a ZeroTier network using the specified network ID. Replace 'e5cd7a9e1cae134f' with the actual network ID you wish to join. ```sh docker exec -it zt zerotier-cli join e5cd7a9e1cae134f ``` -------------------------------- ### Installing ZeroTier Snap Package Source: https://github.com/zerotier/docs/blob/main/docs/snap.md Installs the ZeroTier Snap package and checks its status. Requires root privileges. Joins the specified ZeroTier network. ```sh sudo snap install zerotier sudo zerotier status sudo zerotier join <nwid> ``` -------------------------------- ### Run code-server Source: https://github.com/zerotier/docs/blob/main/docs/code-server.md Starts the code-server application. ```sh code-server ``` -------------------------------- ### Create ZeroTier Data Directory Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Create a directory to store ZeroTier's identity and configuration files. This directory is used to persist ZeroTier's configuration across container restarts. ```sh mkdir /var/lib/zerotier-one ``` -------------------------------- ### Get Network Info Source: https://github.com/zerotier/docs/blob/main/docs/controller.md This command retrieves information about a specific ZeroTier network using a GET request to the local ZeroTierOne service API. It requires the Network ID and auth token. ```sh curl "http://localhost:9993/controller/network/${NWID}" -H "X-ZT1-AUTH: ${TOKEN}" ``` -------------------------------- ### Starting ZeroTier Service - Linux (init.d) Source: https://github.com/zerotier/docs/blob/main/docs/faq.md This command starts the ZeroTier service on Linux systems that use init.d. It is used when the ZeroTier service is not running. ```shell sudo /etc/init.d/zerotier-one start ``` -------------------------------- ### Start ZeroTier Service on Linux (service) Source: https://github.com/zerotier/docs/blob/main/docs/faq.md This command starts the ZeroTier service on Linux systems using the service command. It requires sudo privileges to execute. ```sh sudo service zerotier-one start ``` -------------------------------- ### Pull Latest Docker Image Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Pulls the latest version of the ZeroTier Synology Docker image from the repository. This ensures that the container is upgraded to the newest version. ```sh docker pull zerotier/zerotier-synology:latest ``` -------------------------------- ### Installing ZeroTier from a Specific Channel Source: https://github.com/zerotier/docs/blob/main/docs/snap.md Installs the ZeroTier Snap package from a specified channel (e.g., beta). Allows access to features not yet in the stable release. ```sh snap install zerotier --channel=latest/beta ``` -------------------------------- ### Example ZeroTier Network List Output Source: https://github.com/zerotier/docs/blob/main/docs/code-server.md Example output from the `zerotier-cli listnetworks` command, showing network details. ```text 200 listnetworks <nwid> <name> <mac> <status> <type> <dev> <ZT assigned ips> 200 listnetworks 8156abe27c21623c intranet.joseph.com 31:26:27:43:19:fb OK PRIVATE ztcjyorbnc fd80:76c1:124c:2268:1da9:9bf1:14d:ab3e/88,10.241.208.61/16 ``` -------------------------------- ### Initializing ZeroTier Node and Joining Network - C/C++ Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This C/C++ snippet initializes a ZeroTier node from storage, starts the node, joins a specified network, and retrieves the assigned IP address. It uses functions like zts_init_from_storage, zts_node_start, zts_net_join, and zts_addr_get_str. The code waits for the node to come online and the network transport to become ready before proceeding. ```c zts_init_from_storage(storage_path); zts_node_start(); while (! zts_node_is_online()) { zts_util_delay(1000); } printf("Node ID: %llx\n", zts_node_get_id()); zts_net_join(net_id); while (! zts_net_transport_is_ready(net_id)) { zts_util_delay(1000); } char ipstr[ZTS_IP_MAX_STR_LEN] = { 0 }; zts_addr_get_str(net_id, family, ipstr, ZTS_IP_MAX_STR_LEN); printf("IP address: %s\n", net_id, ipstr); ``` -------------------------------- ### Installing dependencies using Yarn Source: https://github.com/zerotier/docs/blob/main/README.md Installs the necessary dependencies for the project using Yarn package manager. This command is essential for setting up the development environment. ```console yarn install ``` -------------------------------- ### ExoPlayer client setup with ZeroTier Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Configures an ExoPlayer client to stream video over a ZeroTier network. It creates an OkHttpClient with a custom socket factory (ZeroTierSocketsSocketFactory) to route traffic through ZeroTier. It then sets up a data source factory and media source factory to use the OkHttpClient with ExoPlayer. ```Java // Socket logic OkHttpClient client = new OkHttpClient.Builder() .socketFactory(new ZeroTierSocketsSocketFactory(remoteAddr, port)) .build(); assert client instanceof Call.Factory; Call.Factory callFactory = (Call.Factory) client; OkHttpDataSource.Factory okhttpDataSourceFactory = new OkHttpDataSource.Factory(callFactory); DefaultDataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(ctxt, okhttpDataSourceFactory); ExoPlayer player = new ExoPlayer.Builder(ctxt) .setMediaSourceFactory( new DefaultMediaSourceFactory(ctxt).setDataSourceFactory(dataSourceFactory)) .build(); ``` -------------------------------- ### Initializing ZeroTier Node and Joining Network - C# Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This C# snippet initializes a ZeroTier node from storage, starts the node, joins a specified network, and retrieves the assigned IP addresses. It uses the ZeroTier.Core library. The code waits for the node to come online and the network transport to become ready before proceeding. ```csharp node = new ZeroTier.Core.Node(); node.InitFromStorage(configFilePath); node.Start(); while (! node.Online) { Thread.Sleep(1000); } Console.WriteLine("Node ID:" + node.Id) node.Join(networkId); while (! node.IsNetworkTransportReady(networkId)) { Thread.Sleep(1000); } foreach (IPAddress addr in node.GetNetworkAddresses(networkId)) { Console.WriteLine("IP address: " + addr); } ``` -------------------------------- ### Start ZeroTier Service on macOS Source: https://github.com/zerotier/docs/blob/main/docs/faq-macos.md This command starts the ZeroTier system service on macOS by loading the launch daemon. It requires administrator privileges. ```sh sudo launchctl load /Library/LaunchDaemons/com.zerotier.one.plist ``` -------------------------------- ### Traffic Monitoring Setup with tee and watch Source: https://github.com/zerotier/docs/blob/main/docs/terraform-multicloud.md This snippet sets up traffic monitoring using `tee` to capture output and `watch` to continuously observe inbound traffic on a specified interface. It also includes an `accept` command, likely related to traffic filtering or acceptance rules. ```sh tee -1 ${ethertap}; watch -1 ${ethertap} chr inbound; accept; ``` -------------------------------- ### Starting ZeroTier Service - Linux (systemd) Source: https://github.com/zerotier/docs/blob/main/docs/faq.md This command starts the ZeroTier service on Linux systems using systemd. It is used when the ZeroTier service is not running. ```shell sudo service zerotier-one start ``` -------------------------------- ### SSH into Synology NAS Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Connect to your Synology NAS via SSH using the specified username and IP address. Replace 'user' with your username and 'local-ip' with the IP address of your NAS. ```sh ssh user@local-ip ``` -------------------------------- ### Install Pi-Hole using curl and bash Source: https://github.com/zerotier/docs/blob/main/docs/pihole.md This command downloads and executes the Pi-Hole installation script. It uses curl to fetch the script from the specified URL and pipes it to bash for execution. This will install Pi-Hole with the default settings, prompting the user for configuration options during the installation process. ```sh curl -sSL https://install.pi-hole.net | bash ``` -------------------------------- ### Mermaid Diagram Example Source: https://github.com/zerotier/docs/blob/main/docs/example.md This Mermaid code defines a flowchart diagram with three subgraphs and connections between nodes. It illustrates how to create visual diagrams using Mermaid syntax. ```mermaid flowchart TB c1-->a2 subgraph one a1-->a2 end subgraph two b1-->b2 end subgraph three c1-->c2 end ``` -------------------------------- ### List Networks Source: https://github.com/zerotier/docs/blob/main/docs/controller.md This command retrieves a list of Network IDs using a GET request to the local ZeroTierOne service API. It requires the auth token for authentication. ```sh curl "http://localhost:9993/controller/network" -H "X-ZT1-AUTH: ${TOKEN}" ``` -------------------------------- ### Install ZeroTier-One using Chocolatey Source: https://github.com/zerotier/docs/blob/main/docs/chocolatey.md This command installs the ZeroTier One client on Windows using the Chocolatey package manager. It assumes that Chocolatey is already installed on the system. The command fetches and installs the latest version of ZeroTier One from the Chocolatey package repository. ```sh choco install zerotier-one ``` -------------------------------- ### Initializing ZeroTier Node and Joining Network - Python Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This Python snippet initializes a ZeroTier node from storage, starts the node, joins a specified network, and retrieves the assigned IP address. It uses the libzt library. The code waits for the node to come online and the network transport to become ready before proceeding. ```python node = libzt.ZeroTierNode() node.init_from_storage(storage_path) node.node_start() while not node.node_is_online(): time.sleep(1) print("Node ID:", node.node_id()) node.net_join(net_id) while not node.net_transport_is_ready(net_id): time.sleep(1) print("IP address: ", node.addr_get_ipv4(net_id)) ``` -------------------------------- ### Installing ZeroNSD from Package Source: https://github.com/zerotier/docs/blob/main/docs/dns.md This snippet demonstrates how to install ZeroNSD using a deb package. It downloads the package and installs it using dpkg. ```sh wget https://github.com/zerotier/zeronsd/releases/download/v0.1.7/zeronsd_0.1.7_amd64.deb sudo dpkg -i zeronsd_0.1.7_amd64.deb ``` -------------------------------- ### Example 'listeningOn' JSON Output Source: https://github.com/zerotier/docs/blob/main/docs/troubleshooting.md This JSON snippet shows an example of the 'listeningOn' field in the output of `zerotier-cli info -j`. It lists the IP addresses and ports that ZeroTier is listening on. ```json { "listeningOn": [ "192.168.100.193/9993", "192.168.100.193/55957", "192.168.100.193/30431" ] } ``` -------------------------------- ### Installing ZeroNSD with Cargo Source: https://github.com/zerotier/docs/blob/main/docs/dns.md This snippet shows how to install ZeroNSD using cargo. It installs the necessary dependencies and then installs ZeroNSD using cargo install. ```sh sudo /usr/bin/apt-get -y install net-tools librust-openssl-dev pkg-config cargo sudo /usr/bin/cargo install zeronsd --root /usr/local ``` -------------------------------- ### Initializing ZeroTier Node and Joining Network - Rust Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This Rust snippet initializes a ZeroTier node from storage, starts the node, joins a specified network, and retrieves the assigned IP address. It uses the libzt crate. The code waits for the node to come online and the network transport to become ready before proceeding. ```rust let node = libzt::node::ZeroTierNode {}; node.init_from_storage(&storage_path); node.start(); while !node.is_online() { node.delay(1000); } println!("Node ID = {:#06x}", node.id()); node.net_join(net_id); while !node.net_transport_is_ready(net_id) { node.delay(1000); } let addr = node.addr_get(net_id).unwrap(); println!("IP address: {}", addr); ``` -------------------------------- ### Start ZeroTier Service on Linux (init.d) Source: https://github.com/zerotier/docs/blob/main/docs/troubleshooting.md This command starts the ZeroTier service on Linux distributions that use init.d. It ensures that the ZeroTier service is running in the background. ```sh /etc/init.d/zerotier-one start ``` -------------------------------- ### View ZeroTier Node Status Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Check the status of the ZeroTier node running inside the Docker container. This command executes the `zerotier-cli status` command within the `zt` container. ```sh docker exec -it zt zerotier-cli status ``` -------------------------------- ### Initializing ZeroTier Node and Joining Network - Java Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This Java snippet initializes a ZeroTier node from storage, starts the node, joins a specified network, and retrieves the assigned IPv4 address. It uses the ZeroTierNative library. The code waits for the node to come online and the network transport to become ready before proceeding. ```java ZeroTierNode node = new ZeroTierNode(); node.initFromStorage(storagePath); node.start(); while (! node.isOnline()) { ZeroTierNative.zts_util_delay(1000); } System.out.println("Node ID: " + Long.toHexString(node.getId())); node.join(networkId); while (! node.isNetworkTransportReady(networkId)) { ZeroTierNative.zts_util_delay(1000); } System.out.println("IP address: " + node.getIPv4Address(networkId).getHostAddress()); ``` -------------------------------- ### Building ZeroTier SDK JAR with Shell Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md Build a ZeroTier SDK JAR file using the provided build script. ```sh ./build.sh host-jar ``` -------------------------------- ### Creating a ZeroTier Network with Terraform Source: https://github.com/zerotier/docs/blob/main/docs/terraform-multicloud.md This Terraform resource defines a ZeroTier network named `demo.lab` with a description, IPv6 assignment settings, an assignment pool, and a route. ```Terraform resource "zerotier_network" "demolab" { name = "demo.lab" description = "ZeroTier Terraform Demolab" assign_ipv6 { zerotier = true sixplane = true rfc4193 = true } assignment_pool { start = "10.0.0.1" end = "10.0.0.254" } route { target = "10.0.0.0/16" } } ``` -------------------------------- ### List Networks via Central API (Shell curl) Source: https://github.com/zerotier/docs/blob/main/docs/api/central/examples.md This snippet uses curl to retrieve a list of networks from the ZeroTier Central API and formats the output as CSV using jq. It requires curl and jq to be installed. Replace $ZT_TOKEN with your actual ZeroTier API token. ```sh curl -s -H "Authorization: token $ZT_TOKEN" \ "https://api.zerotier.com/api/v1/network" \ | jq '.[] | [ .id, .config.name, .config.description, .totalMemberCount, .config.creationTime, .config.ipAssignmentPools[0].ipRangeStart, .config.ipAssignmentPools[0].ipRangeEnd ]' \ | jq -rs '.[] | @csv' ``` -------------------------------- ### Installing ZeroTier Systemd Manager Source: https://github.com/zerotier/docs/blob/main/docs/dns.md This snippet demonstrates how to install the ZeroTier Systemd Manager using a deb package. It downloads the package and installs it using dpkg. ```sh wget https://github.com/zerotier/zerotier-systemd-manager/releases/download/v0.1.9/zerotier-systemd-manager_0.1.9_linux_amd64.deb sudo dpkg -i zerotier-systemd-manager_0.1.9_linux_amd64.deb ``` -------------------------------- ### Install ZeroTier package Source: https://github.com/zerotier/docs/blob/main/docs/ubiquiti.md Installs the ZeroTier package on the Ubiquiti device using dpkg. This command assumes the package is located in the /config/data/firstboot/install-packages/ directory. ```sh sudo dpkg -i /config/data/firstboot/install-packages/zerotier-one.deb ``` -------------------------------- ### Install ZeroTier using WinGet Source: https://github.com/zerotier/docs/blob/main/docs/winget.md This command installs the ZeroTier One application using the WinGet package manager. The `--id` flag specifies the package identifier, and the `-e` flag likely indicates that the exact version should be installed. ```sh winget install --id=ZeroTier.ZeroTierOne -e ``` -------------------------------- ### List Network Members Source: https://github.com/zerotier/docs/blob/main/docs/controller.md This command retrieves a list of members in a specific ZeroTier network using a GET request to the local ZeroTierOne service API. It requires the Network ID and auth token. ```sh curl "http://localhost:9993/controller/network/${NWID}/member" -H "X-ZT1-AUTH: ${TOKEN}" ``` -------------------------------- ### Install ZeroTier Source: https://github.com/zerotier/docs/blob/main/docs/bridging.md This command downloads and executes the ZeroTier installation script. It uses curl to fetch the script from the ZeroTier website and then executes it with sudo to install ZeroTier on the system. ```shell curl -s https://install.zerotier.com | sudo bash ``` -------------------------------- ### Installing STUN client on Debian/Ubuntu Source: https://github.com/zerotier/docs/blob/main/docs/nat.md This command installs the STUN client on Debian or Ubuntu-based systems using the apt-get package manager. It is a prerequisite for performing NAT characterization tests. ```sh sudo apt-get install stun ``` -------------------------------- ### Troubleshooting PORT_ERROR: Start ZeroTier Service on macOS Source: https://github.com/zerotier/docs/blob/main/docs/faq-macos.md This command starts the ZeroTier system service on macOS by loading the launch daemon. It is used in troubleshooting PORT_ERROR and requires administrator privileges. ```sh sudo launchctl load /Library/LaunchDaemons/com.zerotier.one.plist ``` -------------------------------- ### Starting ZeroTier One and Joining a Network Source: https://github.com/zerotier/docs/blob/main/docs/docker.md These commands start the ZeroTier One daemon and join a specified ZeroTier network. The `zerotier-one -d` command starts the daemon in the background. The `zerotier-cli join <network_id>` command joins the container to the ZeroTier network with the given network ID. ```sh [root@5b88595860bc /]# /usr/sbin/zerotier-one -d [root@5b88595860bc /]# /usr/sbin/zerotier-cli join 8056c2e21c000001 200 join OK [root@5b88595860bc /]# /usr/sbin/zerotier-cli listnetworks 200 listnetworks 200 listnetworks 8056c2e21c000001 - 02:e6:10:ab:69:33 REQUESTING_CONFIGURATION PRIVATE zt0 - [root@5b88595860bc /]# /usr/sbin/zerotier-cli listnetworks 200 listnetworks 200 listnetworks 8056c2e21c000001 earth.zerotier.net 02:e6:10:ab:69:33 OK PUBLIC zt0 fd80:56c2:e21c:0000:0199:93e6:10b7:8bf1/88,28.183.140.10/7 ``` -------------------------------- ### Network Info Again Source: https://github.com/zerotier/docs/blob/main/docs/controller.md This command retrieves network information again to verify the changes after configuration and authorization. ```sh curl "http://localhost:9993/controller/network/${NWID}" -H "X-ZT1-AUTH: ${TOKEN}" ``` -------------------------------- ### Member Info Again Source: https://github.com/zerotier/docs/blob/main/docs/controller.md This command retrieves member information again to verify the changes after authorization. ```sh curl "http://localhost:9993/controller/network/${NWID}/member/${MEMID}" -H "X-ZT1-AUTH: ${TOKEN}" ``` -------------------------------- ### Starting and Enabling ndppd Service Source: https://github.com/zerotier/docs/blob/main/docs/exitnode.md These commands start the ndppd service and enable it to start on boot. This ensures that NDP proxying is active. ```sh systemctl start ndppd systemctl enable ndppd ``` -------------------------------- ### Troubleshooting authtoken.secret Error Source: https://github.com/zerotier/docs/blob/main/docs/snap.md Demonstrates how to resolve the 'authtoken.secret not found' error by using the interactive sudo form. ```sh user@host$ sudo -i root@host# zerotier status root@host# exit user@host$ ``` -------------------------------- ### List Network Members via Central API (Shell curl) Source: https://github.com/zerotier/docs/blob/main/docs/api/central/examples.md This snippet uses curl to retrieve a list of members for a specific network from the ZeroTier Central API and formats the output as CSV using jq. It requires curl and jq to be installed. Replace $ZT_TOKEN with your actual ZeroTier API token and $NWID with the network ID. ```sh curl -H "Authorization: token $ZT_TOKEN" \ "https://api.zerotier.com/api/v1/network/$NWID/member" \ | jq '.[] | [ .id, .lastSeen, .physicalAddress, .ipAssignments[0], .name ]' \ | jq -rs '.[] | @csv' ``` -------------------------------- ### Get Member Info Source: https://github.com/zerotier/docs/blob/main/docs/controller.md This command retrieves information about a specific member in a ZeroTier network using a GET request to the local ZeroTierOne service API. It requires the Network ID, Member ID, and auth token. ```sh curl "http://localhost:9993/controller/network/${NWID}/member/${MEMID}" -H "X-ZT1-AUTH: ${TOKEN}" ``` -------------------------------- ### Load ZeroTier Launch Daemon on macOS Source: https://github.com/zerotier/docs/blob/main/docs/faq.md This command loads the ZeroTier launch daemon on macOS, effectively starting the ZeroTier service. It requires sudo privileges to execute. ```sh sudo launchctl load /Library/LaunchDaemons/com.zerotier.one.plist ``` -------------------------------- ### Monitor TCP Connections - ZeroTier Rules Source: https://github.com/zerotier/docs/blob/main/docs/rules.md This example demonstrates a less bandwidth-intensive security monitor setup. It sends the first 128 bytes of every TCP SYN, RST, or FIN packet to one observer on the inbound side and another observer on the outbound side. It also sends the first 128 bytes of other packets with a probability of one in ten. ```ZeroTier Rules tee 128 deadbeef11 chr inbound and chr tcp_syn or chr tcp_rst or chr tcp_fin or random 0.1 ; tee 128 deadbeef22 not chr inbound and chr tcp_syn or chr tcp_rst or chr tcp_fin or random 0.1 ; ``` -------------------------------- ### STUN client output example Source: https://github.com/zerotier/docs/blob/main/docs/nat.md This is an example of the output generated by the STUN client after performing NAT characterization. It provides information about the NAT type, mapping behavior, filtering behavior, port preservation, and hairpinning support. ```sh STUN client version 0.96 running test number 0 Primary: Independent Mapping, Port Dependent Filter, preserves ports, no hairpin Return value is 0x000017 ``` -------------------------------- ### Start ZeroTier Service on Linux (systemd) Source: https://github.com/zerotier/docs/blob/main/docs/troubleshooting.md This command starts the ZeroTier service on Linux distributions that use systemd. It ensures that the ZeroTier service is running in the background. ```sh sudo service zerotier-one start ``` -------------------------------- ### Getting Network Addresses Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This code snippet retrieves all network addresses assigned to the ZeroTier node and prints them to the console. ```csharp foreach (IPAddress addr in node.GetNetworkAddresses(networkId)) { Console.WriteLine(addr); } ``` -------------------------------- ### Confirm from your nodes Source: https://github.com/zerotier/docs/blob/main/docs/controller.md This command lists the networks the node is connected to using the zerotier-cli tool. It confirms the network status and IP address assignment. ```sh sudo zerotier-cli listnetworks ``` -------------------------------- ### Example iptables Rules Source: https://github.com/zerotier/docs/blob/main/docs/exitnode.md This is an example of the iptables rules that should be present after configuring the exit node. It shows the FORWARD and POSTROUTING rules that are necessary for NAT and traffic forwarding. ```none ...\n\n-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A FORWARD -i zthnhhqofq -o eth0 -j ACCEPT ... -A POSTROUTING -o eth0 -j MASQUERADE ... ``` -------------------------------- ### Authelia Client Configuration Example Source: https://github.com/zerotier/docs/blob/main/docs/sso.md This YAML snippet shows an example client configuration for Authelia, a self-hosted SSO solution. It highlights the requirement for an empty secret and a public client, along with other settings like redirect URIs and scopes. ZeroTierOne version 1.10.1 or greater is required. ```yaml clients: ## The ID is the OpenID Connect ClientID which is used to link an application to a configuration. - id: authelia-sso-client ## The description to show to users when they end up on the consent screen. Defaults to the ID above. description: zerotier ## The client secret is a shared secret between Authelia and the consumer of this client. secret: "" ## Sector Identifiers are occasionally used to generate pairwise subject identifiers. In most cases this is not ## necessary. Read the documentation for more information. ## The subject identifier must be the host component of a URL, which is a domain name with an optional port. # sector_identifier: example.com ## Sets the client to public. This should typically not be set, please see the documentation for usage. public: true ## The policy to require for this client; one_factor or two_factor. authorization_policy: one_factor ## By default users cannot remember pre-configured consents. Setting this value to a period of time using a ## duration notation will enable users to remember consent for this client. The time configured is the amount ## of time the pre-configured consent is valid for granting new authorizations to the user. # pre_configured_consent_duration: ## Audience this client is allowed to request. audience: [ "authelia-test-client" ] ## Scopes this client is allowed to request. scopes: - openid - groups - email - profile - offline_access ## Redirect URI's specifies a list of valid case-sensitive callbacks for this client. redirect_uris: - http://localhost:9993/sso ## Grant Types configures which grants this client can obtain. ## It's not recommended to define this unless you know what you're doing. grant_types: - refresh_token - authorization_code ## Response Types configures which responses this client can be sent. ## It's not recommended to define this unless you know what you're doing. response_types: - code - id_token ## Response Modes configures which response modes this client supports. response_modes: - form_post - query - fragment ## The algorithm used to sign userinfo endpoint responses for this client, either none or RS256. userinfo_signing_algorithm: none ``` -------------------------------- ### Stop Docker Container Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Stops the specified Docker container using its ID. This is a necessary step before removing the container for the upgrade process. ```sh docker stop 52c7cb58a1dd ``` -------------------------------- ### Setting up TCP Client with ZeroTier in Java Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This Java snippet sets up a ZeroTier socket, connects to a remote address and port, retrieves the output stream, writes the message "Hello, network!" as UTF, and then cleans up by closing the socket and stopping the node. ```java // Set up connection socket ZeroTierSocket socket = new ZeroTierSocket(remoteAddr, port); ZeroTierOutputStream outputStream = socket.getOutputStream(); DataOutputStream dataOutputStream = new DataOutputStream(outputStream); // TX dataOutputStream.writeUTF("Hello, network!"); // Cleanup socket.close(); node.stop(); ``` -------------------------------- ### Getting IPv4 and IPv6 Addresses Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This code snippet retrieves the IPv4 and IPv6 addresses assigned to the ZeroTier node and prints them to the console. ```java System.out.println(node.getIPv4Address(networkId).getHostAddress()); System.out.println(node.getIPv6Address(networkId).getHostAddress()); ``` -------------------------------- ### Example 'surfaceAddresses' JSON Output Source: https://github.com/zerotier/docs/blob/main/docs/troubleshooting.md This JSON snippet shows an example of the 'surfaceAddresses' field in the output of `zerotier-cli info -j`. It lists the external IP addresses and ports that ZeroTier is using to communicate with other nodes. ```json { "surfaceAddresses": [ "198.51.100.9/24/9993", "198.51.100.9/30431", "198.51.100.9/2785" ] } ``` -------------------------------- ### Getting IPv4 and IPv6 Addresses Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This code snippet retrieves the IPv4 and IPv6 addresses assigned to the ZeroTier node and prints them to the console. ```python print(node.addr_get_ipv4(net_id)) print(node.addr_get_ipv6(net_id)) ``` -------------------------------- ### Getting IP Address Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This code snippet retrieves the IP address assigned to the ZeroTier node. It retrieves the address and prints it to the console. ```rust let addr = node.addr_get(net_id).unwrap(); println!("{}", addr); ``` -------------------------------- ### Remove Docker Container Source: https://github.com/zerotier/docs/blob/main/docs/synology.md Removes the specified Docker container using its ID. This step is performed after stopping the container and before pulling the latest image. ```sh docker container rm 52c7cb58a1dd ``` -------------------------------- ### ZeroTier Rule Definition Language Example Source: https://github.com/zerotier/docs/blob/main/docs/rules.md This example demonstrates the ZeroTier rule definition language, showcasing how to whitelist IPv4, ARP, and IPv6 traffic, allow SSH, HTTP, and HTTPS, create a tag for department classification, and drop TCP SYN packets. It also defines a 'superuser' capability. ```Text # Whitelist only IPv4 (/ARP) and IPv6 traffic and allow only ZeroTier-assigned IP addresses drop # drop cannot be overridden by capabilities not ethertype ipv4 # frame is not ipv4 and not ethertype arp # AND is not ARP and not ethertype ipv6 # AND is not ipv6 or not chr ipauth # OR IP addresses are not authenticated (1.2.0+ only!) ; # Allow SSH, HTTP, and HTTPS by allowing all TCP packets (including SYN/!ACK) to these ports accept dport 22 or dport 80 or dport 443 and ipprotocol tcp ; # Create a tag for which department someone is in tag department id 1000 # arbitrary, but must be unique enum 100 sales # has no meaning to filter, but used in UI to offer a selection enum 200 engineering enum 300 support enum 400 manufacturing default 0 ; # Allow Windows CIFS and netbios between computers in the same department using a tag accept dport 139 or dport 445 and ipprotocol tcp and tdiff department 0 # difference between department tags is 0, meaning they match ; # Drop TCP SYN,!ACK packets (new connections) not explicitly whitelisted above break # break can be overridden by a capability chr tcp_syn # TCP SYN (TCP flags will never match non-TCP packets) and not chr tcp_ack # AND not TCP ACK ; # Create a capability called "superuser" that lets its holders override all but the initial "drop" cap superuser id 1000 # arbitrary, but must be unique accept; # allow with no match conditions means allow anything and everything ; ``` -------------------------------- ### Serving Non-ZeroTier Records Source: https://github.com/zerotier/docs/blob/main/docs/dns.md This command starts a temporary ZeroNSD server to serve non-ZeroTier records. It uses the `zeronsd start` subcommand with the `-t`, `-f`, and `-d` flags to specify the token, hosts file, and domain. ```sh $ zeronsd start -t /var/lib/zerotier-one/token -f ./hosts -d beyond.corp <network id> Welcome to ZeroNS! Your IP is 1.2.3.4 ``` -------------------------------- ### Create persistent directory for ZeroTier Source: https://github.com/zerotier/docs/blob/main/docs/ubiquiti.md Creates a directory to store ZeroTier installation packages, ensuring they persist across firmware upgrades on Ubiquiti devices. This directory is used to automatically re-install ZeroTier after an upgrade. ```sh mkdir -p /config/data/firstboot/install-packages/ ``` -------------------------------- ### Getting IPv4 Address Source: https://github.com/zerotier/docs/blob/main/docs/sockets.md This code snippet retrieves the IPv4 address assigned to the ZeroTier node. It converts the address to a string and prints it to the console. ```c char ipstr[ZTS_IP_MAX_STR_LEN] = { 0 }; zts_addr_get_str(net_id, ZTS_AF_INET, ipstr, ZTS_IP_MAX_STR_LEN); printf("%s\n", ipstr); ``` -------------------------------- ### ndppd Configuration Rule Example Source: https://github.com/zerotier/docs/blob/main/docs/exitnode.md This shows an example rule for ndppd.conf. It tells ndppd to answer NDP requests for the entire /80 from which IPv6 addresses will be assigned to devices. The IP prefix must be changed to your own. ```text rule 2001:19f0:6001:01a6:00ff:0000:0000:0000/80 { ``` -------------------------------- ### x86 QNAP NAS Models Source: https://github.com/zerotier/docs/blob/main/docs/qnap.md Lists QNAP NAS models that use the x86 processor architecture. This information is used to select the correct ZeroTier package for installation. ```sh TS-x51 Series, TS-x51+ Series, TS-x51A Series, TS-x53B Series, TS-x53A Series, TS-x53U Series TS-239 Pro, TS-239 Pro II, TS-239 Pro II+, TS-251, TS-253A, TS-259 Pro, TS-259 Pro+, TS-269L, TS-439 Pro II, TS-451, TS-459 Pro, TS-439 Pro, TS-459U-RP+/SP+, TS-439 Pro II+, TS-459 Pro II, TS-459 Pro+, TS-459U-RP/SP, SS-439-Pro TS-469L, TS-651, TS-851 ```