I'm using Wireguard as docker container on a pi. I'm running a couple other services on the pi that I want to be only accessible over the wireguard connection. The wireguard server created an interface wg0
and a subnet 10.8.0.0/24
. From inside the container I'm able to connect to the host via 172.17.0.1
so I searched and was able to create the following configuration inside the container:
iptables -t nat -A PREROUTING -d 10.8.0.1/32 -j DNAT --to-destination 172.17.0.1
This allows me to connect from the wireguard client to the wireguard host ip 10.8.0.1
and through that way connect to all services running on the and other containers.
This works fine except that the source ip shows the ip from the docker container.
I have 3 questions:
- Is there any way to show the source ip as
10.8.0.2
(the wireguard client ip)? - Does this impose any security risks?
- Is there a better way to do this?
I'm aware that I could also use docker host mode instead of bridge mode but that comes with it's own set of challenges. I also know that I could access 172.17.0.1
from the vpn client. Only that doesn't work when connected to multiple vpn's at the same time.
Many thanks in advance.