3

I have a VPS with 2 public IPs (assume 192.168.0.1 and 192.168.0.2)

I am trying to do a local tunnel to my router on my VPS bound to the second IP, and then access it via another machine. I do the following -

# ssh -g -L 192.168.0.2:22:remote_machine:22 remote_machine

Then, I am trying to access 192.168.0.2 from my laptop in a coffee shop, but it times out. What could be happening? here's what I have troubleshooted -->

  • My SSH server on my VPS is only listening on 192.168.0.1. When I do a netstat - plant |grep LISTEN I see tcp 0 0 192.168.0.1:22 0.0.0.0:* LISTEN 603/sshd correctly, and 603 is indeed the process ID of SSHD.

  • When I execute the above port forward, when I do netstat -plant | grep LISTEN I see

    tcp 0 0 192.168.0.2:22 0.0.0.0:* LISTEN 1416/ssh 
    tcp 0 0 192.168.0.1:22 0.0.0.0:* LISTEN 603/sshd
    

And 1416 is indeed the process ID of my ssh call.

  • selinux is disabled

  • iptables -L lists nothing. No firewall of any sort whatsoever.

  • I am able to do ssh 192.168.0.2 on the VPS, and it successfully takes me to remote_machine. However, I am not able to get the same behavior from outside the VPS (from my coffee shop)

  • The /etc/ssh/ssh_config , /etc/ssh/sshd_config, $HOME/.ssh/config everything contains the line GatewayPorts yes , and I also use the -g option. In fact, I have tried all combinations and still unable to access the local forward port from a remote machine.

  • When I run ssh with -vvv I do see ->

    debug1: Local connections to 192.168.0.2:22 forwarded to remote address remote_machine:22
    debug3: channel_setup_fwd_listener: type 2 wildcard 0 addr 192.168.0.2
    debug1: Local forwarding listening on 192.168.0.2 port 22.
    

However, there's no notification of any action when I try to connect to that port.

  • I have tried this as a root user with privileged ports and non root user with high numbered ports. Same behavior. Access is only possible from the VPS itself, but not outside the VPS.

  • If I set the VPS SSH server to listen on 192.168.0.2 as well, I am able to access the VPS from that address. However, when I create a tunnel with one of the end points on 192.168.0.2 and another on remote machine, access to the tunnel is only possible from within the VPS, not anywhere outside.

Any idea what I am missing?

  • Maybe the coffee shop blocks port 22? You could try connecting to a well-known site like github.com. – Kenster Nov 22 '15 at 0:02
  • Nope, that is definitely not the case, since I can access the VPS itself via SSH. Also, this behavior is not just for SSH. Even if I forward a port that is running some other service (http based for instance) I see the same behavior, I can access it from within the VPS, but not from a remote machine. – Hari Sundararajan Nov 22 '15 at 0:54
  • Who is the VPS provider? – cutrightjm Nov 22 '15 at 7:36
  • Please don't use public IP addresses (especially those belonging to others). – ctrl-alt-delor May 14 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.