ezvpnguides

Reach the whole site LAN

Turn the host that runs the ezvpn server into a gateway, so remote clients reach every device on its network at the address it already has: 192.168.1.20 on the LAN is still 192.168.1.20 from the client. The devices behind it install nothing. None of this is needed when clients only reach the server host itself at its VPN address — that traffic is never forwarded.

How it works

A client routes the site's prefix into the tunnel. The server host takes the packet off its TUN device and forwards it onto the LAN like any router would. The device's reply is addressed to the client's VPN address, and the one thing to arrange is that this reply finds its way back to the server host.

A client at 10.0.0.2 reaches the LAN device 192.168.1.20 through the ezvpn server, which forwards the packet onto the LAN. The reply gets back to the server in one of two ways: with NAT, the server rewrote the source to its own LAN address 192.168.1.10, so the device replies to the server directly; with a route, the device replies to 10.0.0.2 through the LAN router, which has a route for 10.0.0.0/24 via 192.168.1.10.A · NAT on the serverclient10.0.0.2ezvpn server10.0.0.1 · 192.168.1.10LAN device192.168.1.20QUIC tunnelsource rewritten to 192.168.1.10the reply comes straight backB · a route on the LAN router, no NATclient10.0.0.2ezvpn server10.0.0.1 · 192.168.1.10LAN device192.168.1.20QUIC tunnelLAN router10.0.0.0/24 → 192.168.1.10the device sees 10.0.0.2 and repliesthrough its router, which sends it onto the server
The client routes 192.168.1.0/24 into the tunnel and the server forwards it onto its LAN. A reply addressed to the client's VPN address has to reach the server again: by NAT (A) or by a route (B).

ezvpn configures none of this. Forwarding, firewall, NAT, and routing stay with the OS, set once with its normal tools. The server host does not have to be the site's router: any always-on host on the LAN works. The examples are for a Linux server host, with these values:

ValueMeaning
eth0The server host's interface on the site's LAN.
10.0.0.0/24The server config's network, the IPv4 VPN prefix.
fd00::/64The server config's network6, the IPv6 VPN prefix.
192.168.1.0/24The site's LAN, which clients route with --route.

A Windows server host can be reached itself, at its VPN address, once its firewall allows the VPN prefix (see Windows Firewall); making it a gateway to the rest of its network is not documented yet.

1. Enable IP forwarding

sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv6.conf.all.forwarding=1

Make them persist across reboots with a file in /etc/sysctl.d/:

/etc/sysctl.d/99-ezvpn-gateway.conf
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1

If the host takes its IPv6 default route from router advertisements in the kernel (ifupdown, for example), keep it with sudo sysctl -w net.ipv6.conf.eth0.accept_ra=2; forwarding otherwise turns them off.

2. Let forwarded traffic through

Turning forwarding on does not open the firewall. A host that filters routed traffic — UFW, firewalld, or a default-drop FORWARD policy — also needs a rule that lets the VPN prefix through to the LAN, and the replies back. NAT rules do not do this; netfilter filters forwarded packets separately.

sudo iptables -A FORWARD -s 10.0.0.0/24 -o eth0 -j ACCEPT
sudo iptables -A FORWARD -d 10.0.0.0/24 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

The same applies to IPv6, with ip6tables and the network6 prefix. A host whose firewall forwards everything already can skip this step.

3. Give the VPN prefix a return path

Either hide the client's VPN address behind the server host (NAT), or tell the site where the VPN prefix lives (routing). The two can be mixed per address family: NAT for IPv4 and routing for IPv6 is a common combination.

NAT

The usual choice for IPv4. Devices on the LAN see each connection as coming from the server host, so their replies go straight back to it:

sudo iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADE

The same works for IPv6, with ip6tables and the network6 prefix.

Routing, without NAT

Devices on the LAN see each client's real VPN address, so the site needs a route for the VPN prefix that points at the server host:

  • If the server host is already the site's default router, nothing more is needed: replies come to it anyway.
  • Otherwise add a static route for the VPN prefix on the site's router, with the server host as the next hop — 10.0.0.0/24 via 192.168.1.10 in the diagram.
  • For IPv6, the server host can announce the route itself in a router advertisement, so nothing on the router changes. With radvd:
/etc/radvd.conf on the ezvpn server host
interface eth0 {
    AdvSendAdvert on;
    AdvDefaultLifetime 0;    # a route only: never the LAN's default router
    route fd00::/64 { };     # the server config's network6 prefix
};

AdvDefaultLifetime 0 matters: without it the server host also advertises itself as a default router for the whole LAN.

Not every device picks up an advertised route; for those, add the static route on the router or use NAT.

4. Route the site from the client

On each client, route the site's prefixes into the tunnel with --route and --route6 (or routes and routes6 in its config):

sudo ezvpn client start \
  --server-node-id SERVER_ENDPOINT_ID \
  --auth-key-file ./client.key \
  --route 192.168.1.0/24 \
  --route6 <SITE_IPV6_PREFIX>

A device at 192.168.1.20 on the LAN is then 192.168.1.20 from the client. In the apps, add the same prefixes to the profile's routes. More on routes in Connect with the CLI.

To resolve the site's internal names from a client, set up conditional forwarding to the site's resolver: see Split DNS.

Leave the rules in place

Everything above can be permanent: sysctl.d, a persistent iptables or nftables config, or your distro's firewall service. They key on the VPN prefix, so they are inert while the tunnel is down and need no up and down hooks.

Two kinds of rule you do not need:

  • Keeping clients apart. The server drops packets between clients itself, before they reach the TUN device, even if a client widens its routes to cover the whole VPN prefix. See "Client Isolation" in Architecture.
  • Letting ezvpn in. There is no inbound port to open or allow: the connection comes up by NAT traversal or through a relay.

When the client's LAN is numbered the same

A client refuses a route that overlaps the network it is sitting on, because routing its own LAN into the tunnel would cut it off from its local hosts. So a site LAN in a commonly used range — 192.168.1.0/24, say — cannot be reached from another LAN numbered the same way. Details in Routes that overlap your network.