I have a postgres server (but it could be any service, I suppose) running in local a network and a server (AWS EC2 instance) that I'd like to use as an intermediary to access the database.
So far, I've managed to make a reverse ssh tunnel from the local server to the intermediary:
autossh -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -fnN -R 5432:localhost:5432 user@intermedite-host
I can already access the database from my laptop if I do a "forward" tunnel to the server, and then just connect to my localhost:5432
(in the laptop).
However, what I'd like to do is to have the database public as if it were running in the intermediary server, connecting to it with just intermedite-host:5432
.
So far, I've played around with another ssh tunnel only inside intermedite-host
and with iptables
. But I'm out of my depth and can't figure it out. Any help would be appreciated.