I have a private docker host (A) connected via a Wireguard tunnel to a public "router" in a cloud environment (B).
Wireguard:
(Docker Container)
eth0 172.17.0.2
|
docker0 172.17.0.1
(A) eth0 192.168.1.2 --- Internet (can't accept conns)
wg0 10.0.16.6
|
wg0 10.0.16.5
(B)
eth0 public IP Q
|
USER
The idea is to have traffic first go to B on it's public IP and then forward the request to B and forward the responses back.
I have followed this guide, specifically the Policy Routing section.
The wireguard configuration on A is as follows:
[Interface]
Address = 10.0.16.6/30
Table = 123
PreUp = ip rule add from 10.0.16.6 table 123 priority 456
PostDown = ip rule del from 10.0.16.6 table 123 priority 456
[Peer]
AllowedIPs = 0.0.0.0/0
Endpoint = Q:51820
PersistentKeepalive = 30
The packet with source 10.0.16.6 and destination of the original sender should be routed over the wg0 interface because of this rule:
0: from all lookup local
456: from 10.0.16.6 lookup 123 ### This one
32766: from all lookup main
32767: from all lookup default
So on A, a packet from B enters from the wireguard interface (with destination address 10.0.16.6) and gets routed to the docker http server correctly.
Then as the response packet comes back out from the docker container to A, it has the container's source address. This means that the routing rule above doesn't get respected like it would if the http server was running on the host A.
The packet ends up being NATed after the routing and then sent off on A eth0 instead of A wg0.
I would like the packets to get re-routed after the NAT stage.
Any regular traffic leaving the docker container should not go over the wg0 interface, only traffic originating from the wg0 interface as the referenced guide suggests.
If any further information is required, I am happy to provide e.g. iptables -L
etc