3

In local port forwarding, what DNS server resolves the name of internal_db.local?

Would that be the internal SSH server's DNS? (that's what I would think)

Or is it the external DNS server that assigns the sshgateway.com its address?

For example:

ssh -L 4000:internal_db.local:3306 [email protected]

2 Answers 2

3

Port forwarding in SSH involves a local IP, a local port, a remote IP, a remote port, and a destination. As in:

ssh -L $LOCAL_IP:$LOCAL_PORT:$REMOTE_IP:$REMOTE_PORT $DESTINATION

In this example, DNS names for $LOCAL_IP and $DESTINATION are resolved by the environment in which the ssh command runs. DNS names for $REMOTE_IP are resolved by the environment at $DESTINATION.

1

The complete sequence of a port forwarding in ssh is
-L [<local_ip>:]<local_port>:<remote_ip>:<remote_port>
whereby the local_ip can be omitted.

The <local_ip> (or the DNS name) will be resolved from the local host and the <remote_ip> (or DNS name) by the remote host (in your case that is sshgateway.com).

Edit based on your comment:
Correct me if I don't get it.
Your environment looks like this:

host_1  ->   host_2   ->   host_3
your_PC -> sshgateway -> internal_db.local

and you want to connect from host_1 to a database located on host_3.
With your suggested local port forwarding you forward port 4000 of host_1 through host_2 to port 3306 of host_3.
For that, your connection will be tunneled through ssh from host_1 to host_2 and then send as normal ip-packets from host_2 to host_3, as if host_2 would connect to the database.
Therefore host_2 (sshgateway.com) has to resolve the ip address of host_3 (internal_db.local) with his DNS server.
Hope that clears your question.

7
  • I think you accidentally a word. May 14, 2020 at 19:24
  • @leeand00 I just took back your editing as local host was meant to refer to the local machine and not to localhost as in 127.0.0.1
    – bey0nd
    May 14, 2020 at 19:26
  • @TrippKinetics I'm not sure what you are referring to.
    – bey0nd
    May 14, 2020 at 19:27
  • "The (or the DNS name)" ?? May 14, 2020 at 19:30
  • 1
    @bey0nd Okay you're not understanding the command I don't think (I could be wrong); but the remote_ip is behind the ssh_gateway; the second part of my command says "login to [email protected]" but forward the ports from internal_db.local to my localhost, so I can connect to the database through SSH using Local Port Forwarding.
    – leeand00
    May 14, 2020 at 20:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .