I a bunch of hosts in the cloud with private and public IPs. Until now, I could access all the hosts publicly and any way I want. Now, I want to disable some access to all of these hosts from the outside and set up a VPN.
I have created a VPN server and everything works fine -- I can see my internal network easily. There is this one problem that I am facing right now. All the hosts are being accessed via public DNS and this DNS have public IPs for all the hosts.
I want a way to translate all the public IPs to private IPs. For example, let's say I have 2 hosts with the following IPs:
Host 1:
Private IP: 10.1.0.5
Public IP: 1.2.3.4
Host 2:
Private IP: 10.1.0.6
Public IP: 5.6.7.8
If I access 5.6.7.8 (1.2.3.4), I want the server to translate it to 10.1.0.6 (10.1.0.5).
Is it possible via iptables? I have tried the following so far but nothing changed:
iptables -t nat -A OUTPUT -d 5.6.7.8 -j DNAT --to-destination 10.1.0.6