Thread: Defining local IP address when opening connections to database

Defining local IP address when opening connections to database

From
Michael Bauland
Date:
Hi,

I've got a problem when using the PostgreSQL JDBC driver to open a
connection to a database (not using SSL). The server on which I'm using
the driver has several IPs configured, but I would like to use a certain
IP (since only for that IP the firewalls have been set-up to allow the
connection to the database). Looking at the documentation I couldn't
find a way to define this local IP.
Have I missed something? If not, would it be possible to add this
feature of defining the local IP when setting up a connection?

Cheers,

Michael

Re: Defining local IP address when opening connections to database

From
Dave Cramer
Date:
Michael,

The URL can take an ip address ie jdbc:postgresql://127.0.0.1/dbname

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca



On Wed, Mar 7, 2012 at 11:20 AM, Michael Bauland
<Michael.Bauland@knipp.de> wrote:
> Hi,
>
> I've got a problem when using the PostgreSQL JDBC driver to open a
> connection to a database (not using SSL). The server on which I'm using
> the driver has several IPs configured, but I would like to use a certain
> IP (since only for that IP the firewalls have been set-up to allow the
> connection to the database). Looking at the documentation I couldn't
> find a way to define this local IP.
> Have I missed something? If not, would it be possible to add this
> feature of defining the local IP when setting up a connection?
>
> Cheers,
>
> Michael
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc

Re: Defining local IP address when opening connections to database

From
"Kevin Grittner"
Date:
Michael Bauland <Michael.Bauland@knipp.de> wrote:

> I've got a problem when using the PostgreSQL JDBC driver to open a
> connection to a database (not using SSL). The server on which I'm
> using the driver has several IPs configured, but I would like to
> use a certain IP (since only for that IP the firewalls have been
> set-up to allow the connection to the database). Looking at the
> documentation I couldn't find a way to define this local IP.
> Have I missed something?

You probably either need to read this:

http://www.postgresql.org/docs/current/interactive/runtime-config-connection.html#RUNTIME-CONFIG-CONNECTION-SETTINGS

or this:

http://jdbc.postgresql.org/documentation/head/connect.html

-Kevin

Re: Defining local IP address when opening connections to database

From
"David Johnston"
Date:
> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-
> owner@postgresql.org] On Behalf Of Michael Bauland
> Sent: Wednesday, March 07, 2012 11:20 AM
> To: pgsql-jdbc@postgresql.org
> Subject: [JDBC] Defining local IP address when opening connections to
> database
>
> Hi,
>
> I've got a problem when using the PostgreSQL JDBC driver to open a
> connection to a database (not using SSL). The server on which I'm using
the
> driver has several IPs configured, but I would like to use a certain IP
(since
> only for that IP the firewalls have been set-up to allow the connection to
the
> database). Looking at the documentation I couldn't find a way to define
this
> local IP.
> Have I missed something? If not, would it be possible to add this feature
of
> defining the local IP when setting up a connection?
>
> Cheers,
>
> Michael

Are you missing the obvious, in which case read Kevin's and Dave's
responses, or do you mean that on the "client" machine (i.e., the one using
JDBC) you have multiple network adapters and only one of them is allowed to
connect to the database?

If the latter is the case I am not sure about JDBC but I would presume you
could setup some form of routing table on your machine so that any traffic
to the server IP address is forced to be routed through the appropriate
network card.

David J.




Re: Defining local IP address when opening connections to database

From
Michael Bauland
Date:
Hi David,

thanks for your quick reply.


> Are you missing the obvious, in which case read Kevin's and Dave's
> responses, or do you mean that on the "client" machine (i.e., the one using
> JDBC) you have multiple network adapters and only one of them is allowed to
> connect to the database?
>
> If the latter is the case I am not sure about JDBC but I would presume you
> could setup some form of routing table on your machine so that any traffic
> to the server IP address is forced to be routed through the appropriate
> network card.

yes, I was referring to the latter. I have a client machine which as
several network adapters, but I would like to always have the connection
to the database using exactly one of the IPs available to my client. I
couldn't find a way to specify this IP.

Yes, the routing table might be one solution. But in my case we're
actually having two services running on the client, and both connect to
the same database. And both services should use a different IP. In which
case the routing table won't help. There doesn't seem to be a way of
doing this with JDBC, is there? Since on
http://jdbc.postgresql.org/documentation/head/connect.html
there are a few connection parameters, but none that lets me set my
local IP for the connection.

Cheers,

Michael

Re: Defining local IP address when opening connections to database

From
Scott Harrington
Date:
On Wed, 7 Mar 2012, Michael Bauland wrote:

> I've got a problem when using the PostgreSQL JDBC driver to open a
> connection to a database (not using SSL). The server on which I'm using
> the driver has several IPs configured, but I would like to use a certain
> IP (since only for that IP the firewalls have been set-up to allow the
> connection to the database). Looking at the documentation I couldn't
> find a way to define this local IP.
> Have I missed something? If not, would it be possible to add this
> feature of defining the local IP when setting up a connection?

You haven't missed anything. I had the same requirement a while ago and
needed to patch (see attached) my local build to bind to a localAddress
specified in the JDBC properties.

I find it useful to bind to a particular local address not only for
routing but also simply to improve the connection logs.

Hope this helps.

Attachment

Re: Defining local IP address when opening connections to database

From
John R Pierce
Date:
On 03/07/12 9:04 AM, Michael Bauland wrote:
> yes, I was referring to the latter. I have a client machine which as
> several network adapters, but I would like to always have the connection
> to the database using exactly one of the IPs available to my client. I
> couldn't find a way to specify this IP.
>
> Yes, the routing table might be one solution. But in my case we're
> actually having two services running on the client, and both connect to
> the same database. And both services should use a different IP. In which
> case the routing table won't help. There doesn't seem to be a way of
> doing this with JDBC, is there? Since on
> http://jdbc.postgresql.org/documentation/head/connect.html
> there are a few connection parameters, but none that lets me set my
> local IP for the connection.

what is the point of multiple network adapters connecting to the same
network other than MPIO style ethernet link bonding (whereupon the
physical adapters would appear as a single logical ethernet endpoint)

IP networks route by destination address.  if there's multiple paths to
the same destination that are all the same 'length', the decision as to
which path to use is completely arbitrary.   putting different firewall
rules on different interfaces that are all on the same subnet will just
cause some VERY hard to debug problems.



--
john r pierce                            N 37, W 122
santa cruz ca                         mid-left coast