I am looking into building something like a "VPN satellite device". Basically a Linux box, that can be used in any typically home network. It should obtain a DHCP lease, connect to a vpn server, and then forward/DNAT/SNAT certain ports to an address within the vpn. So, basically, it provides certain services that are hosted within the vpn, as if they were hosted on the satellite device.
First question: Does this technique have a name already? Is this a well known pattern (or anti-pattern) I can read about somewhere?
Going into the details, there is a specific problem that, as it seems, I need to specify the local IP when setting up DNAT/SNAT. At least, that is the cleanest, I assume.
I come up with some interfaces and IP adresses as an example, the device has:
- eth0 with an address obtained through DHCP. Lets assume its 192.168.1.13. But I need code/rules that is agnostic of that address
- wg0 (the vpn interface) with IP 10.0.0.17. This is an address I know for sure. I can use it in code/rules. On that network, there is a server with IP 10.0.0.1.
Lets assume, the server on 10.0.0.1 has an http service running on port 80. I want to setup my satellite box to provide this service on port 80, to whatever home network it is plugged into.
For this, i could have rules like:
iptables -t nat -A PREROUTING -p tcp -i eth0 -d 192.168.1.13 --dport 80 -j DNAT --to-destination 10.0.0.1
iptables -t nat -A POSTROUTING -o wg0 -d 10.0.0.1 -p tcp --dport 80 -j SNAT --to 10.0.0.17
But, obviously, this uses the DHCP-obtained address 192.168.1.13 , which I do not know in advance. Which is basically the heart of my question.
How to solve this in the most clean way? In the end, I want to forward about 3 ports in this way. I basically see 2 options:
a) create a script that re-sets iptable rules, which is executed after dhcp client obtained an address
b) define such rules in a way that they do not require the locally obtained IP address.
a is feasible, but looks a bit quirky to me. For b, I am not sure if its really possible, and does not generate side effects, like DNAT/SNAT-ing to many packets.