How to select the source ip address for a connection to the

How to select the source ip address for a connection to the

am 02.09.2009 19:23:18 von dimitris.sakellarios

This message is in MIME format.

--=_4s20ksne6uio
Content-Type: text/plain;
charset=ISO-8859-7;
DelSp="Yes";
format="flowed"
Content-Description: =?iso-8859-7?b?zojOus60zr/Pg863IA==?=
=?iso-8859-7?b?zrzOt869z43OvM6xz4TOv8+CIA==?= =?iso-8859-7?b?zrzOtSA=?=
=?iso-8859-7?b?zrrOsc64zrHPgc+MIA==?= =?iso-8859-7?b?zrrOtc6vzrzOtc69zr8=?=
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable



Hi,

I am currently=A0working with PHP5+PGSQL 8.2.13 and i have the =20
following problem to solve and i need your help.

The server hosting PHP+psql=A0client=A0has 1 physical network =20
interfaces with multiple=A0subinterfaces using different IPs.

One of those IP=A0is dedicated to my domain, but it is not servers =20
default IP address since i share the server.

So the problem that i need to solve is how am i going to be able to =20
use-select my domains IP address as source=A0to connect to the remote =20
databases.

Is there any configuration to settle default source IP the client will us=
e?

At the moment all my attempts to connect to the database=A0make use =20
of=A0servers default interface IP as source.

Thanks in advance for your help.

--=_4s20ksne6uio
Content-Type: text/html;
charset=ISO-8859-7
Content-Description: HTML =?utf-8?b?zpXOus60zr/Pg863IA==?=
=?utf-8?b?z4TOv8+FIA==?= =?utf-8?b?zrzOt869zq7OvM6xz4TOv8+C?=
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

size=3D"2">Hi,

"> size=3D"2">I am currently=A0working with PHP5+PGSQL =
8.2.13 and
i have the following problem to solve and i need your
help.

The server hosti=
ng
PHP+psql=A0client=A0has 1 physical network interfaces with multiple=A0subint=
erfaces
using different IPs.

One of t=
hose
IP=A0is dedicated to my domain, but it is not servers default IP address sin=
ce i
share the server.

So the prob=
lem that
i need to solve is how am i going to be able to use-select my domains IP add=
ress
as source=A0to connect to the remote databases.

erdana"
size=3D"2">Is there any configuration to settle default source IP the client=
will
use?

At the moment all my att=
empts to
connect to the database=A0make use of=A0servers default interface IP as
source.

Thanks in advance for=
your
help.


--=_4s20ksne6uio--

Re: How to select the source ip address for a connection tothe database server

am 03.09.2009 13:31:28 von Andrew McMillan

--=-d52JdGZSU2ifas0uBnRf
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Wed, 2009-09-02 at 20:23 +0300, dimitris.sakellarios@telesuite.gr
wrote:
> Hi,
>=20
> I am currently working with PHP5+PGSQL 8.2.13 and i have the following
> problem to solve and i need your help.
>=20
> The server hosting PHP+psql client has 1 physical network interfaces
> with multiple subinterfaces using different IPs.
>=20
> One of those IP is dedicated to my domain, but it is not servers
> default IP address since i share the server.
>=20
> So the problem that i need to solve is how am i going to be able to
> use-select my domains IP address as source to connect to the remote
> databases.
>=20
> Is there any configuration to settle default source IP the client will
> use?
>=20
> At the moment all my attempts to connect to the database make use of
> servers default interface IP as source.

Nope, unless you're root you're unlikely to be able to choose the source
address for your connection, and even then it would be tricky.

You probably need to either live with the fact that the people you share
your hosting with might also be able to connect to your database, so if
you are paranoid you might want to make sure it is an SSL connection,
and protect it with a reasonable password.

Or you could shell out some more money for a non-shared server, and then
perhaps you might not need to have the database remote in the first
place.

Cheers,
Andrew McMillan.

------------------------------------------------------------ ------------
http://andrew.mcmillan.net.nz/ Porirua, New Zealand
Twitter: _karora Phone: +64(272)DEBIAN
Beware of Bigfoot!
------------------------------------------------------------ ------------


--=-d52JdGZSU2ifas0uBnRf
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkqfqQ0ACgkQjJA0f48GgBJmtQCglEnkXcrgU1Wpt2Bgfy18 E0bi
tLUAoKMSVBN0R1idOjrj47bi24zscyIL
=y5Ba
-----END PGP SIGNATURE-----

--=-d52JdGZSU2ifas0uBnRf--

Re: How to select the source ip address for a connection to the

am 03.09.2009 14:51:16 von Greg Stark

On Thu, Sep 3, 2009 at 12:31 PM, Andrew McMillan wrote:
> Nope, unless you're root you're unlikely to be able to choose the source
> address for your connection, and even then it would be tricky.

I don't think you need to be root to select a source address. But
that's not helpful since libpq doesn't support binding to a particular
interface. That would be a useful feature and we should probably add
it to the TODO.

You should note that the source address isn't actually a very secure
way to protect your connections since any other host on that network
could spoof your address.

It sounds like what you're looking for is to control the interface the
packets are routed through. This is separate from the source address
as packets are often routed through multiple hosts along their way.
Routing rules are not something individual applications normally get
involved in. If the connections are being routed through the wrong
interface then you have a global problem, not just with the database
and it requires system-wide configuration changes.

--
greg
http://mit.edu/~gsstark/resume.pdf

--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Re: How to select the source ip address for a connection to the database server

am 04.09.2009 12:21:20 von dimitris.sakellarios

Greg and Anrew thanks for your concern on the issue.

Indeed selecting the source interface - ip would be a great option since for
me (but many other) trying to connect to a secure postgresql server over
internet is must accompanied with username + password + ssl but it is one
more L3 criteria.

And also I feel sure that my application will run whatever the server admin
changes.

Pls let me know if any modification in libpq code could help to bind address
or interface alias temporary.

DS
-----Original Message-----
From: gsstark@gmail.com [mailto:gsstark@gmail.com] On Behalf Of Greg Stark
Sent: Thursday, September 03, 2009 3:51 PM
To: Andrew McMillan
Cc: dimitris.sakellarios@telesuite.gr; pgsql-php@postgresql.org
Subject: Re: How to select the source ip address for a connection to the
database server

On Thu, Sep 3, 2009 at 12:31 PM, Andrew McMillan wrote:
> Nope, unless you're root you're unlikely to be able to choose the source
> address for your connection, and even then it would be tricky.

I don't think you need to be root to select a source address. But
that's not helpful since libpq doesn't support binding to a particular
interface. That would be a useful feature and we should probably add
it to the TODO.

You should note that the source address isn't actually a very secure
way to protect your connections since any other host on that network
could spoof your address.

It sounds like what you're looking for is to control the interface the
packets are routed through. This is separate from the source address
as packets are often routed through multiple hosts along their way.
Routing rules are not something individual applications normally get
involved in. If the connections are being routed through the wrong
interface then you have a global problem, not just with the database
and it requires system-wide configuration changes.

--
greg
http://mit.edu/~gsstark/resume.pdf

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4393 (20090904) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4394 (20090904) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Re: How to select the source ip address for a connection tothe database server

am 06.09.2009 02:57:56 von Bob McConnell

dimitris.sakellarios@telesuite.gr wrote:
>
> I am currently working with PHP5+PGSQL 8.2.13 and i have the following
> problem to solve and i need your help.
>
> The server hosting PHP+psql client has 1 physical network interfaces
> with multiple subinterfaces using different IPs.
>
> One of those IP is dedicated to my domain, but it is not servers
> default IP address since i share the server.
>
> So the problem that i need to solve is how am i going to be able to
> use-select my domains IP address as source to connect to the remote
> databases.
>
> Is there any configuration to settle default source IP the client will
> use?
>
> At the moment all my attempts to connect to the database make use
> of servers default interface IP as source.
>
> Thanks in advance for your help.

That is the way sockets normally work, the primary address is always
used for outgoing connections. It can not be changed without some low
level programming. It is necessary to bind the socket to the specific IP
address before opening the connection. I have done it with Perl, but not
PHP.

Bob McConnell
N2SPP

--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Re: How to select the source ip address for a connection to the database server

am 06.09.2009 15:13:26 von dimitris.sakellarios

Bob hi I would be very interested in giving me some small hint of how you
did that in PERL so I can start from someplace in PHP.

BR.

-----Original Message-----
From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org]
On Behalf Of Bob McConnell
Sent: Sunday, September 06, 2009 3:58 AM
To: dimitris.sakellarios@telesuite.gr
Cc: pgsql-php@postgresql.org
Subject: Re: [PHP] How to select the source ip address for a connection to
the database server

dimitris.sakellarios@telesuite.gr wrote:
>
> I am currently working with PHP5+PGSQL 8.2.13 and i have the following
> problem to solve and i need your help.
>
> The server hosting PHP+psql client has 1 physical network interfaces
> with multiple subinterfaces using different IPs.
>
> One of those IP is dedicated to my domain, but it is not servers
> default IP address since i share the server.
>
> So the problem that i need to solve is how am i going to be able to
> use-select my domains IP address as source to connect to the remote
> databases.
>
> Is there any configuration to settle default source IP the client will
> use?
>
> At the moment all my attempts to connect to the database make use
> of servers default interface IP as source.
>
> Thanks in advance for your help.

That is the way sockets normally work, the primary address is always
used for outgoing connections. It can not be changed without some low
level programming. It is necessary to bind the socket to the specific IP
address before opening the connection. I have done it with Perl, but not
PHP.

Bob McConnell
N2SPP

--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4398 (20090905) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4398 (20090905) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Re: How to select the source ip address for a connection tothe database server

am 06.09.2009 21:35:32 von Bob McConnell

Dimitris Sakellarios wrote:
> Bob hi I would be very interested in giving me some small hint of how you
> did that in PERL so I can start from someplace in PHP.
>
> BR.

Well, stripping it down to the basics, here is what I used:

-------------8<------------------------------
$port = 23 unless $port;
$them = 'localhost' unless $them;
$AF_INET = 2;
$SOCK_STREAM = 1;

$sockaddr = 'S n a4 x8';

($name,$aliases,$proto) = getprotobyname('tcp');
($name,$aliases,$port) = getservbyname($port,'tcp')
unless $port =~ /^\d+$/;;
($name,$aliases,$type,$len,$thisaddr) =
gethostbyname($hostname);
($name,$aliases,$type,$len,$thataddr) = gethostbyname($them);

$this = pack($sockaddr, $AF_INET, 0, $thisaddr);
$that = pack($sockaddr, $AF_INET, $port, $thataddr);

if (socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
print "socket ok\n";
}
else {
die $!;
}

if (bind(S, $this)) {
print "bind ok\n";
}
else {
die $!;
}

if (connect(S,$that)) {
print "connect ok\n";
}
else {
die $!;
}
-------------8<------------------------------

The key is the variable $thisaddr. Put your server's DNS name or IP
address as the parameter for the 'gethostbyname($hostname)' call that
initializes it. That binds the outgoing connection to your IP. In my
test platform I use "gethostbyname('10.3.1.70')", which binds it
directly to one of the three network cards in that computer. The rest is
pretty normal for a socket definition.

But as I said, this is pretty low level. It doesn't use any of the
socket libraries or classes most people favor for Perl coding these
days. If you need more ideas, I located this code again today doing a
Google search on "Perl socket bind connect".

Good luck,

Bob McConnell
N2SPP

--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Re: How to select the source ip address for a connection to thedatabase server

am 07.09.2009 12:40:21 von Jasen Betts

On 2009-09-02, dimitris.sakellarios@telesuite.gr wrote:
>
> Hi,
>
> I am currently=A0working with PHP5+PGSQL 8.2.13 and i have the =20
> following problem to solve and i need your help.
>
> The server hosting PHP+psql=A0client=A0has 1 physical network =20
> interfaces with multiple=A0subinterfaces using different IPs.
>
> One of those IP=A0is dedicated to my domain, but it is not servers =20
> default IP address since i share the server.
>
> So the problem that i need to solve is how am i going to be able to =20
> use-select my domains IP address as source=A0to connect to the remote =20
> databases.
>
> Is there any configuration to settle default source IP the client will us=
> e?
>
> At the moment all my attempts to connect to the database=A0make use =20
> of=A0servers default interface IP as source.
>
> Thanks in advance for your help.

easiest way it probably by setting a routing rule, you need
root/adimnistrator to do this.


--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Re: How to select the source ip address for a connection to the

am 07.09.2009 12:49:42 von Jasen Betts

On 2009-09-06, Dimitris Sakellarios wrote:
>
> That is the way sockets normally work, the primary address is always
> used for outgoing connections. It can not be changed without some low
> level programming. It is necessary to bind the socket to the specific IP
> address before opening the connection. I have done it with Perl, but not
> PHP.
>
> Bob McConnell
> N2SPP
>

basically what you need to do is take the libpq source extend the
conneection-string facility to include
bind-to-port and bind-to-address parameters which bind the outgoing
connection to the named resources and then recompile it and get it
installed on your server

no changes are likely to be needed to PHP




--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php