Zerotier
Installation on Docker
Use zyclonite/zerotier image
For podman, need to map to zerotier-one folder in home folder if running as rootless, e.g ~/.containers/zerotier-one, this folder must be created before running docker run
docker run --name zerotier --device=/dev/net/tun \
--network=host -d \
--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add=SYS_ADMIN \
--env TZ=Etc/UTC --env PUID=$(id -u) --env PGID=$(id -g) \
--env ZEROTIER_ONE_LOCAL_PHYS=eth0 \
--env ZEROTIER_ONE_USE_IPTABLES_NFT=true \
--env ZEROTIER_ONE_GATEWAY_MODE=inbound \
--env ZEROTIER_ONE_NETWORK_IDS=$networkid \
-v /var/lib/zerotier-one:/var/lib/zerotier-one \
zyclonite/zerotier:router--device=/dev/net/tun: Grants the container access to the /dev/net/tun device, which is required for creating virtual network interfaces (often needed for VPN or networking tools).
--network=host: Uses the host machine’s network stack instead of creating an isolated one for the container. This allows the container to directly interact with the host's network.
--cap-add=NET_ADMIN, NET_RAW, and SYS_ADMIN: Adds specific capabilities to the container. These are required for advanced networking and system administration tasks:
NET_ADMIN: Allows managing network configurations.
NET_RAW: Enables sending raw packets.
SYS_ADMIN: Grants access to system-level administrative privileges.
--env or -e: environment variables
TZ=Etc/UTC: Sets the time zone for the container.
PUID=$(id -u) and PGID=$(id -g): Passes the current user's ID and group ID to the container for proper permission handling.
ZEROTIER_ONE_LOCAL_PHYS=eth0: Specifies the physical network interface eth0 for ZeroTier.
ZEROTIER_ONE_USE_IPTABLES_NFT=true: Enables the use of iptables/nftables for firewall rules.
ZEROTIER_ONE_GATEWAY_MODE=inbound: Configures the container in inbound gateway mode.
ZEROTIER_ONE_NETWORK_IDS=$networkid: Sets the network IDs for the ZeroTier container
Docker file
main.sh
Build and Run Docker
docker build -t zerotier .
docker run -it --name zerotier --restart unless-stopped --cap-add=NET_ADMIN --cap-add=SYS_ADMIN --device=/dev/net/tun zerotier:latest /bin/bash
zerotier-one -d
zerotier-cli join $id
zerotier-cli leave $id
zerotier-cli listnetworks
zerotier-cli status
Using docker-compose
docker-compose up -d
Configuration Forwarding on container
apt-get update
apt-get upgrade -y
apt-get install procps -y
sysctl -w net.ipv4.ip_forward=1
to change it permanently: add/uncomment net.ipv4.ip_forward=1 to /etc/sysctl.conf
In proxmox, may need to unbind host settings to lxc container: add the following line to /etc/pve/lxc/xxx.conf
lxc.mount.entry = /proc/sys/net/ipv4/ip_forward proc/sys/net/ipv4/ip_forward none bind,optional,create=file
/proc/sys/net/ipv4/ip_forward: first is host, second is container
none bind: not linked, container will not inherit setting from host
optional: If the file doesn’t exist, the container won’t fail to start.
create=file: If the file doesn’t exist inside the container, it will be created automatically.
sysctl -p: apply the changes
sysctl net.ipv4.ip_forward
apt-get install iptables -y
iptables -t nat -A POSTROUTING -s $NetworkofZeroTier -j MASQUERADE
iptables -L -t nat
if needed, configuration forward rule as well
Save iptables and make it persistent: rule will be saved in /etc/iptables/rules.v4 and rules.v6
Install other utilities for testing:
apt-get install iproute2: ip add, route commands
apt-get install iputils-ping: ping command
Install as container in proxmox
Create containter
Create container as usual
Then, in proxmox shell, configure
lxc.cgroup.devices.allow: c 10:200 rwm
This line grants the container permission to access the TUN/TAP network device (c 10:200 refers to the character device with major number 10 and minor number 200).
The rwm flag allows read, write, and memory mapping operations on this device.
This is necessary for VPN software that creates virtual network interfaces inside the container.
lxc.mount.entry: /dev/net dev/net none bind,create=dir
This mounts the /dev/net directory inside the container, ensuring that the TUN/TAP device is accessible.
The bind option links the directory from the host system to the container.
The create=dir option ensures that the directory is created if it does not already exist.
if /dev/net/tun does not exist inside container, create it
Install zero inside container
curl -s https://install.zerotier.com | sudo bash
zerotier-cli join $networkid
zerotier-cli status
Verification
zerotier-cli listnetworks: list networks
-j: output in json format
Print List of network in table format
API
Get Network:
Get Member
Approve Member
Verify Approval Status
Reference
Last updated