---
title: ZeroTier
date: 2024-11-16T14:07:31+08:00
lastmod: 2026-03-10T10:40:37+08:00
---
# ZeroTier
基础指令:`zerotier-cli peers`
> 1. [群晖部署](#20241214150529-9g8ngwv)
>
> 1. [Create a persistent TUN](#20241116140735-qtigym5)
> 2. [Install docker on your NAS](#20241116140735-9yxo6zx)
> 3. [Set up container](#20241116140735-kvb8bpq)
> 4. [Usage](#20241116140735-utigdu9)
> 5. [Upgrading ZeroTier](#20241116140735-ywc4iy4)
> 2. [iStoreOS部署](#20241214150547-17h0b8e)
> 3. [删除 ZeroTier 网络:](#20241214150746-h67e5fb)
> 4. [卸载ZeroTier](#20241214150740-6qd6cit)
# 群晖部署
## Create a persistent TUN
SSH into your NAS
```sh
ssh user@local-ip
```
The following setup steps must be run as root
```sh
sudo -i
```
Write script to `/usr/local/etc/rc.d/tun.sh` that will setup `/dev/net/tun` on startup
```sh
echo -e '#!/bin/sh -e \ninsmod /lib/modules/tun.ko' > /usr/local/etc/rc.d/tun.sh
```
Set executable permissions on script
```sh
chmod a+x /usr/local/etc/rc.d/tun.sh
```
Run script once to create a TUN
```sh
/usr/local/etc/rc.d/tun.sh
```
Check for the TUN
```sh
ls /dev/net/tun
/dev/net/tun
```
*If you experience trouble getting the TUN to work check out* *[Rui Marinho's guide](https://memoryleak.dev/post/fix-tun-tap-not-available-on-a-synology-nas/)*
## Install [docker](https://www.synology.com/en-us/dsm/packages/Docker) on your NAS
`Package Center -> Search "Docker" -> Install`
## Set up container
Make directory to store ZeroTier's identity and config
```sh
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](https://hub.docker.com/repository/docker/zerotier/zerotier-synology))
```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
```
```yaml
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
```sh
docker exec -it zt zerotier-cli status
```
Join your network
```sh
docker exec -it zt zerotier-cli join e5cd7a9e1cae134f
```
Authorize the NAS on your [network](https://my.zerotier.com/). Then view the network status:
```sh
docker exec -it zt zerotier-cli listnetworks
```
Show running container (optional)
```sh
docker ps
```
Enter the container (optional)
```sh
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:
```sh
docker ps
```
Example output:
```sh
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
```sh
docker stop 52c7cb58a1dd
```
Remove the container
```sh
docker container rm 52c7cb58a1dd
```
Pull latest updates
```sh
docker pull zerotier/zerotier-synology:latest
```
Now, re-run the commands from the [Set up container](https://docs.zerotier.com/synology/#set-up-container) section.
# iStoreOS部署
1. **更新软件包列表**: 打开终端,确保你的系统是最新的:
```bash
opkg update
```
2. **安装 ZeroTier**: 你需要添加 ZeroTier 的官方源,然后安装 ZeroTier。
```bash
opkg install zerotier
```
3. **启用 ZeroTier 服务**:
你需要手动启用 ZeroTier 服务。编辑 `/etc/config/zerotier` 文件并将 `enabled` 设置为 `1`,以便启动服务。
编辑配置文件:
```bash
vi /etc/config/zerotier
```
查找并修改以下部分:
```bash
config zerotier 'global'
option enabled '1' # 如果为 '0',改为 '1' 启用 ZeroTier 服务
```
4. **启动 ZeroTier 服务**: 安装完成后,启动 ZeroTier 服务:
```bash
/etc/init.d/zerotier start
```
5. **将 ZeroTier 设置为开机自启**: 设置 ZeroTier 在系统启动时自动启动:
```bash
/etc/init.d/zerotier enable
```
6. **加入 ZeroTier 网络**: 使用以下命令加入你的 ZeroTier 网络。请替换 `your_network_id` 为你的 ZeroTier 网络 ID:
```bash
zerotier-cli join your_network_id
```
7. **验证连接**: 查看 ZeroTier 设备的状态,确保它已成功连接到网络:
```bash
zerotier-cli status
```
8. **查看设备在 ZeroTier 网络中的状态**: 在 ZeroTier 控制面板([https://my.zerotier.com)中,确认你的设备已连接,并授权该设备。]()
# 删除 ZeroTier 网络:
1. **使用** **`zerotier-cli leave`** **命令退出网络**:
首先,运行以下命令来离开该网络:
```bash
zerotier-cli leave 8056c2e21c000001
```
这会将设备从 `NOT_FOUND` 状态的网络中移除。
2. **验证网络是否删除**:
执行完离开命令后,运行以下命令来验证网络是否已经从列表中删除:
```bash
zerotier-cli listnetworks
```
如果网络已经成功删除,它将不再出现在列表中。
# 卸载ZeroTier
1. **停止 ZeroTier 服务**:
在卸载之前,首先停止 ZeroTier 服务:
```bash
/etc/init.d/zerotier stop
```
2. **卸载 ZeroTier 包**:
使用 `opkg` 卸载 ZeroTier 包:
```bash
opkg remove zerotier
```
3. **删除配置文件和数据目录**:
为了彻底清理之前的安装,可以删除配置文件和数据目录:
```bash
rm -rf /etc/config/zerotier
rm -rf /var/lib/zerotier-one
```
**注意**:这会删除 ZeroTier 的所有配置和数据,包括网络信息。如果你以后打算重新使用同一个网络或保存当前配置,记得先备份这些文件。
4. **检查 ZeroTier 是否完全卸载**:
通过以下命令确认 ZeroTier 是否已完全卸载:
```bash
zerotier-cli info
```
如果输出类似 `command not found` 或提示 `ZeroTier not installed`,则表示已成功卸载。