[Skip To Content]


# SSH port forwarding with OSX

If you’re doing remote port forwarding on Leopard, you might encounter the as problem as we have done this morning. I don’t remember this happening with Tiger, so I think it’s a Leopard specific thing.

We wanted a client to see a in-development feature hosted on one of our machines in the office, which is protected by a firewall. For various reasons, we can’t punch a hole in that firewall and configure the router to direct requests for a given port to a specific machine.

You can normally do this by running something like :

  1. ssh -R 6000:localhost:5000 blog.carldr.com

We’re wanting to tunnel HTTP here, so in this example, it means that requests to ‘http://blog.carldr.com:6000/’ are forwarded (transparently to the user) to port 5000 on the machine where the ‘ssh’ was ran from.

However, this didn’t work. The connection which SSH was trying to make to port 5000 on our local machine was being refused. With use of ‘ssh -v’, ‘lsof’, ‘netstat’ et al., we found out what the problem was.

On Leopard, ‘localhost’ resolves as IPv6 ’::1’, so ssh is trying to connect to that port. The web server we were running locally was binding to 0.0.0.0, which is all interfaces, but just IPv4. The solution is one of these :

  1. ssh -4 -R 6000:localhost:5000 blog.carldr.com
  1. ssh -R 6000:127.0.0.1:5000 blog.carldr.com

Or binding the web server to ’::1’.

More about this site...

Last Week’s Top 5 Albums (More »)

  1. Conor OberstConor Oberst
  2. Cruel TownBroder Daniel
  3. Far From the Maddening CrowdsChicane
  4. The Midnight Organ FightFrightened Rabbit
  5. Perfect CureLorraine