0

I am trying to build a tunnel to then connect to an Oracle DB, but tunnel cannot be opened. Error is the following:

ERROR | Problem setting SSH Forwarder up: Couldn't open tunnel localhost:1521 <> XXXXXXXXX:1521 might be in use or destination not reachable.

sshtunnel.HandlerSSHTunnelForwarderError: An error occurred while opening tunnels.

My code is set as:

self.tunnel = sshtunnel.SSHTunnelForwarder((conn_data['gateway'], int(conn_data['gateway_port'])),
                                                   ssh_username=conn_data['username'],
                                                   ssh_password=password,
                                                   remote_bind_address=(conn_data['remote_bind'],
                                                                        int(conn_data['remote_port'])),
                                                   local_bind_address=(conn_data['local_bind'],
                                                                       int(conn_data['local_port'])))

The code works fine if I am inside the network of the company I work for. But if I am connected through VPN, I get the above error. My guess is that the VPN is built over the same tunnel.

I tried changing the local_port and removing the local bind, but if I do that, I get the error:

cx_Oracle.DatabaseError: ORA-12541: TNS:no listener

So, how can I dynamically set the port of SSHTunnelForwarder so it can access my DB through my already set VPN?

Note: changing the VPN's configuration or not using it is not an option.

1 Answer 1

1

Problem solved. The issue was that my VPN was using the same port as me (which caused the first error), and my Oracle connection was pointing to this port also (what caused error ORA-12541).

To solve it, I had to change conn_data['local_port'] to another port and set the port of my oracle connection to this same port:

self.tunnel = sshtunnel.SSHTunnelForwarder((conn_data['gateway'], 
                                                    int(conn_data['gateway_port'])),
                                                   ssh_username=conn_data['username'],
                                                   ssh_password=password,
                                                   remote_bind_address=(conn_data['remote_bind'], int(conn_data['remote_port'])),
                                                   local_bind_address=(conn_data['local_bind'], 1234))

self.connection.connect(conn_data['host'],
                            port=1234,
                            username=conn_data['username'],
                            password=password,
                            look_for_keys=False)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.