SSH Reverse Port Forwarding with PuTTy - how to specify bind address
Using Putty, I have set up a reverse proxy which allows me to connect on port 8080 of the server at server.tld
to port 80 of the machine which initiated the SSH connection.
The server allows me to connect on localhost:8080
and returns the result of initiator:80
when I connect on the server.
This question says to enable GatewayPorts and bind to all addresses.
Using Putty, how can I expose port 8080 on the server so that when a request comes through on the external interface (e.g. a web request) the port is forwarded to the initiator:80
?
There are two checkboxes when setting up the PuTTY tunnel,
- Local ports accept connections from other hosts
- Remote ports do the same (SSH-2 only)
the second of those does what you need.
I just tested it,
PuTTY tunnels dialog,
- Tick Remote ports ...
- Put 8080 into Source port
- Put 127.0.0.1:80 into Destination port
- Select 'Remote' radio button
- Click Add
- Connect
Works fine, here's the resulting netstat,
# netstat -an | grep 8080
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp6 0 0 :::8080 :::* LISTEN
You can also use plink.exe that comes with PuTTY, for example,
plink -R *:8080:localhost:80 [email protected]
which works fine as well.
# netstat -an | grep 8080
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp6 0 0 :::8080 :::* LISTEN
If you're still getting 127.0.0.1:8080 on the host, then GatewayPorts is still set to no in your sshd config.
Also, don't forget to update the firewall on the target server to allow external connections to port 8080.