Re: Port forwarding - different results between using "127.0.0.1" and "localhost"



"Stephan Carydakis" <scarydakis@xxxxxxxxxxxxxxxx> writes:

Hi All,

I am experiencing differing results using "ssh -R 3306:shiraz:3306
127.0.0.1" and " ssh -R 3306:shiraz:3306 localhost". If I use the IP in
port forwading, I can successfully connect to the destination MySql server
by using "localhost" or 127.0.0.1 in my connection. If I establish the port
forward using "localhost", I can only connect by using the IP address (this
is no good to me for reasons I will explain!). I've tried both the command
line mysql client and an PHP and both behave the same.

I really need to be able to use "localhost" in my connection because I have
inherited some code for a small extranet that happens to have a connection
string in about 45 different PHP files and each connection specifies
"localhost". I am trying to establish a development environment for this
extranet. I am running PHP on a Debian box but do not have a local MySql
server. I have a MySql server on Win2k machine and this is the way it must
stay. My idea is to forward local port 3306 to my Win2k's port 3306.

I do plan to fix the code so the connection string is located in just 1
file, making changes back and forth a non-issue. For now, I have to play the
hand I've been dealt. Besides, I like the idea of being able to have a
permanent forward from my Linux box to my MySql server on the Win2k machine.

I've checked that localhost resolves to 127.0.0.1. When adding the forward
using "localhost", netstat shows 127.0.0.1:3306 as listening. So is this an
SSH issue, or OS related. If it's not an SSH problem, I apologise.


I use 127.0.0.1 because some time in the past I experienced this same
problem where localhost was not reliable. I haven't seen the issue
resurface ever since.

Search and replace in 45 files, no problem:

mkdir /tmp/foo
cp *.php /tmp/foo
cd /tmp/foo
perl -pi -w -e 's/localhost/127\.0\.0\.1/g;' *.php


I didn't rigorously test this, so be sure you're working in the tmp
directory with a copy of your php code. :-)



--
Todd H.
http://www.toddh.net/
.



Relevant Pages

  • Re: puTTy: Coonection reset by peer
    ... I'm always getting a "connection reset by ... Your problem has nothing to do with "port 3306," or anything with your ... The difference is that the first is localhost access and the second is from ... because the code's user does not have a login via a remote host. ...
    (comp.security.ssh)
  • Re: MySQL/PHPMyAdmin on FC3 Connection Problem
    ... You say you opened the port 3306, ... that means that mysql is running and listening. ... If you had connection, then now try to access your mysql server from outside ... If you cannot connect on localhost, then please check that mysql is running ...
    (Fedora)
  • Re: ssh tunnel problems
    ... Connecting to localhost port 5000. ... debug1: connect to address 127.0.0.1 port 5000: Connection refused ... password and I connect and see files on my home computer (from being ...
    (Fedora)
  • Re: ssh tunnel problems
    ... Connecting to localhost port 5000. ... debug1: connect to address 127.0.0.1 port 5000: Connection refused ... password and I connect and see files on my home computer (from being ...
    (Fedora)
  • Re: C# Reflection - Nasty bug??
    ... Can you telnet into localhost to the port your server is running and get ... >>> This happens when LAN connection is present upon starting ...
    (microsoft.public.dotnet.languages.csharp)