Skip to contentSkip to conversation

dnat problem in transparent firewall

DISCUSSION Raido Kurel 2 participants 5 messages Aug 4, 2004

lore
Share & tools
lore
#0 lore raw

Sorry, about not beeing in the thread. I just subscribed and can see message just in archive...

Quoted 3 lines
Quoted 3 lines

Needs:
To change destination IP of some packets coming from Internet. ie to change destination IP from aaa.aaa.aaa.12 to aaa.aaa.aaa.13

...

Quoted 5 lines
Quoted 2 lines

iptables -t nat -A PREROUTING -d aaa.aaa.aaa.12 -j DNAT --to-dest aaa.aaa.aaa.13

Do you have a FORWARD rule allowing packets through to aaa.aaa.aaa.13 after they've been NATted?

Yes.
Also packets from Internet to aaa.aaa.aaa.13 reach destination.
I am more worried about fact, that
-t nat -A PREROUTING -j DNAT ...
and then
-t nat -A PREROUTING -j LOG ...
does not log anything. Without the first rule logging works.
I thought, that -j DNAT should pass packet for next nat PREROUTING rule for logging. According to http://ebtables.sourceforge.net/br_fw_ia/PacketFlow.png
packet should next go to ebtables filter table input or forward chains, but nothing reaches there in case of the iptables -t nat -A PREROUTING -j DNAT rule.

Raido

#1 lore raw
Quoted 10 lines · Raido Kurel
Quoted 2 lines

Do you have a FORWARD rule allowing packets through to aaa.aaa.aaa.13 after they've been NATted?

Yes.
Also packets from Internet to aaa.aaa.aaa.13 reach destination. I am more worried about fact, that
-t nat -A PREROUTING -j DNAT ...
and then
-t nat -A PREROUTING -j LOG ...
does not log anything. Without the first rule logging works.

That's because the DNAT target does not return to the chain. The LOG target
is almost the only target I can think of which *does* return back to the chain for further processing - all other targets are the "final outcome" for the packet.

Put the two rules the other way round and you'll get both LOGging and DNATting.

Regards,

Antony.

Signature · 6 lines
Most people are aware that the Universe is big.

 - Paul Davies, Professor of Theoretical Physics

                                                     Please reply to the list;
                                                           please don't CC me.
#2 lore raw
Quoted 7 lines

That's because the DNAT target does not return to the chain. The LOG
target is almost the only target I can think of which *does* return back to the chain for further processing - all other targets are the "final outcome" for the packet.

Put the two rules the other way round and you'll get both LOGging and DNATting.

Thanks, I have been missed that. Now I can ask my question in other words:

I presume, that http://ebtables.sourceforge.net/br_fw_ia/PacketFlow.png is correct.

According to this picture, my packets should flow in lowest path. To be sure it is so, I have made rules to log incoming packet in 3 points:
a)iptables nat table prerouting chain
b)ebtables filter table forward chain
c)iptables mangle table forward chain
d)ebtables filter table input chain

I try to connect fron Internet to aaa.aaa.aaa.12

In case of rule:
iptables -t nat -A PREROUTING -d aaa.aaa.aaa.12 -j DNAT --to-dest aaa.aaa.aaa.13

I see packet only in point a)

In case of no rule or rule
iptables -t nat -A PREROUTING -d aaa.aaa.aaa.12 -j DNAT --to-dest aaa.aaa.aaa.12

I see packet in a), b) and c) points.

I see also packet in a), b) and c) points if I connect from internet to aaa.aaa.aaa.13

It's just like DNAT rule drops packet, but it can't be, because DNAT to the same address works fine. I know I have missed something important, but what could it be?

Raido

#3 lore raw
Quoted 32 lines · Raido Kurel
Quoted 7 lines

That's because the DNAT target does not return to the chain. The LOG
target is almost the only target I can think of which *does* return back to the chain for further processing - all other targets are the "final outcome" for the packet.

Put the two rules the other way round and you'll get both LOGging and DNATting.

Thanks, I have been missed that. Now I can ask my question in other words:

I presume, that http://ebtables.sourceforge.net/br_fw_ia/PacketFlow.png is correct.

According to this picture, my packets should flow in lowest path. To be sure it is so, I have made rules to log incoming packet in 3 points:
a)iptables nat table prerouting chain
b)ebtables filter table forward chain
c)iptables mangle table forward chain
d)ebtables filter table input chain

I try to connect fron Internet to aaa.aaa.aaa.12

In case of rule:
iptables -t nat -A PREROUTING -d aaa.aaa.aaa.12 -j DNAT --to-dest aaa.aaa.aaa.13

I see packet only in point a)

In case of no rule or rule
iptables -t nat -A PREROUTING -d aaa.aaa.aaa.12 -j DNAT --to-dest aaa.aaa.aaa.12

Quoted 8 lines

I see packet in a), b) and c) points.

I see also packet in a), b) and c) points if I connect from internet to aaa.aaa.aaa.13

It's just like DNAT rule drops packet, but it can't be, because DNAT to the same address works fine. I know I have missed something important, but what could it be?

What do your LOGging rules say? Is it possible that you are trying to LOG
packets addressed to aaa.aaa.aaa.12, and therefore the rules no longer see the packets once the address has been changed to aaa.aaa.aaa.13?

Regards,

Antony.

Signature · 7 lines
I don't know, maybe if we all waited then cosmic rays would write all our 
software for us. Of course it might take a while.

 - Ron Minnich, Los Alamos National Laboratory

                                                     Please reply to the list;
                                                           please don't CC me.
#4 lore raw
Quoted 4 lines

What do your LOGging rules say? Is it possible that you are trying to LOG
packets addressed to aaa.aaa.aaa.12, and therefore the rules no longer see the packets once the address has been changed to aaa.aaa.aaa.13?

That's a good point. I checket it also over several times.
Thats why I also tested and wrote, that I see packets if I try to connect to aaa.aaa.aaa.13

I added 2 logging rules for every logging point from a) to d). For example exact logging rules for a) are :
iptables -t nat -A PREROUTING -s nnn.nnn.nnn.nnn -d aaa.aaa.aaa.12 -j LOG --log-prefix " ipt nat pre "
iptables -t nat -A PREROUTING -s nnn.nnn.nnn.nnn -d aaa.aaa.aaa.13 -j LOG --log-prefix " ipt nat pre "

where nnn.nnn.nnn.nnn is a computer from where I connect behind other ISP.

It should not be relevant, but the port I try to connect for testing right now is ssh. I try to connect with telnet aaa.aaa.aaa.12 22.
both .12 and .13 have ssh servers up and running.

Raido