I'm having some difficulties setting up a routing between 3 nodes. Here's the situation:
- A, B and R are wireguard (wg0) peers
- R is a public hub (vpn.example.com) with IP 172.0.0.1
- A is a peer connected to R with IP 172.0.0.10
- B is a peer connected to R with IP 172.0.0.20
- B is also connected to a LAN with IP 192.168.1.20
- C is a host in the same LAN with IP 192.168.1.30
- Firewall on R that accepts traffic on wg0 and public network towards wireguard (51820/udp).
I would like to route traffic so that A and C can communicate and 192.168.1.30 was reachable from A.
Naively I thought to set up a routing in this way:
B# sysctl net.ipv4.ip_forward=1
A# ip route add 192.168.1.30/32 via 172.0.0.20 dev wg0
C# ip route add 172.0.0.10/32 via 192.168.1.20 dev eth0
this does not work though: if I tcpdump
traffic on A, I can see packages going from A to C:
A# tcpdump -n -l -i wg0 | grep 192
17:27:47.492184 IP 172.0.0.10 > 192.168.1.30: ICMP echo request, id 10, seq 1, length 64
17:52:36.908342 IP 172.0.0.10 > 192.168.1.30: ICMP echo request, id 10, seq 2, length 64
17:52:37.921042 IP 172.0.0.10 > 192.168.1.30: ICMP echo request, id 10, seq 3, length 64
17:52:37.932100 IP 172.0.0.10 > 192.168.1.30: ICMP echo request, id 10, seq 4, length 64
but there's no answer and it even seems that those packets never reach R, even if apparently the routing is set up correctly:
A# ip route get 192.168.1.30
192.168.1.30 dev wg0 src 172.0.0.20 uid 1000
cache
So I thought that it might wireguard. There's an AllowedIPs
option that might be useful, so I changed the configurations like this:
# wg0.conf on A and B
[Interface]
Address = 172.0.0.10/24
PrivateKey = AAAAAAAAAAAAAAAAAAAAAAAAAA
[Peer]
PublicKey = rrrrrrrrrrrrrrrrrrrrrrrrrr
Endpoint = vpn.example.com:51820
AllowedIPs = 172.0.0.0/24, 192.168.1.30/32 # added second addr
on R I changed it like this:
# wg0.conf on R, the VPN hub
[Interface]
Address = 172.0.0.1/24
PrivateKey = RRRRRRRRRRRRRRRRRRRRRRRRRR
[Peer]
PublicKey = aaaaaaaaaaaaaaaaaaaaaaaaaa
AllowedIPs = 172.0.0.10/32, 192.168.1.30/32 # added second addr
[Peer]
PublicKey = bbbbbbbbbbbbbbbbbbbbbbbbbb
AllowedIPs = 172.0.0.20/32, 192.168.1.30/32 # added second addr
and rebooted wireguard on all hosts.
Now I can see some traffic flowing from A to R, but it doesn't seem to get to B:
A# tcpdump -n -l -i wg0 | grep 192.168
...
18:11:15.421908 IP 172.0.0.10 > 192.168.1.30: ICMP echo request, id 25, seq 50, length 64
...
R# tcpdump -n -l -i wg0 | grep 192.168
...
18:11:15.421908 IP 172.0.0.10 > 192.168.1.30: ICMP echo request, id 25, seq 50, length 64
...
B# tcpdump -n -l -i wg0 | grep 192.168
The route on B doesn't seem right:
B# ip route get 192.168.1.30
192.168.1.30 dev wg0 src 172.0.0.20 uid 30042
cache
...in fact, I cannot ping C anymore from B... But that's expected since I changed the route in B's wireguard configuration. So I rolled it back and B can ping C, but packets are still not received.
Now I'm stuck: I don't get what's going on and why packets are not routed to B.
Also, I'm not sure how a packet coming to B from wg0 should be routed to eth0 towards C: does B needs some other entries in the routing table or will sysctl net.ipv4.ip_forward=1