6

I am trying to Remote port forward from Raspberry pi in my local network using ssh on my windows pc

ssh -R 5941:localhost:8000 [email protected]

So from the above command, I am trying to forward connections from port 5941 on Raspberry pi server (192.168.1.191) to port 8000 on my pc (localhost) which hosts a web server on port 8000

The above ssh command executes with no errors but when i try to access http://localhost:5941/ on Raspberry Pi (192.168.1.191) i get

ERR_EMPTY_RESPONSE

I have tried

  1. Turned off firewall on my Windows PC
  2. netstat on raspberrypi gives me
$ sudo netstat -a | grep 5941
tcp        0      0 0.0.0.0:5941        0.0.0.0:*               LISTEN
tcp6       0      0 [::]:5941               [::]:*                  LISTEN
  1. when i run the ssh command in verbose mode ssh -R 5941:localhost:8000 [email protected] -v I get this
debug1: Remote connections from LOCALHOST:5941 forwarded to local address localhost:8000
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: console supports the ansi parsing
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Remote: Forwarding listen address "localhost" overridden by server GatewayPorts
debug1: remote forward success for: listen 5941, connect localhost:8000
debug1: All remote forwarding requests processed

and when i try to access http://localhost:5941/ on Raspberry Pi (192.168.1.191) i get this on ssh console

debug1: client_input_channel_open: ctype forwarded-tcpip rchan 3 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 5941, originator ::1 port 58122
debug1: getsockopt TCP_NODELAY: Invalid argument
debug1: connect_next: host localhost ([::1]:8000) in progress, fd=7
debug1: channel 1: new [::1]
debug1: confirm forwarded-tcpip
debug1: channel 1: connected to localhost port 8000
debug1: channel 1: free: ::1, nchannels 2

How should I further diagnose my problem ?

1
  • What service is running on localhost:8000 on the local system? Is the process which provides this service logging any messages? Commented Apr 21, 2021 at 18:36

1 Answer 1

19

The solution to this is to put 127.0.0.1 instead of localhost

ssh -R 5941:127.0.0.1:8000 [email protected]

This forces ipv4 instead of ipv6, for some reason ssh port forwarding in windows fails to work on ipv6, I was able to work the same command with localhost on linux just fine.

I found the solution from this post here

Sign up to request clarification or add additional context in comments.

3 Comments

For other's who may land here, I made the change above (i.e. 127.0.0.1 instead of "localhost") into a "gcloud compute ssh .." port forwarding command into a GCP windows server VM and my ZMQ REQ/REP python connection suddenly came alive.
Don't forget to enable: AllowTcpForwarding yes and GatewayPorts yes in /etc/ssh/sshd_config and restart the SSH service after changes: sudo systemctl restart sshd
Thanks. This was the solution. Very weird and inconsistent with Linux implementations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.