ZeroTier.md 7.5 KB


title: ZeroTier date: 2024-11-16T14:07:31+08:00

lastmod: 2026-03-10T10:40:37+08:00

ZeroTier

  基础指令:zerotier-cli peers

  1. 群晖部署

    1. Create a persistent TUN
    2. Install docker on your NAS
    3. Set up container
    4. Usage
    5. Upgrading ZeroTier
  2. iStoreOS部署

  3. 删除 ZeroTier 网络:

  4. 卸载ZeroTier

  ‍

群晖部署

Create a persistent TUN

  SSH into your NAS

ssh user@local-ip

  The following setup steps must be run as root

sudo -i

  Write script to /usr/local/etc/rc.d/tun.sh​ that will setup /dev/net/tun on startup

echo -e '#!/bin/sh -e \ninsmod /lib/modules/tun.ko' > /usr/local/etc/rc.d/tun.sh

  Set executable permissions on script

chmod a+x /usr/local/etc/rc.d/tun.sh

  Run script once to create a TUN

/usr/local/etc/rc.d/tun.sh

  Check for the TUN

ls /dev/net/tun
/dev/net/tun

  If you experience trouble getting the TUN to work check out Rui Marinho's guide

Install docker on your NAS

  ​Package Center -> Search "Docker" -> Install

Set up container

  Make directory to store ZeroTier's identity and config

mkdir /var/lib/zerotier-one

  cautionIn the next step we bind mount to the host's /var/lib/zerotier-one created above in order to store ZeroTier's identity. This is not guaranteed to survive DSM updates. I would suggest placing this on an automatically-mounted volume where your other private user data resides. The location you choose to store your identities should be kept secure and never placed on a shared volume that others can access.

  Make Docker container called zt​ (Repo: zerotier/zerotier-synology)

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

version: '3.8'

services:
  zt:
    image: zerotier/zerotier-synology:latest
    container_name: zt
    restart: always
    devices:
      - /dev/net/tun
    network_mode: host
    cap_add:
      - NET_ADMIN
      - SYS_ADMIN
    volumes:
      - /var/lib/zerotier-one:/var/lib/zerotier-one

Usage

  Previous versions of our package contained a GUI, however this is no longer the case and it is for the better. The CLI can be used as follows:

  View node status

docker exec -it zt zerotier-cli status

  Join your network

docker exec -it zt zerotier-cli join e5cd7a9e1cae134f

  Authorize the NAS on your network. Then view the network status:

docker exec -it zt zerotier-cli listnetworks

  Show running container (optional)

docker ps

  Enter the container (optional)

docker exec -it zt bash

Upgrading ZeroTier

  To upgrade ZeroTier you'll need to stop and remove the container, then pull latest and start a new container:

docker ps

  Example output:

CONTAINER ID   IMAGE                               COMMAND          CREATED       STATUS      PORTS     NAMES
52c7cb58a1dd   zerotier/zerotier-synology:latest   "zerotier-one"   5 weeks ago   Up 9 days             zt

  Stop the container

docker stop 52c7cb58a1dd

  Remove the container

docker container rm 52c7cb58a1dd

  Pull latest updates

docker pull zerotier/zerotier-synology:latest

  Now, re-run the commands from the Set up container section.

iStoreOS部署

  1. 更新软件包列表: 打开终端,确保你的系统是最新的:

    opkg update
    
  2. 安装 ZeroTier: 你需要添加 ZeroTier 的官方源,然后安装 ZeroTier。

    opkg install zerotier
    
  3. 启用 ZeroTier 服务

你需要手动启用 ZeroTier 服务。编辑 /etc/config/zerotier​ 文件并将 enabled​ 设置为 1,以便启动服务。

编辑配置文件:

   vi /etc/config/zerotier

查找并修改以下部分:

   config zerotier 'global'
       option enabled '1'  # 如果为 '0',改为 '1' 启用 ZeroTier 服务
  1. 启动 ZeroTier 服务: 安装完成后,启动 ZeroTier 服务:

    /etc/init.d/zerotier start
    
  2. 将 ZeroTier 设置为开机自启: 设置 ZeroTier 在系统启动时自动启动:

    /etc/init.d/zerotier enable
    
  3. 加入 ZeroTier 网络: 使用以下命令加入你的 ZeroTier 网络。请替换 your_network_id 为你的 ZeroTier 网络 ID:

    zerotier-cli join your_network_id
    
  4. 验证连接: 查看 ZeroTier 设备的状态,确保它已成功连接到网络:

    zerotier-cli status
    
  5. 查看设备在 ZeroTier 网络中的状态: 在 ZeroTier 控制面板([https://my.zerotier.com)中,确认你的设备已连接,并授权该设备。]()

删除 ZeroTier 网络:

  1. 使用 zerotier-cli leave命令退出网络
    首先,运行以下命令来离开该网络:

    zerotier-cli leave 8056c2e21c000001
    

这会将设备从 NOT_FOUND 状态的网络中移除。

  1. 验证网络是否删除
    执行完离开命令后,运行以下命令来验证网络是否已经从列表中删除:

    zerotier-cli listnetworks
    

如果网络已经成功删除,它将不再出现在列表中。

卸载ZeroTier

  1. 停止 ZeroTier 服务
    在卸载之前,首先停止 ZeroTier 服务:

    /etc/init.d/zerotier stop
    
  2. 卸载 ZeroTier 包
    使用 opkg 卸载 ZeroTier 包:

    opkg remove zerotier
    
  3. 删除配置文件和数据目录
    为了彻底清理之前的安装,可以删除配置文件和数据目录:

    rm -rf /etc/config/zerotier
    rm -rf /var/lib/zerotier-one
    

注意:这会删除 ZeroTier 的所有配置和数据,包括网络信息。如果你以后打算重新使用同一个网络或保存当前配置,记得先备份这些文件。

  1. 检查 ZeroTier 是否完全卸载
    通过以下命令确认 ZeroTier 是否已完全卸载:

    zerotier-cli info
    

如果输出类似 command not found​ 或提示 ZeroTier not installed,则表示已成功卸载。