Skip to contentSkip to conversation

How to use DNAT

DISCUSSION Steven Kath 5 participants 5 messages Feb 17, 2011 – Feb 19, 2011 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

----- "Italo Valcy" <[email protected]> wrote: -----

Quoted 7 lines
Quoted 2 lines

Please provide some details about the rule, packets... Note that iptables' NAT ignores packets in the INVALID state.

Well... so could be this: INVALID state... The packets are about a netflow traffic (9996/UDP) comming to the firewall, which should be redirected to a internal host (through the DNAT). How can I debug these possible INVALID packets?

iptables -I FORWARD -p udp -m udp --dport 9996 -m state --state INVALID -j LOG --log-prefix "INVALID-FWD: " iptables -I INPUT -p udp -m udp --dport 9996 -m state --state INVALID -j LOG --log-prefix "INVALID-IN: "

This will allow you to see matching traffic through the filter table's FORWARD and INPUT chains with the invalid state in dmesg.

Also, bear in mind that the nat table is only consulted for packets with state NEW. If your UDP flow state transitions to ESTABLISHED before your NAT rule is created, the new rule will not be applied to that flow.

You'd need to clear that connection from the table with conntrack-tools, flush the entire table, or let the connection expire from the table for it to be considered NEW again and compared against the nat rules.

#2 lore raw
Quoted 7 lines · Steven Kath

----- "Italo Valcy" <[email protected]> wrote: -----

Quoted 5 lines

Well... so could be this: INVALID state... The packets are about a netflow traffic (9996/UDP) comming to the firewall, which should be redirected to a internal host (through the DNAT). How can I debug these possible INVALID packets?

Quoted 5 lines

iptables -I FORWARD -p udp -m udp --dport 9996 -m state --state INVALID -j LOG --log-prefix "INVALID-FWD: " iptables -I INPUT -p udp -m udp --dport 9996 -m state --state INVALID -j LOG --log-prefix "INVALID-IN: "

This will allow you to see matching traffic through the filter table's FORWARD and INPUT chains with the invalid state in dmesg.

AFAIK, UDP packets cannot be INVALID.

Quoted 4 lines

Also, bear in mind that the nat table is only consulted for packets with state NEW. If your UDP flow state transitions to ESTABLISHED before your NAT rule is created, the new rule will not be applied to that flow.

Actually it is even stricter : the nat rules are consulted only for the first packet of a new flow ("connection"). The next packets skip the nat rules even when the flow does not transition to ESTABLISHED (when there is no packet in the reply direction).

Quoted 4 lines

You'd need to clear that connection from the table with conntrack-tools, flush the entire table, or let the connection expire from the table for it to be considered NEW again and compared against the nat rules.

#3 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi guys,

Em 17-02-2011 20:41, Pascal Hambourg escreveu:

Quoted 9 lines
Quoted 4 lines

Also, bear in mind that the nat table is only consulted for packets with state NEW. If your UDP flow state transitions to ESTABLISHED before your NAT rule is created, the new rule will not be applied to that flow.

Actually it is even stricter : the nat rules are consulted only for the first packet of a new flow ("connection"). The next packets skip the nat rules even when the flow does not transition to ESTABLISHED (when there is no packet in the reply direction).

Yes, you are correct, but I didn't understand this behaviour. I managed to get the netflow traffic working again by stoping the netflow device, wainting about one minute and starting again. Almost sure its the exact explanation above. But, why this behavior???

I think this problem starts happening when I restart the iptables rules and the traffic keeps going. Maybe in that moment, the packets does not pass to NAT table anymore. How can I fix it? Do you have any ideias guys? I'm using the rules generated by fwbuilder to start/restart the firewall.

Thanks again for the help!

- --
Saudações,

Italo Valcy :: http://wiki.dcc.ufba.br/~ItaloValcy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1eaxIACgkQfidLqjN6RNHpQACgm6ISsVBVByr5PSRT8LSu1WRA zwUAn1+VtJAxR42LfYS+aVHrTOXMQKbc
=9O4a
-----END PGP SIGNATURE-----

#4 lore raw

Den 18. feb. 2011 kl. 13.50 skrev Italo Valcy <[email protected]>:

Quoted 21 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi guys,

Em 17-02-2011 20:41, Pascal Hambourg escreveu:

Quoted 9 lines
Quoted 4 lines

Also, bear in mind that the nat table is only consulted for packets with state NEW. If your UDP flow state transitions to ESTABLISHED before your NAT rule is created, the new rule will not be applied to that flow.

Actually it is even stricter : the nat rules are consulted only for the first packet of a new flow ("connection"). The next packets skip the nat rules even when the flow does not transition to ESTABLISHED (when there is no packet in the reply direction).

Yes, you are correct, but I didn't understand this behaviour. I managed to get the netflow traffic working again by stoping the netflow device, wainting about one minute and starting again. Almost sure its the exact explanation above. But, why this behavior???

Quoted 6 lines

I think this problem starts happening when I restart the iptables rules and the traffic keeps going. Maybe in that moment, the packets does not pass to NAT table anymore. How can I fix it? Do you have any ideias guys? I'm using the rules generated by fwbuilder to start/restart the firewall.

You flush the conntrack table.

# conntrack -F

Atle.

#5 lore raw

(sorry for top posting; Gmail mobile client can only reply by top posting)

If I flush the conntrack table, would the next packet be considered NEW?

Because AFAIK the nat table is checked only for NEW packets.

(That would also mean overly-secure rules like -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP must be deleted, or temporarily disabled)

Rgds,

Quoted 51 lines · Atle Solbakken

Den 18. feb. 2011 kl. 13.50 skrev Italo Valcy <[email protected]>:

Quoted 27 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi guys,

Em 17-02-2011 20:41, Pascal Hambourg escreveu:

Quoted 5 lines
Quoted 4 lines

Also, bear in mind that the nat table is only consulted for packets with state NEW. If your UDP flow state transitions to ESTABLISHED before your NAT rule is created, the new rule will not be applied to that flow.

Quoted 7 lines

Actually it is even stricter : the nat rules are consulted only for the
first packet of a new flow ("connection"). The next packets skip the nat
rules even when the flow does not transition to ESTABLISHED (when there
is no packet in the reply direction).

Yes, you are correct, but I didn't understand this behaviour. I managed
to get the netflow traffic working again by stoping the netflow device,
wainting about one minute and starting again. Almost sure its the exact
explanation above. But, why this behavior???

Quoted 8 lines

I think this problem starts happening when I restart the iptables rules
and the traffic keeps going. Maybe in that moment, the packets does not
pass to NAT table anymore. How can I fix it? Do you have any ideias guys? I'm using the rules generated by fwbuilder to start/restart the firewall.

You flush the conntrack table.

# conntrack -F

Atle.
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
--
Pandu E Poluan - IT Optimizer
My website: http://pandu.poluan.info/