Network diagram: Laptop (10.8.0.2) -> (wireguard) -> server A (10.8.0.1, 10.10.0.10) -> server B (10.10.0.20)
sequence diagram
I've connected my laptop (10.8.0.2) to a server A (10.8.0.1) via Wireguard.
I can ping/curl to the server A (10.10.0.10), but not another server B (10.10.0.20).
When ping 10.10.0.20
server B from my laptop, I find the following on server A:
tcpdump -nn -i wg0
shows request, but no response:
tcpdump -nn -i enp7s0
shows request and response
So the problem seems to be that the response is not forwarded from enp7s0 to wg0.
But why not?
This is my iptables configuration:
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -o enp7s0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -o enp7s0 -j MASQUERADE
Laptop wireguard:
[Interface]
PrivateKey = ...
Address = 10.8.0.2/24
[Peer]
PublicKey = ...
AllowedIPs = 10.8.0.0/24,10.10.0.0/24
Endpoint = ...
Server A wireguard:
[Interface]
PrivateKey =
Address = 10.8.0.1/24
ListenPort = 51820
SaveConfig = true
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -o cilium_host -j MASQUERADE
PostUp = iptables -t nat -A POSTROUTING -o enp7s0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -o cilium_host -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -o enp7s0 -j MASQUERADE
[Peer]
PublicKey =
AllowedIPs = 10.8.0.2/32
Server B and server A are connected via a virtual private network.
Update: wireguard service reload
Restarting the service also seemed to help.
systemctl reload [email protected]
systemctl restart [email protected]
You can also try adding these rules, but I removed them and it still worked:
PostUp = iptables -A FORWARD -o wg0 -j ACCEPT
PostDown = iptables -D FORWARD -o wg0 -j ACCEPT
Update: Other related problems (FYI):
When I analyzed my routing table (ip route
):
default via 172.31.1.1 dev eth0
10.0.0.0/24 via 10.0.1.50 dev cilium_host proto kernel src 10.0.1.50 mtu 1400
10.0.0.0/8 via 10.0.0.1 dev enp7s0
10.0.0.1 dev enp7s0 scope link
10.0.1.0/24 via 10.0.1.50 dev cilium_host proto kernel src 10.0.1.50
10.0.1.50 dev cilium_host proto kernel scope link
10.0.2.0/24 via 10.0.1.50 dev cilium_host proto kernel src 10.0.1.50 mtu 1400
10.0.3.0/24 via 10.0.1.50 dev cilium_host proto kernel src 10.0.1.50 mtu 1400
10.8.0.0/24 dev wg0 proto kernel scope link src 10.8.0.1
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
172.31.1.1 dev eth0 scope link
I realized that 10.0.0.0/8 via 10.0.0.1 dev enp7s0
was conflicting with the other routes, due to the 10.10.0.0/24 subnet belonging to a larger 10.0.0.0/8 range. So I moved my Kubernetes/Cilium network (to avoid 10.0.0.0/8 that could conflict with common networks at coffee shops etc.), and narrowed the VPC network as well.