Skip to contentSkip to conversation

NAT & MySQL

DISCUSSION adburne 3 participants 7 messages Nov 25, 2003 – Nov 27, 2003

lore
Share & tools
lore

adburne

author
#0 lore raw

Someone can make NAT with mysql? I've tried for a long time without make it work.

My natural language is spanish, sorry by mistakes writing in english.

This is the situation:

I've have a linux box as gateway between my lan and internet routing paquets without problems, I need access from internet another linux box running apache and mysql on my private lan.
To do this work I try to use nat; with apache all works ok, but with mysql can't connect. I'll be looking on different network devices using tcpdump to find what's wrong.

This is what tcpdump show on device eth0 on my mysql server (inside the lan)
there is a petition from 200.10.10.1 (internet client) to 192.168.0.80
(mysql lan server), this reply with ack, but internet client don't reply. Any clue? =)

200.10.10.1.56405 > 192.168.0.80.3306: S 2205542765:2205542765(0) win 5840 <mss
1412,sackOK,timestamp 620645629 0,nop,wscale 0> (DF) 192.168.0.80.3306 > 200.10.10.1.56405: S 2497023396:2497023396(0) ack 2205542766
win 5792 <mss 1460,sackOK,timestamp 95764658 620645629,nop,wscale 0> (DF)
200.10.10.1.56405 > 192.168.0.80.3306: R 2205542766:2205542766(0) win 0 (DF) 200.10.10.1.56405 > 192.168.0.80.3306: S 2205542765:2205542765(0) win 5840 <mss
1412,sackOK,timestamp 620648701 0,nop,wscale 0> (DF) 192.168.0.80.3306 > 200.10.10.1.56405: S 2503023731:2503023731(0) ack 2205542766
win 5792 <mss 1460,sackOK,timestamp 95765258 620648701,nop,wscale 0> (DF)
200.10.10.1.56405 > 192.168.0.80.3306: R 2205542766:2205542766(0) win 0 (DF)

The forward rules on the gateway are:

# "Accept forward all connections to port 3306 on ppp0" iptables -A FORWARD -p tcp -i ppp0 --dport 3306 -o eth0 -j ACCEPT # "All stablished connections are ok"
iptables -A FORWARD -i ppp0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# "All connection from inside to outside are accepted"
iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT
# "Rest go away"
iptables -A FORWARD -j REJECT

NAT rule:
iptables -t nat -A PREROUTING -p tcp -i ppp0 --dport 3306 -j DNAT --to 192 168.0.80 -s 200.10.10.1

If someone can make the light turn on, thanks!!!!

Alejandro

#1 lore raw
Quoted 11 lines · adburne

The forward rules on the gateway are:

# "Accept forward all connections to port 3306 on ppp0"
iptables -A FORWARD -p tcp -i ppp0 --dport 3306 -o eth0 -j ACCEPT
# "All stablished connections are ok"
iptables -A FORWARD -i ppp0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT # "All connection from inside to outside are accepted"
iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT
# "Rest go away"
iptables -A FORWARD -j REJECT

Quoted 3 lines

NAT rule:
iptables -t nat -A PREROUTING -p tcp -i ppp0 --dport 3306 -j DNAT --to 192.168.0.80 -s 200.10.10.1

Are you using MASQUERADE or SNAT ? If you aren't then the outside can't 'see' your internal server.

Jeff

#2 lore raw
In reply to adburne

The ACK packets you see in your dump are probably being dropped at the firewall because a state table entry does not exist. So you need to add a NEW rule to do this:

iptables -A FORWARD -i ppp0 -o eth0 -m state --state NEW -j ACCEPT

this rule will then allow your ESTABLISHED,RELATED rule to work and permit those ACK packets to pass.

_____

From: [email protected] [mailto:[email protected]] On Behalf Of adburne
Sent: Tuesday, November 25, 2003 4:18 AM
To: [email protected]
Subject: NAT & MySQL

Someone can make NAT with mysql? I've tried for a long time without make it work.

My natural language is spanish, sorry by mistakes writing in english.

This is the situation:

I've have a linux box as gateway between my lan and internet routing paquets without problems, I need access from internet another linux box running apache and mysql on my private lan.
To do this work I try to use nat; with apache all works ok, but with mysql can't connect. I'll be looking on different network devices using tcpdump to find what's wrong.

This is what tcpdump show on device eth0 on my mysql server (inside the lan), there is a petition from 200.10.10.1 (internet client) to 192.168.0.80 (mysql lan server), this reply with ack, but internet client don't reply. Any clue? =)

200.10.10.1.56405 > 192.168.0.80.3306: S 2205542765:2205542765(0) win 5840 <mss
1412,sackOK,timestamp 620645629 0,nop,wscale 0> (DF) 192.168.0.80.3306 > 200.10.10.1.56405: S 2497023396:2497023396(0) ack 2205542766
win 5792 <mss 1460,sackOK,timestamp 95764658 620645629,nop,wscale 0> (DF)
200.10.10.1.56405 > 192.168.0.80.3306: R 2205542766:2205542766(0) win 0 (DF) 200.10.10.1.56405 > 192.168.0.80.3306: S 2205542765:2205542765(0) win 5840 <mss
1412,sackOK,timestamp 620648701 0,nop,wscale 0> (DF) 192.168.0.80.3306 > 200.10.10.1.56405: S 2503023731:2503023731(0) ack 2205542766
win 5792 <mss 1460,sackOK,timestamp 95765258 620648701,nop,wscale 0> (DF)
200.10.10.1.56405 > 192.168.0.80.3306: R 2205542766:2205542766(0) win 0 (DF)

The forward rules on the gateway are:

# "Accept forward all connections to port 3306 on ppp0" iptables -A FORWARD -p tcp -i ppp0 --dport 3306 -o eth0 -j ACCEPT # "All stablished connections are ok"
iptables -A FORWARD -i ppp0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# "All connection from inside to outside are accepted"
iptables -A FORWARD -i eth0 -o ppp0 -j ACCEPT
# "Rest go away"
iptables -A FORWARD -j REJECT

NAT rule:
iptables -t nat -A PREROUTING -p tcp -i ppp0 --dport 3306 -j DNAT --to 192.168.0.80 -s 200.10.10.1

If someone can make the light turn on, thanks!!!!

Alejandro

_________________________________________________________________
<http://www.incredimail.com/redir.asp?ad_id=310&lang=10> IncrediMail - El
E-mail ha evolucionado finalmente -
<http://www.incredimail.com/redir.asp?ad_id=310&lang=10> Haga clic aquí

#3 lore raw
Quoted 7 lines · Mark E. Donaldson

The ACK packets you see in your dump are probably being dropped at the firewall because a state table entry does not exist. So you need to add a NEW rule to do this:

iptables -A FORWARD -i ppp0 -o eth0 -m state --state NEW -j ACCEPT

this rule will then allow your ESTABLISHED,RELATED rule to work and permit those ACK packets to pass.

Hi Mark,

I'm not sure I understand what this rule does for him. Only the first packet from the web client would be NEW and based on his FORWARD rules that's been accepted and the dump shows it went through (although I'd still like to see his SNAT rule). Your rule would open his mysql server to any NEW packet. Are you saying that the RELATED ACK packets won't go through unless the first packet is matched with a NEW state and makes an entry in the state table?

Jeff

#4 lore raw

Yeah you are correct Jeff. Don't know what I was thinking. Maybe that's the
problem: I wasn't.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jeffrey Laramie
Sent: Tuesday, November 25, 2003 1:25 PM
To: [email protected]
Subject: Re: NAT & MySQL

Quoted 10 lines · Mark E. Donaldson

The ACK packets you see in your dump are probably being dropped at the firewall because a state table entry does not exist. So you need to add a NEW rule to do this:

iptables -A FORWARD -i ppp0 -o eth0 -m state --state NEW -j ACCEPT

this rule will then allow your ESTABLISHED,RELATED rule to work and permit those ACK packets to pass.

Hi Mark,

I'm not sure I understand what this rule does for him. Only the first packet from the web client would be NEW and based on his FORWARD rules that's been accepted and the dump shows it went through (although I'd still like to see his SNAT rule). Your rule would open his mysql server to any NEW packet. Are you saying that the RELATED ACK packets won't go through unless the first packet is matched with a NEW state and makes an entry in the state table?

Jeff

#5 lore raw

Mark E. Donaldson wrote:
Yeah you are correct Jeff. Don't know what I was thinking. Maybe that's the problem: I wasn't.
No worries. This is a tough list to answer on (just ask Antony). One needs to understand inet protocols, the inner workings of netfilter, network design, and a whole bunch of unforgiving iptables rules. And that's before you get to POM and the bleeding edge stuff! This is why I only answer the easy questions ;-)

Anyway, the original post said that the web server worked fine yet there aren't any rules that would allow that. If you're still following the thread, can you post all your rules and maybe a schematic of your LAN so we can see where the servers are?

Jeff

author
#6 lore raw

How ever, thanks; I'll be found the reason that didn't work DNAT.

Don't punch me =)

I set up, time ago, another gateway box on my mysql server (I've 2 links to internet), it runs rh7.1 and network setup was setting using linuxconf. I setup it correctly, but don't take changes.
It show incorrect information about gateway ip, when I saw this because I think in it, all was ok (in theory).

Thanks, and sorry for waste your time (and my too) with this problem.

Alejandro.

-------Mensaje original-------

De: Jeffrey Laramie
Fecha: miércoles 26 de noviembre de 2003 00:51:40
A: [email protected]
Asunto: Re: NAT & MySQL

Mark E. Donaldson wrote:

Yeah you are correct Jeff. Don't know what I was thinking. Maybe that's the
problem: I wasn't.

No worries. This is a tough list to answer on (just ask Antony). One needs to understand inet protocols, the inner workings of netfilter, network design, and a whole bunch of unforgiving iptables rules. And that's before you get to POM and the bleeding edge stuff! This is why I only answer the easy questions ;-)

Anyway, the original post said that the web server worked fine yet there aren't any rules that would allow that. If you're still following the thread
can you post all your rules and maybe a schematic of your LAN so we can see
where the servers are?

Jeff