VNC via SSH Problem

remote desktopssh

I am trying to screen share to my Mac Server, on my home LAN, remotely via the internet.

I can VNC to my server while on the LAN find with vnc://lanserver:5900.

I am forwarding port 22 from my DSL to the LAN VNC computer.

I can SSH to the LAN PC through the firewall ok.

I can setup the SSH tunnel, logs:

Authenticated to xx.xxx.xxx.xxx ([xx.xxx.xxx.xxx]:22).
debug1: Local connections to LOCALHOST:5901 forwarded to remote address x.x.x.x:5900
debug1: Local forwarding listening on ::1 port 5901.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 5901.
debug1: channel 1: new [port listener]
debug1: channel 2: new [client-session]

When I try vnc://127.0.0.0.1:5901 on the remote machine, I get a timeout error:

lanserver:~ user$ debug1: Connection to port 5901 forwarding to x.x.x.x port 5900 requested.
debug1: channel 3: new [direct-tcpip]
lanserver:~ user$ channel 3: open failed: connect failed: Operation timed out

I'm out of options trying to find out why the connection times out.

Best Answer

It looks to me like you're using the wrong remote IP address in your tunnel. You should be using -L 5901:127.0.0.1:5900 ....

It's important to realize that the destination IP for the tunnel is where the remote (server) computer forwards the connection to, so 127.0.0.1:5900 means it connects to port 5900 on the server itself.

It looks like you're using ssh -L 5901:PublicIPofServer:5900 ..., which makes the server try to connect to port 5900 on its own public IP. But that's actually the WAN IP of the router the server's behind, so unless that router forwards port 5900 to the private IP of the server (in which case you wouldn't need the SSH tunnel) AND the router supports NAT loopback (aka hairpin NAT), this won't work.