netfilter.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vigneswaran R <vignesh@atc.tcs.com>
To: netfilter@vger.kernel.org
Subject: Re: Using source nat to discriminate traffic
Date: Wed, 27 Apr 2011 11:07:46 +0530	[thread overview]
Message-ID: <4DB7ABAA.4070604@atc.tcs.com> (raw)
In-Reply-To: <4DB6BDC3.1070306@gmail.com>

On 04/26/2011 06:12 PM, carlopmart wrote:
> Thanks Vignesh. Yes, your solution is perfectly and correct. But exists
> a problem: this hosts is included on a cluster (RHCS) with three nodes
> (in three weeks, will be six nodes). Service can run on a hostA, hostB
> or hostC ...

Ok. In that case I don't have any solutions using iptables. I can 
suggest the following two alternatives for your consideration.

1. Is there any application level change that you can make? You told 
already that you won't be able to upgrade mysql client for technical 
reasons. However, if the actual problem exists between the [web] 
services which require DB access and the MySQL server, you can look for 
options which allow us to specify the source IP while making the socket 
connection with MySQL server.

eg., if your website is using PHP to make connections to MySQL server, 
then the following code may help,

On website1,

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, '172.21.2.2');
socket_connect($sock, '172.17.3.3', 3306);
//code to access the BBDD_1

On website2,

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, '172.21.2.3');
socket_connect($sock, '172.17.3.3', 3306);
//code to access the BBDD_2

The above code snippet is only to give some idea and is neither complete 
nor tested. Similar code must be available for other web technologies too.

ref:
[1] 
<http://stackoverflow.com/questions/4765269/specify-source-ip-using-fsockopen>
[2] Example #1 in <http://in2.php.net/manual/en/function.socket-bind.php>

2. Another option would be using Virtual Machines (VMs). Run the 
services inside different VMs and migrate the VMs instead of services 
across hosts.

ref: 
<http://phparmor.com/php-source-code/how-can-i-bind-to-specific-ip-address-for-outbound-phpmysql-connection-linux/>

Note: Since my suggestions are not related to iptables, our discussion 
seems to be off topic for this list. If you have any other queries, 
please reply to me.

Regards,
Vignesh

      reply	other threads:[~2011-04-27  5:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-26  9:07 Using source nat to discriminate traffic carlopmart
2011-04-26  9:15 ` Jan Engelhardt
2011-04-26  9:45   ` carlopmart
2011-04-26 12:02 ` Vigneswaran R
2011-04-26 12:42   ` carlopmart
2011-04-27  5:37     ` Vigneswaran R [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DB7ABAA.4070604@atc.tcs.com \
    --to=vignesh@atc.tcs.com \
    --cc=netfilter@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).