Skip to contentSkip to conversation

DNAT-Problem

DISCUSSION Tom Fischer 3 participants 8 messages Sep 9, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

i have a problem with DNAT. We have to move some services for a few days on another machine. So we want do DNAT on incoming Packets. I set

iptables -A PREROUTING -t nat -s 0/0 -d xxx.xxx.xxx.xxx -p tcp --dport 9000-j DNAT --to xxx.xxx.xxx.xxx

Should be enough on this box in my opinion. So i can see the Packet incoming on the old machine, and i can see the Packet with my Source IP and the new destination IP, but i think the packet never leaves the old machine. tcpdump looks like this

[root@server4 mysql]# tcpdump -n port 9000
tcpdump: listening on eth0
04:02:04.746105 217.232.189.4.65423 > oldmachine.9000: S 740515023:740515023(0) win 5840 <mss 1452,sackOK,timestamp 66069311 0,nop,wscale 7> (DF) [tos 0x70]
04:02:04.746151 217.232.189.4.65423 > newmachine.70.9000: S 740515023:740515023(0) win 5840 <mss 1452,sackOK,timestamp 66069311 0,nop,wscale 7> (DF) [tos 0x70]
04:02:07.744772 217.232.189.4.65423 > oldmachine.9000: S 740515023:740515023(0) win 5840 <mss 1452,sackOK,timestamp 66072311 0,nop,wscale 7> (DF) [tos 0x70]
04:02:07.744806 217.232.189.4.65423 > newmachine.9000: S 740515023:740515023(0) win 5840 <mss 1452,sackOK,timestamp 66072311 0,nop,wscale 7> (DF) [tos 0x70]

The packet never arivves on the new machine. What am I missing?

Kernel is 2.4.27, the box seems to be Fedora Core 2 and iptables is Version 1.2.7a.

Anybody can help me out?

Tom

#1 lore raw
Quoted 7 lines · Tom Fischer

Hi,

i have a problem with DNAT. We have to move some services for a few days on another machine. So we want do DNAT on incoming Packets. I set

iptables -A PREROUTING -t nat -s 0/0 -d xxx.xxx.xxx.xxx -p tcp --dport 9000-j DNAT --to xxx.xxx.xxx.xxx

since you didn't provide your rules, i'm gonna haveta ask a really stupid question...

did you execute that command with the old DNAT rule in place? if so--the new rule got appended to the end of the PREROUTING chain of the nat table, after the old rule; therefore, will never get matched.

it would be helpful for us list-types to see the output of:

iptables -t nat -vnL

another thought--NAT happens first (PREROUTING), then filter rules. you will need to edit your filter rule to allow traffic to "newserver's" actual IP instead of "oldserver's" actual IP.

-j

Signature · 1 line
Jason Opperisano <[email protected]>
#7 lore raw
In reply to Tom Fischer

Are you sure that you are not dropping the packet in another table/chain. Perhaps do something like

watch -n 1 iptables -L -n -v

so that you can see the packet count when you test to see if the packet rule is being accepted or dropped somewhere.

Abdul-Wahid

Quoted 38 lines · Tom Fischer

Hi,

i have a problem with DNAT. We have to move some services for a few days on another machine. So we want do DNAT on incoming Packets. I set

iptables -A PREROUTING -t nat -s 0/0 -d xxx.xxx.xxx.xxx -p tcp --dport 9000-j DNAT --to xxx.xxx.xxx.xxx

Should be enough on this box in my opinion. So i can see the Packet incoming on the old machine, and i can see the Packet with my Source IP and the new destination IP, but i think the packet never leaves the old machine. tcpdump looks like this

[root@server4 mysql]# tcpdump -n port 9000
tcpdump: listening on eth0
04:02:04.746105 217.232.189.4.65423 > oldmachine.9000: S 740515023:740515023(0) win 5840 <mss 1452,sackOK,timestamp 66069311 0,nop,wscale 7> (DF) [tos 0x70]
04:02:04.746151 217.232.189.4.65423 > newmachine.70.9000: S 740515023:740515023(0) win 5840 <mss 1452,sackOK,timestamp 66069311 0,nop,wscale 7> (DF) [tos 0x70]
04:02:07.744772 217.232.189.4.65423 > oldmachine.9000: S 740515023:740515023(0) win 5840 <mss 1452,sackOK,timestamp 66072311 0,nop,wscale 7> (DF) [tos 0x70]
04:02:07.744806 217.232.189.4.65423 > newmachine.9000: S 740515023:740515023(0) win 5840 <mss 1452,sackOK,timestamp 66072311 0,nop,wscale 7> (DF) [tos 0x70]

The packet never arivves on the new machine. What am I missing?

Kernel is 2.4.27, the box seems to be Fedora Core 2 and iptables is Version 1.2.7a.

Anybody can help me out?

Tom

#2 lore raw
In reply to Jason Opperisano
Quoted 13 lines · On Wed, 08 Sep 2004 22:26:44 -0400 Jason Opperisano <[email protected]> wrote:
Quoted 8 lines · Tom Fischer

Hi,

i have a problem with DNAT. We have to move some services for a few days on another machine. So we want do DNAT on incoming Packets. I set

iptables -A PREROUTING -t nat -s 0/0 -d xxx.xxx.xxx.xxx -p tcp --dport 9000-j DNAT --to xxx.xxx.xxx.xxx

since you didn't provide your rules, i'm gonna haveta ask a really stupid question...

Quoted 7 lines

did you execute that command with the old DNAT rule in place? if so--the new rule got appended to the end of the PREROUTING chain of the nat table, after the old rule; therefore, will never get matched.

it would be helpful for us list-types to see the output of:

iptables -t nat -vnL

This is the only rule.

[root@server4 root]# iptables -t nat -vnL
Chain PREROUTING (policy ACCEPT 645K packets, 35M bytes)
pkts bytes target prot opt in out source
destination 2 120 DNAT tcp -- * *
0.0.0.0/0 oldmachine tcp dpt:9000 to:newmachine

Chain POSTROUTING (policy ACCEPT 62473 packets, 3966K bytes)
pkts bytes target prot opt in out source
destination

Chain OUTPUT (policy ACCEPT 62441 packets, 3964K bytes)
pkts bytes target prot opt in out source
destination

Quoted 5 lines

another thought--NAT happens first (PREROUTING), then filter rules. you will need to edit your filter rule to allow traffic to "newserver's" actual IP instead of "oldserver's" actual IP.

There are no Filterrules installed at the moment.

Tom

#3 lore raw
Quoted 17 lines · Tom Fischer

This is the only rule.

[root@server4 root]# iptables -t nat -vnL
Chain PREROUTING (policy ACCEPT 645K packets, 35M bytes)
pkts bytes target prot opt in out source
destination 2 120 DNAT tcp -- * *
0.0.0.0/0 oldmachine tcp dpt:9000 to:newmachine

Chain POSTROUTING (policy ACCEPT 62473 packets, 3966K bytes)
pkts bytes target prot opt in out source
destination

Chain OUTPUT (policy ACCEPT 62441 packets, 3964K bytes)
pkts bytes target prot opt in out source
destination

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

another thought--NAT happens first (PREROUTING), then filter rules. you will need to edit your filter rule to allow traffic to "newserver's" actual IP instead of "oldserver's" actual IP.

There are no Filterrules installed at the moment.

Tom

what are the IP addresses of $oldmachine and $newmachine (obfuscate the first two octets if you must)?

are you trying to DNAT from one machine on the local network to another machine on the local network? what network is the client traffic sourcing from? is it the same network?

-j

Signature · 1 line
Jason Opperisano <[email protected]>
#4 lore raw
Quoted 2 lines · On Thu, 09 Sep 2004 07:38:26 -0400 Jason Opperisano <[email protected]> wrote:

what are the IP addresses of $oldmachine and $newmachine (obfuscate the first two octets if you must)?

$oldmachine=81.16.97
$newmachine=80.190.140

There are a few IP-Adresse which i have to transfer to the newmachine.

Quoted 3 lines

are you trying to DNAT from one machine on the local network to another machine on the local network? what network is the client traffic sourcing from? is it the same network?

No, they are on different locations. The old one is in Innsbruck, Austria and the new one in Munich, Germany.

Tom

#5 lore raw
Quoted 9 lines · Tom Fischer
Quoted 2 lines · On Thu, 09 Sep 2004 07:38:26 -0400 Jason Opperisano <[email protected]> wrote:

what are the IP addresses of $oldmachine and $newmachine (obfuscate the first two octets if you must)?

$oldmachine=81.16.97
$newmachine=80.190.140

Quoted 8 lines

There are a few IP-Adresse which i have to transfer to the newmachine.

Quoted 3 lines

are you trying to DNAT from one machine on the local network to another machine on the local network? what network is the client traffic sourcing from? is it the same network?

No, they are on different locations. The old one is in Innsbruck, Austria and the new one in Munich, Germany.

for what it's worth--it sounds like your problem has much more to do with routing than with iptables firewalling.

i think i may have misunderstood your original post. are you running iptables and the DNAT rule on $oldmachine? if so, unless the reply packets from $newmachine are routed back through $oldmachine; this setup won't work (for what should be painfully obvious reasons).

if your DNAT rule is on a gateway machine upstream from both $oldmachine and $newmachine--i'd say you have a routing failure somewhere in the chain.

-j

Signature · 1 line
Jason Opperisano <[email protected]>
#6 lore raw
Quoted 20 lines · On Thu, 09 Sep 2004 09:26:54 -0400 Jason Opperisano <[email protected]> wrote:
Quoted 12 lines · Tom Fischer
Quoted 2 lines · On Thu, 09 Sep 2004 07:38:26 -0400 Jason Opperisano <[email protected]> wrote:

what are the IP addresses of $oldmachine and $newmachine (obfuscate the first two octets if you must)?

$oldmachine=81.16.97
$newmachine=80.190.140

There are a few IP-Adresse which i have to transfer to the newmachine.

Quoted 6 lines
Quoted 3 lines

are you trying to DNAT from one machine on the local network to another machine on the local network? what network is the client traffic sourcing from? is it the same network?

No, they are on different locations. The old one is in Innsbruck, Austria and the new one in Munich, Germany.

Quoted 7 lines

for what it's worth--it sounds like your problem has much more to do with routing than with iptables firewalling.

i think i may have misunderstood your original post. are you running iptables and the DNAT rule on $oldmachine? if so, unless the reply packets from $newmachine are routed back through $oldmachine; this setup won't work (for what should be painfully obvious reasons).

Ok, i see the Problem. Is it possible to mark this packet and route it based on the mark? I think i build a similar setup few weeks ago where i have to route and nat packets which came in on eone vpn and should go out on the other vpn.

Quoted 3 lines

if your DNAT rule is on a gateway machine upstream from both $oldmachine and $newmachine--i'd say you have a routing failure somewhere in the chain.

No, unfortunately it is not. I will try to mark the packets.

Thx for help

Tom