NetFilter
[Top] [All Lists]

Re: port forwarding through localhost

To: netfilter@lists.netfilter.org
Subject: Re: port forwarding through localhost
From: Pascal Hambourg <pascal.mail@plouf.fr.eu.org>
Date: Fri, 26 Jan 2007 23:18:57 +0100
Delivered-to: sp-com-lists@consult.net
Delivered-to: netfilter-list1@securepoint.com
In-reply-to: <000001c74194$d484d9b0$0d01a8c0@Mobi>
List-archive: </pipermail/netfilter>
List-help: <mailto:netfilter-request@lists.netfilter.org?subject=help>
List-id: General discussion and user questions <netfilter.lists.netfilter.org>
List-post: <mailto:netfilter@lists.netfilter.org>
List-subscribe: <https://lists.netfilter.org/mailman/listinfo/netfilter>, <mailto:netfilter-request@lists.netfilter.org?subject=subscribe>
List-unsubscribe: <https://lists.netfilter.org/mailman/listinfo/netfilter>, <mailto:netfilter-request@lists.netfilter.org?subject=unsubscribe>
Organization: Plouf !
References: <000001c74194$d484d9b0$0d01a8c0@Mobi>
Sender: netfilter-bounces@lists.netfilter.org
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
Hello,

Andy B. a écrit :

Webserver that uses many many mySQL connections to 127.0.0.1 (Port 3306).

Now I would like to put the mySQL server onto a dedicated machine without
changing the "127.0.0.1" setting on a few hundred websites.

The new mySQL Server listens on 10.0.0.100:3306

My first guess was the following ruleset on the webserver:

iptables -t nat -A PREROUTING -p tcp -i lo --dport 3306 -j DNAT --to
10.0.0.100

Then I tried to telnet 127.0.0.1 3306, which failed immediately

Of course. Locally generated packets don't go into the PREROUTING chain.

I figured out the prerouting is no good for localhost and changed it into:

iptables -t nat -A OUTPUT -o lo -p tcp --dport 3306 -j DNAT --to
10.0.0.100:3306

telnet 127.0.0.1 3306 seems to do something, but not what I expected:

$ telnet 127.0.0.1 3333

Why 3333 ?

Trying 127.0.0.1...

<sleeping...... sleeping......>

Timeout eventually.

Does connecting directly to the SQL server work (no filtering rule that may block the connection) ? What is the kernel version ? Since 2.6.11, DNAT in the OUTPUT chain does not mangle the source address any more. But 127.0.0.1 is an invalid address for external communication and is rejected by the re-routing decision.


<Prev in Thread] Current Thread [Next in Thread>