ssh tunnel and receiving Web pages through the tunnel

5,023

Solution 1

Here's what I use to load my webmin on my servers (which is firewalled away so only somebody with ssh access can see it):

ssh -l oli -L 9090:localhost:9090 my-server-ip

That connects me to the server and maps my local port 9090 to the server's P9090. I just browse at http://localhost:9090/ and I can see the webmin.


If you're trying to connect to another device through your server, you don't really want to faff around with manual tunnel options. ssh has a built-in SOCKS proxy mode. Run this:

ssh -D 9999 oli@my-server-ip

Then you tell your browser about the SOCKS proxy. Look under the network settings. localhost as the server, port 9999. Remember this has to be under the setting for SOCKS. This is not a HTTP proxy.

Now when you browse, all the traffic goes through the ssh tunnel. This means if there's a device on the other end that only your server can reach, you can connect to that using its IP.

Note that DNS lookups and other network traffic won't go through the tunnel (AFAIK) so you need to connect to an IP if it makes a difference (which I suspect it will in this case)

Solution 2

You want a reverse Tunnel, try this:

ssh -NT -R 4444:local.mydomain.com:80 [email protected]

What this does is initiate a connection to remote.mydomain.com and forwards TCP port 4444 on remote.mydomain.com to TCP port 80 on local.mydomain.com. "-N" tells ssh to just set up the tunnel and not to prepare a command stream, and "-T" tells ssh not to allocate a pseudo-tty on the remote system. The "-R" option tells ssh to set up the tunnel as a reverse tunnel.

Share:
5,023

Related videos on Youtube

Riccardo Magrini
Author by

Riccardo Magrini

Updated on September 18, 2022

Comments

  • Riccardo Magrini
    Riccardo Magrini over 1 year

    I've tried to create a tunnel torward a client passed through a server, using the following command

    ssh -X -f admin@IP_server -N -L 4444:IP_client:80

    but when try to open client:80 by firefox receive as error this

    channel 2: open failed: unknown channel type: 
    Connection to 81.21.20.207 closed by remote host.
    

    someone knows where is the issue? thanks so much

  • Riccardo Magrini
    Riccardo Magrini about 13 years
    I'm sorry I've explained it bad.you right! My situation is the following: client -> remote_server -> voip phone. I should create a tunnel on the remote server to have the possibility of accessing to the graphic's interface of VoIP phone by firefox. I tried gSTM but receive the same error
  • Riccardo Magrini
    Riccardo Magrini about 13 years
    I've to pass through a server to reach a VoIP phone and open its own web interface to make some configuration on it.
  • Riccardo Magrini
    Riccardo Magrini about 13 years
    If I've to connect to a remote server that suggest is fine, my issue is to reach a VoIP phone which is situated back a PBX. So the topology is the following PC -> Internet -> PBX -> VoIP phone. The PBX is a network device as a router.
  • Riccardo Magrini
    Riccardo Magrini about 13 years
    I know that using putty can make it but I want make it using Ubuntu
  • nicoX
    nicoX over 10 years
    I get a SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1 Protocol mismatch in Firefox
  • Oli
    Oli over 10 years
    @nicoX I assume you're using the second, proxy method. Make sure you've put it in the SOCKS Host box and not the HTTP Proxy input.
  • nicoX
    nicoX over 10 years
    @oli I'm on a local network. ssh -R 4444:localhost:22 desktopX@<IP> from my VirtualBox server to my Ubuntu desktop client. From my desktop client I run ssh -D 4444 clientX@<IP>. I tried SOCKS but it don't work.
  • Michael
    Michael over 10 years
    So this is what I got to work (with error messages in the terminal): ssh -l remoteuser -L localport:localhost:remoteport remoteIP