Skip to content

Commit 8551038

Browse files
authored
addresses documentation problems raised in issue 35 (#36)
Responses to #35: 1. Revises `docker run` example: * places container in host mode * runs container detached (so it does not appear to stall) * passes the user and group IDs for the local user (so persistent storage is owned by the local user) * changes default mechanism for net-filter rules to `iptables-nft` * places image reference on a separate line 2. Revises `docker compose` service definition: * removes deprecated `version` clause, substituting the "here comes YAML" `---` signature * changes default mechanism for net-filter rules to `iptables-nft` 3. Re-writes explanation of `ZEROTIER_ONE_USE_IPTABLES_NFT` to make it clear that `true` is usually the correct option for all implementations (not just Raspberry Pi). Also adds explicit test to confirm that the container's net-filters are getting into the host's tables. Opportunistic changes: 1. Updates URLs for ZeroTier Knowledge Base article (avoids redirects when following those links). 2. Clarifies that it is the ZeroTier Knowledge Base article which implements a half-router, and summarises the additional capabilities of `zerotier-router`. 3. Adds cross-reference to IOTstack documentation (IMO this is more comprehensive than anything in the ZeroTier Knowledge Base). 4. Removes extraneous `0x09` characters. Fixes #35 Signed-off-by: Phill Kelley <34226495+Paraphraser@users.noreply.github.com>
1 parent f1bae68 commit 8551038

1 file changed

Lines changed: 59 additions & 27 deletions

File tree

README-router.md

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,32 @@
44

55
This is a variation built on top of the zyclonite/zerotier container which implements a local network router. It is based upon the ZeroTier Knowledge Base article:
66

7-
* [Route between ZeroTier and Physical Networks](https://zerotier.atlassian.net/wiki/spaces/SD/pages/224395274/Route+between+ZeroTier+and+Physical+Networks)
7+
* [Route between ZeroTier and Physical Networks](https://docs.zerotier.com/route-between-phys-and-virt/)
88

9-
Technically, this could be described as a *half-router*:
9+
Technically, the above approach could be described as a *half-router*:
1010

1111
* You can initiate connections *from* a remote client *to* devices on the LAN; but
1212
* You can't initiate connections *to* the remote client *from* devices on the LAN.
1313

14+
This implementation extends the concept so that you have a choice of:
15+
16+
* Permitting remote clients to initiate connections with a devices on your LAN; or
17+
* Permitting clients on your LAN to initiate connections with remote devices reachable across your ZeroTier Cloud network; or
18+
* Both of the above (ie a full router).
19+
1420
### Command line example
1521

1622
``` console
1723
$ docker run --name zerotier-one --device=/dev/net/tun \
24+
--network=host -d \
1825
--cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add=SYS_ADMIN \
19-
--env TZ=Etc/UTC --env PUID=999 --env PGID=994 \
26+
--env TZ=Etc/UTC --env PUID=$(id -u) --env PGID=$(id -g) \
2027
--env ZEROTIER_ONE_LOCAL_PHYS=eth0 \
21-
--env ZEROTIER_ONE_USE_IPTABLES_NFT=false \
28+
--env ZEROTIER_ONE_USE_IPTABLES_NFT=true \
2229
--env ZEROTIER_ONE_GATEWAY_MODE=inbound \
2330
--env ZEROTIER_ONE_NETWORK_IDS=«yourDefaultNetworkID(s)» \
24-
-v /var/lib/zerotier-one:/var/lib/zerotier-one zyclonite/zerotier:router
31+
-v /var/lib/zerotier-one:/var/lib/zerotier-one \
32+
zyclonite/zerotier:router
2533
```
2634

2735
Note:
@@ -35,7 +43,8 @@ Note:
3543
### Compose file example
3644

3745
``` yaml
38-
version: '3'
46+
---
47+
3948
services:
4049
zerotier:
4150
image: "zyclonite/zerotier:router"
@@ -55,7 +64,7 @@ services:
5564
- PUID=999
5665
- PGID=994
5766
- ZEROTIER_ONE_LOCAL_PHYS=eth0
58-
- ZEROTIER_ONE_USE_IPTABLES_NFT=false
67+
- ZEROTIER_ONE_USE_IPTABLES_NFT=true
5968
- ZEROTIER_ONE_GATEWAY_MODE=inbound
6069
# - ZEROTIER_ONE_NETWORK_IDS=«yourDefaultNetworkID(s)»
6170
```
@@ -87,9 +96,9 @@ Note:
8796
- PUID=1000
8897
- PGID=1000
8998
```
90-
99+
91100
If omitted, `PUID` defaults to user ID 999, while `PGID` defaults to group ID 994.
92-
101+
93102
These variables are only used to ensure consistent ownership of persistent storage on each launch. They do not affect how the container *runs.* Absent a `user:` directive, the container runs as root and does not downgrade its privileges.
94103

95104
* `ZEROTIER_ONE_LOCAL_PHYS` - a space-separated list of physical interfaces that should be configured to participate in NAT-based routing. Examples:
@@ -107,31 +116,45 @@ Note:
107116
environment:
108117
- ZEROTIER_ONE_LOCAL_PHYS=wlan0
109118
```
110-
119+
111120
- If your computer has both Ethernet and WiFi interfaces active and you wish to be able to route through each interface:
112-
121+
113122
``` yaml
114123
environment:
115124
- ZEROTIER_ONE_LOCAL_PHYS=eth0 wlan0
116125
```
117-
126+
118127
This scheme could be appropriate where the physical interfaces were:
119-
128+
120129
1. In the same broadcast domain (subnet). Disconnecting Ethernet would fail-over to WiFi.
121130
2. In different broadcast domains, such as if you allocated different subnets for Ethernet and WiFi.
122131

123-
* `ZEROTIER_ONE_USE_IPTABLES_NFT` - controls the command the container uses to set up NAT forwarding. Example:
132+
* `ZEROTIER_ONE_USE_IPTABLES_NFT` - controls the command the container uses to set up net-filter rules to implement packet forwarding. Example:
124133

125-
``` yaml
126-
environment:
127-
- ZEROTIER_ONE_USE_IPTABLES_NFT=true
128134
```
129-
130-
- `false` means the container uses `iptables`. This is the default.
131-
- `true` means the container uses `iptables-nft`.
135+
environment:
136+
- ZEROTIER_ONE_USE_IPTABLES_NFT=true
137+
```
138+
139+
* `false` means the container uses `iptables-legacy`. This is the default if the variable is omitted but that is only to maintain backwards compatibility.
140+
* `true` means the container uses `iptables-nft`. This is *generally* what you need.
141+
142+
The way to be absolutely certain is to start the container and then run the following command:
143+
144+
``` console
145+
$ sudo nft list ruleset | grep -c "zt*"
146+
```
147+
148+
Ignore any lines that start with the `#` character.
149+
150+
There are three possible responses:
151+
152+
1. An error saying that the `nft` command has not been found. Docker uses `iptables-nft` to construct its own net-filter rules so it installs the `iptables` package as a dependency which, in turn, installs `nftables` as its own dependency. For that reason, not being able to find the `nft` command generally indicates an improper installation of Docker.
153+
2. A line-count of zero. This means the container has not been able to configure net-filter rules on the host. If that happens, try the opposite setting for this environment variable (eg `true` instead of `false`).
154+
3. A non-zero line-count. That means the container has been able to propagate net-filter rules into the host's tables, which is what you want. The actual number is not important, just something other than zero.
155+
156+
The container will always come up. Once you've authorised the client in ZeroTier Central, it will be able to join your ZeroTier Cloud network. Tests like `ping` and `traceroute` that you run on the same host will always work. However, if the container is not able to propagate its net-filter rules into the host's tables, traffic *beyond* the host where the container is running will not work properly. The problem is quite subtle so it's always a good idea to check that the host has the expected net-filters.
132157

133-
Try `true` if NAT does not seem to be working. This is needed on Raspberry Pi Bullseye.
134-
135158
* `ZEROTIER_ONE_GATEWAY_MODE` - controls the traffic direction. Examples:
136159

137160
- Only permit traffic *from* the ZeroTier cloud *to* the local physical interfaces:
@@ -140,7 +163,7 @@ Note:
140163
environment:
141164
- ZEROTIER_ONE_GATEWAY_MODE=inbound
142165
```
143-
166+
144167
- Only permit traffic *from* the local physical interfaces *to* the ZeroTier cloud:
145168

146169
``` yaml
@@ -156,18 +179,18 @@ Note:
156179
```
157180

158181
Defaults to `inbound` if omitted. Note that you will probably need one or more static routes configured in your local LAN router so that traffic originating in a local host which is not running the ZeroTier client can be directed to the gateway host.
159-
182+
160183
* `ZEROTIER_ONE_NETWORK_IDS` – a space-separated list of ZeroTier network IDs.
161184

162185
This variable is *only* effective on first launch. There is no default if it is omitted. Examples:
163-
186+
164187
- to join a single network:
165188

166189
``` yaml
167190
environment:
168191
- ZEROTIER_ONE_NETWORK_IDS=aaaaaaaaaaaaaaaa
169192
```
170-
193+
171194
Equivalent of running the following command after the container first starts:
172195

173196
```
@@ -194,6 +217,15 @@ Note:
194217

195218
For each ZeroTier container that is configured as a router, ZeroTier needs at least one *Managed Route*.
196219

197-
The [ZeroTier Wiki](https://zerotier.atlassian.net/wiki/spaces/SD/pages/224395274/Route+between+ZeroTier+and+Physical+Networks#Configure-the-ZeroTier-managed-route) explains how to design managed routes.
220+
The [ZeroTier Wiki](https://docs.zerotier.com/route-between-phys-and-virt/#configure-the-zerotier-managed-route) explains how to design managed routes.
198221

199222
You configure Managed Routes in ZeroTier Central.
223+
224+
### Detailed examples
225+
226+
See:
227+
228+
* [SensorsIot/IOTstack - ZeroTier](https://sensorsiot.github.io/IOTstack/Containers/ZeroTier/)
229+
230+
You do not have to use IOTstack just to get ZeroTier running. However, the IOTstack documentation explores several network models and is a useful guide to the concepts involved and decisions you will need to make.
231+

0 commit comments

Comments
 (0)