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.
Before you begin
Section titled “Before you begin”- 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
iptablescommand installed. The nftables-backediptablesis 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
tenantAdminornetworkAdminrole 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.
How it works
Section titled “How it works”Three things in Guard make a subnet router:
| Object | What it says |
|---|---|
A resource of kind subnet | The range to reach, such as 10.20.0.0/16. |
| Served by | The node, or nodes, that route the resource. Serving a subnet is what makes a node a router. |
| A grant | Which 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 router
Section titled “Register the router”Register the machine as a server and name the subnet in one step.
- In the console, open the network, and select Nodes, Add node, then Register a server.
- Enter a Name, such as
office-router. - Under Serves, add a resource: Kind
subnet, and the range as the Address, such as10.20.0.0/16. The address is the network address, with no host bits set:10.20.0.0/16, not10.20.0.1/16. - Create the node. The console shows a one-time code that starts with
ga_. Copy it. No page shows it again.
With awctl:
awctl guard context set --tenant TENANT --network NETWORKawctl guard nodes create --display-name office-router --out router.codeawctl guard resources create --display-name "Office LAN" \ --kind subnet --address 10.20.0.0/16 --serving-node-ids NODE_IDnodes 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.
Install the client and join
Section titled “Install the client and join”On the Linux machine:
-
Install the Guard client, as in Add nodes.
-
Join with the code, as root.
ADDRESSis your tenant’s Guard address, such asacme.guard.example.com.Terminal window sudo awguard up ADDRESS --auth-code "$(cat router.code)" -
Start the service.
Terminal window sudo systemctl enable --now awguard-peer
Grant the subnet
Section titled “Grant the subnet”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:
awctl guard nodes add-grants CLIENT_NODE_ID resources/RESOURCE_IDawctl guard nodes list-grants CLIENT_NODE_IDTo grant many nodes at once, put them in a node group and grant the group:
awctl guard node-groups add-grants GROUP resources/RESOURCE_IDEach node picks the change up at its next configuration poll, within a minute.
Check that it works
Section titled “Check that it works”On the router:
awguard statussudo 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:
ping 10.20.0.5What the client changes on the router
Section titled “What the client changes on the router”When the node serves its first subnet, the service restarts once by itself and then:
- sets
net.ipv4.ip_forwardto1; - adds a
MASQUERADErule to thenattable’sPOSTROUTINGchain, for traffic from the mesh that leaves by any interface but the tunnel; - adds two
ACCEPTrules to theFORWARDchain, 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 tunnelThe 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:
sudo iptables -t mangle -A FORWARD -i awguard0 -p tcp --tcp-flags SYN,RST SYN \ -m tcpmss --mss 1241:65535 -j TCPMSS --set-mss 1240sudo iptables -t mangle -A FORWARD -o awguard0 -p tcp --tcp-flags SYN,RST SYN \ -m tcpmss --mss 1241:65535 -j TCPMSS --set-mss 1240Use 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.
Make the router reachable directly
Section titled “Make the router reachable directly”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 = 51820endpoint = "203.0.113.7:51820"| Where the router is | What to do |
|---|---|
| Behind a site firewall | Forward 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 address | Open udp_port in its firewall or security group. The endpoint is the public address and the port. |
| A cloud instance with no public address | Put 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:
sudo systemctl restart awguard-peerRun two routers for one subnet
Section titled “Run two routers for one subnet”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:
awctl guard resources add-nodes RESOURCE_ID SECOND_NODE_IDA 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.
Make an existing node a router
Section titled “Make an existing node a router”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.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause 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 set | The 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 … failed | The 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 subnet | A 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 open | The 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 subnet | The 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 range | The 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 bits | The 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 address | A 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 serving | The 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 stall | A 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 slow | The path to the router is relay-udp. See Make the router reachable directly. |