Routing through a non-adjacent host in a virtual network
1
vote
1
answer
28
views
I have a WireGuard virtual network. Three hosts on the network: A, B and R.
Only the host R has a static public IP, so both hosts A and B connect to the host R to connect to the virtual network.
Hosts A and R are directly connected, but hosts A and B are not — the packets have to be routed through the host R.
### Problem
I want to route packets from host A through the host B, without configuring the routing table of the host R.
Example:
To send a packet from host A to public host with IP
1.1.1.1
:
Host A -> Host R -> Host B -> (through B's public interface) -> 1.1.1.1
One possible solution is to create another WireGuard network between the hosts A and B, inside the original virtual network, and then route the same way I would route from host A through R, but that looks redundant. Are there other solutions? Thank you.
### What I have tried
Assume VPN subnet: 10.78.1.0/24
Host R: 10.78.1.1
Host A: 10.78.1.2
Host B: 10.78.1.3
VPN interface on host A: wg
I tried adding a route on host A (also addings AllowedIPs in wireguard config):
ip route add 1.1.1.1 via 10.78.1.3 dev wg
But the packets never reach host B: the packets are routed according to the routing table of host R, and that is to route immediately through the host R's public interface.
I presume that is because host R does not receive any information about the preferred next route. Is there any way to give host R such information?
Asked by g00dds
(173 rep)
Jun 3, 2025, 02:39 PM
Last activity: Jun 3, 2025, 09:45 PM
Last activity: Jun 3, 2025, 09:45 PM