1

I am trying to google a method to achieve this but unable to find one.

Basically, I have created an SSH tunnel to several remote hosts through a bastion host using a command like this.

ssh -L 9000:ourprodserver.domain.com:1521 \
    -L 9001:otherprodserver.domain.com:1521 \
-A -l knayak@somejumphost.domain.com somebastionhost.domain.net

Now, how do I know the connection details mapping to the local port whenever the tunnel is active.

i.e I want to be able to create a list of this form.

L_port         Remote_host            R_port
9000       ourprodserver.domain.com   1521
9001       otherprodserver.domain.com 1521

Is it possible?

  • Excellent question, though I'd like to know if there is any way to see what/where the tunnel ends at in general, never mind a specific tabular format. – ivanivan Jun 1 '18 at 11:42
  • @ivanivan : Yes. It need not be in this format. But, information contained in each of the column should be available somewhere, that's all. – Kaushik Nayak Jun 1 '18 at 12:09
0

A simple solution exists, but it will only list the currently active tunnel connections: it's using the ssh escape sequence ~#

If the tunnel is not used, it won't be shown.

From the help (shown with ~? inside an active ssh connection):

~# - list forwarded connections

Example output will be :

user@somebastionhost$ ~#
The following connections are open:
  #4 client-session (t4 r0 i0/0 o0/0 fd 9/10 cc -1)
  #5 direct-tcpip: listening port 9000 for ourprodserver.domain.com port 1521, connect from 127.0.0.1 port 48954 to 127.0.0.1 port 9000 (t3 nr0 i0/0 o0/0 fd 12/12 cc -1)

On the client side, you can get an idea of the open tunnels, even the inactive ones, by listing TCP sockets it has opened:

lsof -n -p <pidof-ssh-client> -a -iTCP -a -sTCP:LISTEN

Although this doesn't fully answer your question, it may be a starting point.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.