Skip to content

Route a subnet through a Linux node

A subnet router is a Guard node that forwards traffic to a network behind it. Use one to reach machines that can’t run the Guard client, such as printers, storage, switches, or a whole office or cloud network. The nodes you grant reach those machines at their own addresses, through the router.

You don’t configure routing on the Linux machine. In Guard, you say which subnet the node serves, and the client turns on forwarding by itself.

  • A Guard network on a tenant, as in Install Authwise Workplace. The versions on that page apply.
  • A Linux machine on the subnet you want to reach, with root access and the iptables command installed. The nftables-backed iptables is fine. Only a Linux node can route. A node on macOS, Windows, or iOS reaches what it’s granted and never routes for others.
  • A tenantAdmin or networkAdmin role on the Guard network, and a second factor on your account. Registering a server asks for it.
  • A subnet outside 100.64.0.0/10. That range holds the mesh’s own addresses. Guard routes IPv4 only.

Three things in Guard make a subnet router:

ObjectWhat it says
A resource of kind subnetThe range to reach, such as 10.20.0.0/16.
Served byThe node, or nodes, that route the resource. Serving a subnet is what makes a node a router.
A grantWhich nodes may reach the resource. Nothing reaches the subnet until a grant says so.

A granted node gets a route for the subnet through the router. Every other node gets nothing: no route, and no tunnel to the router on the subnet’s account.

The router rewrites the source of what it forwards to its own LAN address. The machines on the subnet see connections from the router, so they need no route back to the mesh and no change of their own. For the same reason, they can’t tell which Guard node a connection came from.

A grant has a direction. It lets the granted node open connections to the subnet, and lets the machines on the subnet answer. It doesn’t let them open connections to the granted node, even when their route to 100.64.0.0/10 goes through the router. The granted node checks this on every packet that it receives. See How Guard enforces grants, which also says what holds for a node on a Guard client earlier than 0.26.0.

A grant to the subnet doesn’t reach the router itself. To reach the router’s own mesh address, for example over SSH, grant the router node as well.

To join two networks so that the machines on each reach the machines on the other, see Connect two sites.

Register the machine as a server and name the subnet in one step.

  1. In the console, open the network, and select Nodes, Add node, then Register a server.
  2. Enter a Name, such as office-router.
  3. Under Serves, add a resource: Kind subnet, and the range as the Address, such as 10.20.0.0/16. The address is the network address, with no host bits set: 10.20.0.0/16, not 10.20.0.1/16.
  4. Create the node. The console shows a one-time code that starts with ga_. Copy it. No page shows it again.

With awctl:

Terminal window
awctl guard context set --tenant TENANT --network NETWORK
awctl guard nodes create --display-name office-router --out router.code
awctl guard resources create --display-name "Office LAN" \
--kind subnet --address 10.20.0.0/16 --serving-node-ids NODE_ID

nodes create writes the code to router.code and prints the node’s name, which ends in its ID (nd-…). Use that ID as NODE_ID.

To route a single machine and not a range, use kind host and its address, such as 10.20.0.5.

On the Linux machine:

  1. Install the Guard client, as in Add nodes.

  2. Join with the code, as root. ADDRESS is your tenant’s Guard address, such as acme.guard.example.com.

    Terminal window
    sudo awguard up ADDRESS --auth-code "$(cat router.code)"
  3. Start the service.

    Terminal window
    sudo systemctl enable --now awguard-peer

Let each node that should reach the subnet do so.

In the console, open the node, and under Can reach select the resource. A person’s laptop is a node like any other.

With awctl:

Terminal window
awctl guard nodes add-grants CLIENT_NODE_ID resources/RESOURCE_ID
awctl guard nodes list-grants CLIENT_NODE_ID

To grant many nodes at once, put them in a node group and grant the group:

Terminal window
awctl guard node-groups add-grants GROUP resources/RESOURCE_ID

Each node picks the change up at its next configuration poll, within a minute.

On the router:

Terminal window
awguard status
sudo journalctl -u awguard-peer | grep -E "ip_forward|subnet-router"

The status has a routes line with the subnet, and the log has net.ipv4.ip_forward = 1 and subnet-router NAT programmed.

On a router that runs Guard client 0.26.0 or later, the status also has an mss line. See Keep large packets from stalling connections.

On a granted node, awguard status lists the router as a peer. Then reach a machine on the subnet by its own address:

Terminal window
ping 10.20.0.5

When the node serves its first subnet, the service restarts once by itself and then:

  • sets net.ipv4.ip_forward to 1;
  • adds a MASQUERADE rule to the nat table’s POSTROUTING chain, for traffic from the mesh that leaves by any interface but the tunnel;
  • adds two ACCEPT rules to the FORWARD chain, for traffic in and out of the tunnel.

When the service stops, it removes the three rules. It leaves net.ipv4.ip_forward on, because Docker, Kubernetes, or another VPN on the same machine may depend on it.

You don’t need to set a sysctl, write a firewall rule, or edit /etc/awguard/peer.toml. A file that sets routes or forwarding is refused.

Keep large packets from stalling connections

Section titled “Keep large packets from stalling connections”

The tunnel carries packets of up to 1280 bytes. When a machine on the subnet sends a larger packet, the router answers with an ICMP “fragmentation needed” message, and the machine sends smaller packets from then on. Allow ICMP from the router to the machines on the subnet.

In some networks that message can’t reach the machine that sent the packet, whatever a firewall allows:

  • The machine is behind a passthrough load balancer that returns replies directly. The reply carries the load balancer’s address as its source, so the router’s message goes to the load balancer, which forwards only the ports it was created for.
  • The machine is behind an anycast address.
  • A firewall between the router and the machine drops ICMP, and you can’t change it.

The sign is a pause of several seconds on each new connection that carries a large reply, such as a TLS handshake, after which the connection works. The sender keeps retransmitting until it lowers its packet size by itself, which takes about six seconds with Linux defaults.

To prevent the pause, the TCP maximum segment size (MSS) of connections that cross the tunnel has to be lowered to fit it.

A router that runs Guard client 0.26.0 or later does this by itself. It lowers the MSS on the connection-opening packets that it forwards, in both directions, to 1240 for IPv4, which is the tunnel’s 1280 bytes less the IPv4 and TCP headers. You don’t add a rule, and no setting turns it off. It never raises a value, and it doesn’t change the router’s own connections. To confirm it, run awguard status on the router and look for this line:

mss 1240 (IPv6 1220): forwarded TCP connections fitted to the tunnel

The values follow the tunnel’s packet size. 1240 and 1220 are the values at the default of 1280 bytes, and the line shows the values in use.

On a router that runs an earlier client, add both of these rules:

Terminal window
sudo iptables -t mangle -A FORWARD -i awguard0 -p tcp --tcp-flags SYN,RST SYN \
-m tcpmss --mss 1241:65535 -j TCPMSS --set-mss 1240
sudo iptables -t mangle -A FORWARD -o awguard0 -p tcp --tcp-flags SYN,RST SYN \
-m tcpmss --mss 1241:65535 -j TCPMSS --set-mss 1240

Use both rules. The --clamp-mss-to-pmtu option lowers the size only on connections that leave by the tunnel and misses the ones that arrive from it.

An earlier client doesn’t add these rules and doesn’t keep them. Add them again each time the router starts, for example from a unit that runs after the awguard service.

After every node that forwards runs client 0.26.0 or later, you can remove the rules. Leaving them in place is harmless: the rules and the client only ever lower the value, so the lower of the two applies.

Both ways cover TCP only. An application that uses UDP must keep its own packets within 1280 bytes.

A router often sits behind a firewall or a cloud NAT gateway that gives each destination its own port. Traffic then goes through a Guard relay. It works, and it’s slower than a direct path. awguard status shows the path to each peer as direct or relay-udp.

To get a direct path, give the router a UDP port that’s reachable on purpose, and tell the client about it in /etc/awguard/peer.toml:

udp_port = 51820
endpoint = "203.0.113.7:51820"
Where the router isWhat to do
Behind a site firewallForward one UDP port on the firewall to the router’s udp_port. The endpoint is the firewall’s public address and that port.
A cloud instance with a public addressOpen udp_port in its firewall or security group. The endpoint is the public address and the port.
A cloud instance with no public addressPut a passthrough network load balancer in front of it, with a UDP forwarding rule on udp_port. The endpoint is the load balancer’s address and the port.

endpoint also takes a DNS name, or a list. Restart the service after you change the file:

Terminal window
sudo systemctl restart awguard-peer

For high availability, let two nodes on the same subnet serve the same resource. In the console, open the resource and select both under Serving nodes. With awctl:

Terminal window
awctl guard resources add-nodes RESOURCE_ID SECOND_NODE_ID

A granted node sends the subnet’s traffic to one router and keeps using it while it answers. When that router stops answering, the node moves to the other in about a minute. Connections that were open through the first router are cut, and new ones go through the second. This needs Guard client 0.23.0 or later on the granted nodes.

Two nodes may serve the same range. Two nodes may not serve ranges that overlap and differ, such as 10.20.0.0/16 on one and 10.20.5.0/24 on the other. Guard refuses the second.

A Linux node that has already joined becomes a router when a resource names it. In the console, select Resources, New resource, enter the subnet, and select the node under Served by. Or open the node and select the resource under Serves.

To stop routing, remove the node from the resource, or delete the resource. Its grants go with it.

SymptomCause and fix
The service won’t start and logs this node is served as a router, but net.ipv4.ip_forward is "0" and could not be setThe client can’t write the sysctl. Run the service as root. In a container, set the sysctl before the client starts.
The service won’t start and logs iptables … failedThe iptables command is missing or can’t change the tables. Install it.
A granted node lists the router as a peer in awguard status and can’t reach the subnetA rule earlier in the router’s FORWARD chain drops the traffic. The client appends its rules, so a DROP or REJECT rule ahead of them, from a host firewall, wins. Allow forwarding in and out of the tunnel interface in that firewall.
The same, and the router’s own firewall is openThe machine on the subnet, or a firewall or security group in front of it, refuses the router. Connections arrive from the router’s LAN address, so allow that address.
A node has no route to the subnetThe node isn’t granted the resource, or the resource has no serving node. awctl guard nodes list-grants and awctl guard resources list-nodes show both.
The resource is refused as inside the mesh rangeThe address is in 100.64.0.0/10. To reach a Guard node itself, grant the node, not a resource.
The resource is refused for host bitsThe address isn’t the range’s network address. Use the address the message suggests.
A granted node can’t reach the router’s own mesh addressA grant to the subnet doesn’t include the router. Grant the router node as well. See How Guard enforces grants.
A resource reaches no one, and the console shows the router as Not servingThe router’s client is too old to enforce grants. Upgrade it. See How Guard enforces grants.
Each new connection pauses for several seconds and then works, or small requests work and large transfers stallA machine on the subnet doesn’t learn that its packets are too large for the tunnel, and the router runs a client earlier than 0.26.0. See Keep large packets from stalling connections.
Traffic works and is slowThe path to the router is relay-udp. See Make the router reachable directly.