PuTTY dynamic port forwarding with access to localhost ports

7,983

So you are forwarding 8000 on your local machine to connect to a webserver listening on 127.0.0.1:8000 on your remote machine?

Then you are asking putty to listen on 8000 on your local machine to do the dynamic port forwarding. It won't be able to do both at once.

You could change the dynamic port to something other than 8000 - how about 8001?

So have the Dynamic forward (SOCKS) on 8001, and keep the local port forward from 8000 to 127.0.0.1:8000.

Share:
7,983

Related videos on Youtube

gatlanticus
Author by

gatlanticus

Updated on September 18, 2022

Comments

  • gatlanticus
    gatlanticus almost 2 years

    I want to combine the functionality of two SSH tunnels set up through PuTTY.

    The first tunnel is:

    • PuTTY: L8000 127.0.0.1:8000 (in SSH->Tunnels), and
    • Firefox: SOCKS (v5) Host:127.0.0.1, Port:8000

    This lets me navigate to http://localhost:8000 on my local browser and connect to localhost:8000 on my remote server, which I use to access a web development server on that port.

    The second tunnel simply uses PuTTY set to D8000 (with same Firefox settings), which lets me browse the internet at large through my remote server.

    The problem is, I want to connect to, say, "google.com" and "localhost:8000" (on the remote server) in the same session. This is mainly because my web development server (tunnel 1) needs access to remote links (e.g. google APIs). I thought the dynamic port forward in tunnel 2 would work but I can no longer reach localhost:8000 on the remote server by navigating to localhost:8000 in the browser.

    I have searched far and wide but I cannot find any answer. I suspect it's because the answer is too obvious :/


    tunnel 1 PuTTY settings

    tunnel 2 PuTTY settings

    netstat -nptl output (with development server running)

    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 23172/python tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 574/sshd tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 572/memcached tcp 0 0 127.0.0.1:38637 0.0.0.0:* LISTEN 27836/firefox tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN 27635/Xvfb tcp 0 0 127.0.0.1:5454 0.0.0.0:* LISTEN 812/postgres tcp6 0 0 :::3047 :::* LISTEN 574/sshd tcp6 0 0 :::11211 :::* LISTEN 572/memcached tcp6 0 0 :::6000 :::* LISTEN 27635/Xvfb tcp6 0 0 :::8983 :::* LISTEN 257/java

    • Admin
      Admin over 7 years
      can you screenshot the putty port forwarding configuration for both tunnels? and paste the output from netstat -ptl (edit any sensitive IPs)
    • Admin
      Admin over 7 years
      @PHPaul Sure, I've uploaded the screenshots.
    • Admin
      Admin over 7 years
      Thanks... by the way I don't think anything is listening on port 8000 on your machine at the moment? I should have said netstat -nptl which would have given port numbers instead of names, but I don't think those names correspond to 8000.
    • Admin
      Admin over 7 years
      Oh, I wasn't running the development server earlier, so I re-ran netstat -tlpn with the server running and it is listening on 8000
    • Admin
      Admin over 7 years
      seeing as it it is only bound to 127.0.0.1, I will revise my answer below slightly....
  • gatlanticus
    gatlanticus over 7 years
    Thanks for the ideas. So far I've set the dynamic port forward to use 8001, and Firefox to use SOCKS 127.0.0.1 8001 too. The dynamic port forward then works as normal (e.g. can visit google.com), but 127.0.0.1:8000 doesn't redirect to remote server 8000 like with tunnel 1. Also set a hostname alias newhostname and tried navigating to newhostname:8000 but didn't get there
  • bao7uo
    bao7uo over 7 years
    updated answer accordingly... :)
  • gatlanticus
    gatlanticus over 7 years
    OK, it works and I'm thrilled! It was a bit different to what you suggested though, as I simply had to add two rules to the same PuTTY connection (one local listening on 8000, one dynamic listening on 8001) and only use one Firefox browser with SOCKS 127.0.0.1:8001. If you are happy with me revising your answer to what worked and removing the extra suggestions, I can mark your answer as accepted
  • gatlanticus
    gatlanticus over 7 years
    Thanks. I +1'd your answer too but with only 6 points it doesn't even show!