Skip to content

TUN Mode (Full-Tunnel VPN)

TUN mode provides a full-tunnel VPN experience where all client traffic is routed through the server. This differs from SOCKS5 relay mode, which requires per-application SOCKS5 configuration.


FeatureTUN ModeSOCKS5 Mode
Traffic routingFull tunnel, all appsPer-app, requires SOCKS5 config
Setup complexityServer-side NAT configClient-side app configuration
PerformanceKernel-level packet handlingApplication-level relay
Use caseComplete privacy, all trafficApp-specific tunneling

In TUN mode, the client creates a virtual TUN interface and routes all traffic through it. The server receives these packets and NATs them to the internet, similar to a traditional VPN.


TUN startup is fail-closed. The server derives the network CIDR from tun_ip, blocks private, loopback, CGNAT, NAT64, documentation, and other special-use destinations, and drops all TUN-originated traffic to the server host. The same destination policy applies to raw TUN packets, TCP, UDP, and DNS. DNS responses with mixed answers retain only public addresses; answers with no public addresses return NODATA.

nat_enabled = false disables NAT only; it does not disable containment. Setup failures stop TUN startup before clients are accepted.

From v1.3.9 each client can only send from its own assigned tunnel address, so one client can’t pose as another. Two opt-in settings in [server.network] relax containment for raw TUN traffic, both off by default:

  • allow_client_to_client = true lets clients on this server reach each other’s tunnel addresses. It covers this server’s own TUN pool only.
  • allowed_internal_ranges = [...] lists extra internal ranges clients may reach, such as a home LAN.

The server’s own addresses stay unreachable either way, and traffic from the internet still can’t reach a client: rVPN has no port forwarding. See Server Config for the full rules.

Enable IP forwarding and install both iptables and ip6tables:

Terminal window
sudo sysctl -w net.ipv4.ip_forward=1
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf

At startup the server reconciles only its RVPN_INPUT, RVPN_FORWARD, and RVPN_NAT chains, inserts TUN-specific jumps ahead of broad existing accepts, and adds MASQUERADE for the normalized TUN subnet when NAT is enabled. It does not flush global rules or change chain policies. Do not add a parallel nftables ruleset; on nft-backed distributions use the distribution’s iptables/ip6tables frontend.

macOS does not support server-side TUN mode natively. For macOS servers, use SOCKS5 mode or run rvpn-server inside a FreeBSD/Linux VM with proper NAT configuration.

Enable forwarding and PF. The active main ruleset must contain both attachment points, placed before broad pass quick rules that could otherwise bypass the anchor:

nat-anchor "rvpn"
anchor "rvpn"

Have the operator validate and load the main ruleset after adding those lines. The installer and server never enable PF, alter /etc/pf.conf, reload the main ruleset, flush PF state, or use ipfw/natd. At TUN startup the server writes /usr/local/etc/rvpn/rvpn.anchor.conf, then runs only the scoped operations:

Terminal window
pfctl -a rvpn -nf /usr/local/etc/rvpn/rvpn.anchor.conf
pfctl -a rvpn -f /usr/local/etc/rvpn/rvpn.anchor.conf

The anchor quick-blocks special-use destinations and the host’s own interface addresses ((self)), statefully passes permitted public flows from the TUN subnet, blocks remaining TUN input, and optionally NATs only that subnet through the detected external interface using ($ext_if). TUN startup fails if PF or forwarding is disabled, either attachment is missing, or validation/loading fails.

If a broad pass quick rule appears earlier in the main ruleset than anchor "rvpn", packets it matches never reach the anchor: the startup log warns about this, and for those packets only the userspace destination check (is_blocked_egress in permitted_tun_destination, which also covers the server’s own addresses) still applies. Move the anchor before such rules to restore full kernel-side containment.


[server]
bind_address = "0.0.0.0:443"
tls_cert_file = "/etc/letsencrypt/live/your-domain.com/fullchain.pem"
tls_key_file = "/etc/letsencrypt/live/your-domain.com/privkey.pem"
identity_key_file = "/etc/rvpn/server_identity.key"
websocket_path = "/api/v1/ws"
[server.network]
nat_enabled = true
[server.tun]
enabled = true
tun_ip = "10.200.0.1/24"
mtu = 1420
dns_servers = ["1.1.1.1", "8.8.8.8"]

Key settings for TUN mode:

  • websocket_path — Must be /api/v1/ws for TUN mode clients to reach the TUN endpoint at /api/v1/ws/tun
  • [server.network].nat_enabled — Controls server-managed NAT only; containment remains enabled when this is false.
  • [server.tun].tun_ip — The gateway address and prefix. Client allocation, routing, filtering, and NAT all use its normalized network CIDR. Change this if 10.200.0.0/24 clashes with your LAN.
  • [server.tun].dns_servers — DNS resolvers pushed to clients over the tunnel

Terminal window
sudo rvpn-server -c /etc/rvpn/server.toml

The service runs the same binary regardless of mode. Ensure server.toml has TUN-mode settings as shown above.

Terminal window
sudo systemctl restart rvpn-server

Check server logs:

Terminal window
sudo journalctl -u rvpn-server -f

Look for entries showing the WebSocket path and TUN handler:

INFO Starting rVPN Server on 0.0.0.0:443
INFO Server listening on wss://0.0.0.0:443
INFO WebSocket endpoint (mobile TUN): /api/v1/ws/tun
INFO TUN server started on 10.200.0.1/24

Verify the owned rules are active (Linux):

Terminal window
sudo iptables -L RVPN_INPUT -v
sudo iptables -L RVPN_FORWARD -v
sudo iptables -t nat -L RVPN_NAT -v

Test connectivity and containment:

Connect a client in TUN mode and verify:

  1. Client receives an IP from the normalized tun_ip subnet (e.g., 10.200.0.x).
  2. Public IP TCP, UDP, DNS, and ICMP traffic works.
  3. Server-host, private LAN, loopback, CGNAT, NAT64, and malformed-packet attempts are dropped without disconnecting the session.
  4. DNS names with mixed private/public answers return only public addresses; all-private answers return NODATA.

Check active connections on server:

Terminal window
sudo ss -tlnp | grep 443
sudo ip addr show tun0 # if interface exists

  • Verify port 443 is open in firewall
  • Check websocket_path is /api/v1/ws (clients append /tun automatically)
  • Review server logs for TLS or WebSocket upgrade errors
  • Verify IP forwarding is enabled: sysctl net.ipv4.ip_forward
  • Check the owned NAT chain: iptables -t nat -L RVPN_NAT
  • Ensure the server’s security group/firewall allows outbound traffic on all ports
  • Confirm nat_enabled = true in server.toml
  • Verify the normalized tun_ip subnet does not conflict with existing networks
  • Check that dns_servers are reachable from the server

The server creates a real TUN interface (e.g., tun0 with IP 10.200.0.1) when TUN mode is enabled. This provides true TUN-to-TUN tunneling:

ComponentDescription
Server TUNtun0 with IP 10.200.0.1/24
Client TUNVirtual interface with IP from 10.200.0.x
RoutingKernel routes packets through TUN interface

The server’s TUN interface handles:

  • Writing packets received from clients to the kernel
  • Reading response packets from the kernel
  • Forwarding responses back to the appropriate client

When running behind a reverse proxy (Caddy, nginx, HAProxy), ensure the proxy forwards /api/v1/ws/tun to the server. The proxy configuration for TUN mode is identical to SOCKS5 mode — both use the same WebSocket base path.

See Reverse Proxy Setup for complete proxy configurations.


ItemValue
WebSocket path/api/v1/ws
TUN endpoint/api/v1/ws/tun
Default port443
DHCP range default10.200.0.0/24
NAT requiredYes