-   Linux - Networking (
-   -   unforward ssh port? (

santana 02-02-2010 01:48 PM

unforward ssh port?
after login in I forward a port from our front end to a node like this:


fe$ ~C <enter>

so far I have been loging out of the ssh session to remove that port forward. Is there a command to do so, so I won't have to log out? I really just want to redirect the remote end (node:YYYY) to a different node.

rweaver 02-02-2010 03:39 PM

Find the process id and kill it.

santana 02-02-2010 03:58 PM

uh...if I kill ssh that will log me out...

Web31337 02-02-2010 11:48 PM

lol rweaver has a sense of humor. actually it won't log you out when you kill ssh... it will just cause connection drop :D

wondering about this too...
no way I just built the latest ssh 5.3p1 from sources: they just added -D param in that ~C menu.
you know what... it looks like simply not supported.
here's some code(clientloop.c:810, 5.3p1)

        if (*s == 'K') {
                delete = 1;
        if (*s == 'L')
                local = 1;
        else if (*s == 'R')
                remote = 1;
        else if (*s == 'D')
                dynamic = 1;
        else {
                logit("Invalid command.");
                goto out;

        if ((local || dynamic) && delete) {
                logit("Not supported.");
                goto out;

probably there is a way around if try to hack the code...

Web31337 02-03-2010 12:55 AM

I'm not a good C coder but from here it looks like to get this to work we have to list existing port forwarding "channels", find one listening that local port and destroy it in channel_setup_fwd_listen() function before calling bind() and listen() etc.
Like it's done here: (channels.c:2630, 5.3p1)

channel_cancel_rport_listener(const char *host, u_short port)
        u_int i;
        int found = 0;

        for (i = 0; i < channels_alloc; i++) {
                Channel *c = channels[i];

                if (c != NULL && c->type == SSH_CHANNEL_RPORT_LISTENER &&
                    strcmp(c->path, host) == 0 && c->listening_port == port) {
                        debug2("%s: close channel %d", __func__, i);
                        found = 1;

        return (found);

i'm now really curious about this, maybe I can add this little improvement. I'll go try this out by now.

Web31337 02-03-2010 06:08 AM

santana you may either use -D parameter in SSH(since 5.2) or you can look here for alternate solution I've cooked today :)
It's a sort of solution, anyways, I don't guarantee it's going to work in your case but still might be useful.

rweaver 02-03-2010 11:14 AM

The long and short answer is without resetting the ssh session (at least on the versions I have access to (5.1.x)) there is no way to kill an existing tunnel you created. I think the answer offered by web31337 is as good an answer as you're going to find. I also think it would be something worthwhile to suggest to the openssh developers... there IS a way to do it with the protocol because you can do it with putty for instance connected to an openssh server... but I can't find a good way to do it with the command line version of the openssh client.

Web31337 02-03-2010 11:46 AM

Probably the one I suggest is the very method of doing that. At least it seem to be logically correct in code. I can't see a reason why such a simple thing was not implemented in OpenSSH while it is added in PuTTY.
Tunnel appears to be freed correctly(at least debug messages say that, and it just works as meant to), but there are still things I have to add, but not now.

santana 02-03-2010 12:04 PM

Wow! Awesome! Thanks guys

All times are GMT -5. The time now is 10:10 PM.