PgSQL behind a firewall

Started by nmiletover 24 years ago4 messagesgeneral
Jump to latest
#1nmilet
nmilet@sympatico.ca

Hi all,

How can I connect to a remote database that is protected by a firewall. I`m
using Java and JDBC.
I try to sep up a SSL connection but didn't succeed.
Thanks!

Nico

#2Holger Klawitter
lists@klawitter.de
In reply to: nmilet (#1)
Re: PgSQL behind a firewall

Nicolas Milet wrote:

Hi all,

How can I connect to a remote database that is protected by a firewall. I`m
using Java and JDBC.
I try to sep up a SSL connection but didn't succeed.

You can open the port in the firewall (note that the world may acces your DB
now)
or use a ssh tunnel.

With kind regards / Mit freundlichem Gru�
Holger Klawitter
--
Holger Klawitter
holger@klawitter.de http://www.klawitter.de

#3nmilet
nmilet@sympatico.ca
In reply to: nmilet (#1)
Re: PgSQL behind a firewall

The question now is how can I set a ssh tunnel (I try to recompile postgres
with openssl support
but I did not succeed), and then can I use a ssh tunnel from Java (perharps
yes by specifying the
port number in connection).

Thanks for idea.

Nicolas
"Le savant montre la lune, l'imbecile regarde le doigt"

----- Original Message -----
From: "Holger Klawitter" <lists@klawitter.de>
To: "Nicolas Milet" <nmilet@sympatico.ca>; <pgsql-general@postgreSQL.org>
Sent: Friday, September 28, 2001 3:47 AM
Subject: Re: [GENERAL] PgSQL behind a firewall

Nicolas Milet wrote:

Hi all,

How can I connect to a remote database that is protected by a firewall.

I`m

using Java and JDBC.
I try to sep up a SSL connection but didn't succeed.

You can open the port in the firewall (note that the world may acces your

DB

Show quoted text

now)
or use a ssh tunnel.

With kind regards / Mit freundlichem Gru�
Holger Klawitter
--
Holger Klawitter
holger@klawitter.de http://www.klawitter.de

#4Holger Klawitter
lists@klawitter.de
In reply to: nmilet (#1)
Re: PgSQL behind a firewall

nmilet wrote:

The question now is how can I set a ssh tunnel (I try to recompile postgres
with openssl support
but I did not succeed), and then can I use a ssh tunnel from Java (perharps
yes by specifying the
port number in connection).

That's not difficult:

1.) Establish a ssh connecton from the client formwaarding to the
dbhost (port is the port number on the local host being forwarded):
ssh -L port:dbhost:5432 dbhost
or (as I regularly do)
ssh -2 -n -N -L port:dbhost:5432 dbhost
You'll probably have to set up some identities to make this
work conveniently.

2.) Then you can connect to the remote database by using
db = DriverManager.getConnection
( "jdbc:postgresql://localhost:"+port+"/"+dbname, user, pass );
Where post is the local port and dbname is the (remove) database
name.

With kind regards / Mit freundlichem Gru�
Holger Klawitter
--
Holger Klawitter
holger@klawitter.de http://www.klawitter.de