You are not logged in.

#1 2011-03-12 16:42:54

sironitomas
Member
From: Cordoba, Argentina
Registered: 2009-11-28
Posts: 174
Website

[SOLVED] SSH port forwarding

Hi fellows. I am trying to forward a port from my pc to another one in the network using ssh.

With only learning purposes, I'm trying to connect to the mpd of the server, via a tunneled ssh connection. First of all, the ssh shell works perfectly.

Now, to make the port tunnel I execute:

$ ssh -v -NL 1919:myserver:6600 root@myserver

Where 1919 is an arbitrary port, 6600 is the mpd port in the server, and myserver is of course a IP in /etc/hosts. When I execute that, it seems it will work until I try this command:

$ ncmpcpp -h localhost -p 1919

But it says: "Connection closed by the server'. At the same time, the verbose output of ssh shows:

channel 1: open failed: administratively prohibited: open failed

TCPforwarding is enabled in the ssh server. What am I doing wrong? Thanks in advance.

Last edited by sironitomas (2011-03-12 19:42:34)

Offline

#2 2011-03-12 17:48:59

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: [SOLVED] SSH port forwarding

Can you try a higher port (e.g. 13000) instead of 1919?


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#3 2011-03-12 18:10:13

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: [SOLVED] SSH port forwarding

I don't think you're doing it correctly.

$ ssh server -L 1919/localhost/6600

Did you:
configure your mpd client to use localhost:1919 as its sever?
setup port forwarding in /etc/ssh/sshd_conf

Post your /etc/hosts.allow too.

Last edited by graysky (2011-03-12 18:13:41)

Offline

#4 2011-03-12 18:12:49

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,730
Website

Re: [SOLVED] SSH port forwarding

... and the /etc/hosts.allow in the receivng system allows the connection. Correct?
And, of course, if there are any firewalls in the receiving server it should also allow the connection.

Hope this helps.

R.

@graysky, you are too fast for me smile

Last edited by ralvez (2011-03-12 18:14:22)

Offline

#5 2011-03-12 19:42:06

sironitomas
Member
From: Cordoba, Argentina
Registered: 2009-11-28
Posts: 174
Website

Re: [SOLVED] SSH port forwarding

Thanks for the answers. I was doing it wrong, although I still don't understand why.

graysky's answer did the trick!

It works with any of these:

$ ssh -L 1919/localhost/6600 root@myserver
$ ssh myserver -L 1919/localhost/6600 -l root

Those are both the same, right? The explanation in man is a little bit confusing for me...

According to man:

[bind_address:]port:host:hostport

Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side...

So in my original post, I gave it port=1919, host=myserver and hostport=6600. Why didn't it work that way?

Last edited by sironitomas (2011-03-12 20:40:58)

Offline

#6 2011-03-12 20:21:04

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: [SOLVED] SSH port forwarding

A better question is what is it you mean by SOLVED? You just forwarded port 1919 on local machine to port 6600 on the same computer...

What hapens if you do

telnet 1919 localhost

Perhaps, an example is in order. Suppose I have a firewall, which blocks outgoing traffic to port 993 (secure imap). This means, that I can not use fetchmail to get emails from imap.gmail.com. However, I can circumvent this by doing:

ssh -vxNL 13001:imap.gmail.com:993 user@some.server.edu

and point fetchmail to localhost:13001. Then, the request to local port 13001 will be forwarded to some.server.edu, and from there to imap.gmail.com:993.


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#7 2011-03-12 20:36:05

sironitomas
Member
From: Cordoba, Argentina
Registered: 2009-11-28
Posts: 174
Website

Re: [SOLVED] SSH port forwarding

Leonid.I wrote:

A better question is what is it you mean by SOLVED? You just forwarded port 1919 on local machine to port 6600 on the same computer...

No, I think you misunderstood something. I just forwarded port 1919 in my local machine to port 6600 in the server. I wasn't able get it working and that's why I posted here in the first place. Thanks to graysky's answer I finally could make it work.

What it is not "solved" is my understanding on the syntax of the -L option.

PS: I also don't know exactly why is localhost given instead of myserver.

Last edited by sironitomas (2011-03-12 20:39:28)

Offline

#8 2011-03-12 20:50:34

Leonid.I
Member
From: Aethyr
Registered: 2009-03-22
Posts: 999

Re: [SOLVED] SSH port forwarding

sironitomas wrote:

PS: I also don't know exactly why is localhost given instead of myserver.

That's kinda my point, because "-L x:host:y some.server" means "take traffic from any local program to local port  x and forward it to host's port y through some.server". I did what you were doing in the OP (ntc and haf1 are two machines):

[ntc] ~> ssh -xvNL 13001:localhost:5001 haf1
...
[ntc] ~> ssh -p 13001 localhost
ssh_exchange_identification: Connection closed by remote host

because there is no sshd on port 5001, and ssh output on [ntc]

debug1: Local connections to LOCALHOST:13001 forwarded to remote address localhost:5001
debug1: Local forwarding listening on 127.0.0.1 port 13001.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on ::1 port 13001.
debug1: channel 1: new [port listener]
debug1: Entering interactive session.
>>>debug1: Connection to port 13001 forwarding to localhost port 5001 requested.
debug1: channel 2: new [direct-tcpip]
channel 2: open failed: connect failed: Connection refused
debug1: channel 2: free: direct-tcpip: listening port 13001 for localhost port 5001, connect from 127.0.0.1 port 33937, nchannels 3

Please note the first and ">>>" lines? What am I missing?


Arch Linux is more than just GNU/Linux -- it's an adventure
pkill -9 systemd

Offline

#9 2011-03-12 22:07:59

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: [SOLVED] SSH port forwarding

Glad you got it working!

Offline

Board footer

Powered by FluxBB