5

I have two servers. Server 1 has access to an Oracle instance on a server I have permission to hit but not login to via SSH. I would like to use SSH port forwarding to connect from server 2 to server 1 and from there to the Oracle instance. I have set GatewayPorts=yes and AllowTcpForwarding=yes but I still feel like something is wrong.

For the purposes of this question, I would like to focus simply on connecting to a postgres instance on server 1 (port 5432) from server 2 port forward from 16951.

After running:

ssh -L 16951:localhost:5432 server1 -nNT -f -g

from server 2, I can see "localhost.16951" after running netstat to check open ports which leads me to believe that the port is listening successfully.

When I run:

psql -U jbarton -p 16951

I get a message saying that there is no listening port localhost:16951

    psql: could not connect to server: No such file or directory
     Is the server running locally and accepting
     connections on Unix domain socket "/tmp/.s.PGSQL.16951"?

Any comments, answers or suggestions are greatly appreciated.

Update

When I now try this with oracle, connect using: ./sqlplus W_USER/password@//localhost:16951/dbname, I get this error: ERROR: ORA-12537: TNS:connection closed

My oracle ora files look like this:

`#tnsnames.ora
PROD2 =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 16951))
      (CONNECT_DATA =
         (SERVER = DEDICATED)
         (SERVICE_NAME = prod2)
      )
    )

And the sqlnet.ora

'# sqlnet.ora Network Configuration File Generated by Oracle configuration tools.

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
NAMES.LOG_DIRECTORY = /var/oracle/network/log
5

If you do not specify the hostname psql assumes domain socket connections. As per the man page:

If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to localhost on machines that don't have Unix-domain sockets.

Try adding -h localhost to the psql command line.

As to the Oracle error, I would guess because of the following (oracle is much harder to diagnose):

The ORA-12537 error sometimes relates configuration issues in the sqlnet.ora, protocol.ora and listener.ora files.  Verify that you service names match between your listener and remote client connect strings.

So your connect string including localhost is being rejected by oracle.

update

If that is a local tnsnames.ora, have you tried sqlplus W_USER@PROD2 instead? (it will prompt for a password if required). You may have to set the environment variable TNS_ADMIN to the location of where tnsnames.ora resides.

  • That worked, so now that the proof of concept is in place, why doesn't this same process work with oracle? I connect using: ./sqlplus W_USER/password@//localhost:16951/dbname I get this error: ERROR: ORA-12537: TNS:connection closed – Josh Barton Aug 5 '15 at 19:14
  • Updated my answer in relation to the Oracle error. – Drav Sloan Aug 5 '15 at 21:34
  • Updated my question with my ora files, as far as I can tell they are the same as the ora files on my working system (other than the change to localhost:16951) – Josh Barton Aug 6 '15 at 17:07
  • I did have the $TNS_ADMIN var set and attempted sqlplus W_USER@PROD2 but I got the same no listener error – Josh Barton Aug 6 '15 at 21:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.