Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get list of open SSH tunnels?

I'm using Mac OS X client connected to FreeBSD server. I'm trying to query open tunnels on the client.

share|improve this question
What OS would this be on? Is this your server? Do you have root access to it? Please edit your question and include more information. – EEAA Mar 11 '11 at 2:53
Check your other question, the answer I gave there will solve that too. – coredump Mar 11 '11 at 3:14
Are you looking at one session with multiple tunnels or multiple sessions? Pretty different topic :) – LordT Mar 11 '11 at 13:29

You can use lsof:

$ lsof -i tcp | grep ^ssh
ssh       2211 lcipriani    3r  IPv4  20825      0t0  TCP lcipriani-laptop.local:49164-> (ESTABLISHED)
ssh       2223 lcipriani    3r  IPv4  21945      0t0  TCP lcipriani-laptop.local:34471-> (ESTABLISHED)
ssh       2640 lcipriani    3r  IPv4  37488      0t0  TCP lcipriani-laptop.local:45693-> (ESTABLISHED)
ssh       5279 lcipriani    3r  IPv4 212324      0t0  TCP lcipriani-laptop.local:56491-> (ESTABLISHED)
ssh       5279 lcipriani    4u  IPv6 210281      0t0  TCP lcipriani-laptop:10000 (LISTEN)
ssh       5279 lcipriani    5u  IPv4 210282      0t0  TCP localhost.localdomain:10000 (LISTEN)

The last line represent a tunnel (look at the state LISTEN).

share|improve this answer

In Ubuntu, with iptables and iptstate installed and standard ssh port:

iptstate -D 22

each line will represent open tunnel.

share|improve this answer
great tip.I did not knew it existed. – Registered User Mar 11 '11 at 7:06

If you're trying to find out what's using the tunnel(s) in a single ssh session, type ~# at the beginning of a line.

share|improve this answer
interesting!!!! – Valeriy Van Oct 18 '13 at 17:45
/sbin/ip tunnel list # replacement for the deprecated iptunnel command
share|improve this answer

Using lcipriani's answer in a script:

sessions=$(lsof -i tcp | grep "^ssh" | grep ESTABLISHED)
if [ -z "sessions" ]; then
    echo "no open ssh sessions"
    echo "ssh sessions are open"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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