java - Can I specify *source* IP address for a JDBC connection? -


i have java application connects database jdbc driver. happens postgres instance, i'm looking general solution if exist.

the server on application runs has multiple ip address, in same subnet. jdbc connection established using 'primary' ip of server.

i can play linux networking stack have outgoing connections database use secondary ip address.

is there way programatically specify source ip address used to jdbc connection?


context: want move application without touching database, has rules restricting ip address accept connections from.

the hack see making ssl connection, , return new socket bound secondary ip custom sslsocketfactory.

some googling suggests depends on particular jdbc driver.

for mysql, it's done via property on url:

jdbc:mysql://localhost:3306/sakila?localsocketaddress=123.33.33.33 

(see https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html)

in case of postgres, looks best option socketfactory url property - create plain old sockets, not ssl sockets.

(see https://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters)


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -