Skip to contentSkip to conversation

DNATing packets sent to the NATing box

DISCUSSION [email protected] 3 participants 9 messages Dec 14, 2003 1 message not in the archive

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines
Quoted 2 lines

Yes, and I've added a rule like this:
/sbin/iptables -t nat -A PREROUTING -j LOG and don't see the packets.

Ummmm
if you ADD the rule above after the rule that is re-routing the packet,
no ... you wont see the packets. Try
iptables -t nat -I PREROUTING (line number)
where (line number) is less than the line on which your DNAT line occurrs. (see iptables -t nat --line-numbers -v )

I'm really replacing the DNAT rule with the LOG one (only rule in the chain is the LOG one)

Saludos,
HoraPe
---
Horacio J. Peña
[email protected]
[email protected]

#1 lore raw
Quoted 10 lines · On Sunday 14 December 2003 08:52, [email protected] wrote:
Quoted 9 lines
Quoted 2 lines

Yes, and I've added a rule like this:
/sbin/iptables -t nat -A PREROUTING -j LOG and don't see the packets.

Ummmm
if you ADD the rule above after the rule that is re-routing the
packet, no ... you wont see the packets. Try
iptables -t nat -I PREROUTING (line number)
where (line number) is less than the line on which your DNAT line
occurrs. (see iptables -t nat --line-numbers -v )

Quoted 3 lines

I'm really replacing the DNAT rule with the LOG one (only rule in the chain is the LOG one)

If there are no other rules in the nat PREROUTING chain and assuming that you don't have and mangle PREROUTING rules (you don't, do you?) then that log rule will see every single packet that comes in off the wire. Try this:

iptables -A PREROUTING -p all -j LOG --log-prefix "PREROUTING: "

You should see tons output in /var/log/messages including the packets you're looking for. If the packets aren't there, then they aren't making it to the box.

Jeff

#3 lore raw
In reply to a message not in the archive
Quoted 8 lines
Quoted 2 lines

I'm really replacing the DNAT rule with the LOG one (only rule in the chain is the LOG one)

If there are no other rules in the nat PREROUTING chain and assuming that you don't have and mangle PREROUTING rules (you don't, do you?) then that log rule will see every single packet that comes in off the wire. Try this:

iptables -A PREROUTING -p all -j LOG --log-prefix "PREROUTING: "

I do:

iptables -t nat -A PREROUTING -p udp -j LOG --log-prefix "PREROUTING: " iptables -t filter -A INPUT -p udp -j LOG --log-prefix "INPUT: "

(I'm logged in that box via ssh, so I prefer not to do -p all)

There are no more rules than these ones.

In the log I see the INPUT ones but not the PREROUTING (only see on PREROUTING packets to port 137, maybe some worm...)

Quoted 3 lines

You should see tons output in /var/log/messages including the packets you're looking for. If the packets aren't there, then they aren't making it to the box.

But the packets got to the INPUT rule, that should be after PREROUTING. And got to my socket.

Quoted 1 line

Jeff

Saludos,
HoraPe
---
Horacio J. Peña
[email protected]
[email protected]

#4 lore raw
Quoted 15 lines · On Sunday 14 December 2003 10:26, [email protected] wrote:
Quoted 9 lines
Quoted 2 lines

I'm really replacing the DNAT rule with the LOG one (only rule in the chain is the LOG one)

If there are no other rules in the nat PREROUTING chain and assuming that you don't have and mangle PREROUTING rules (you don't, do you?) then that log rule will see every single packet that comes in off the wire. Try this:

iptables -A PREROUTING -p all -j LOG --log-prefix "PREROUTING: "

I do:

iptables -t nat -A PREROUTING -p udp -j LOG --log-prefix "PREROUTING: " iptables -t filter -A INPUT -p udp -j LOG --log-prefix "INPUT: "

Quoted 7 lines

(I'm logged in that box via ssh, so I prefer not to do -p all)

There are no more rules than these ones.

In the log I see the INPUT ones but not the PREROUTING (only see on PREROUTING packets to port 137, maybe some worm...)

That's very strange. You said in your first post that you had a udp proxy running. Is it on this box? I'm not sure at what level a proxy hooks into the box, but I know that some programs read the data stream before netfilter sees it. If the proxy is in front of netfilter then netfilter would never see those packets. The port 137 packets are prolly just internet garbage.

Quoted 7 lines
Quoted 3 lines

You should see tons output in /var/log/messages including the packets you're looking for. If the packets aren't there, then they aren't making it to the box.

But the packets got to the INPUT rule, that should be after PREROUTING. And got to my socket.

Can you show these log entries? I don't even know how that could happen. Maybe someone else has some ideas.

Jeff

#5 lore raw
Quoted 9 lines
Quoted 8 lines

I do:

iptables -t nat -A PREROUTING -p udp -j LOG --log-prefix "PREROUTING: " iptables -t filter -A INPUT -p udp -j LOG --log-prefix "INPUT: "

(I'm logged in that box via ssh, so I prefer not to do -p all)

There are no more rules than these ones.

Quoted 7 lines
Quoted 2 lines

In the log I see the INPUT ones but not the PREROUTING (only see on PREROUTING packets to port 137, maybe some worm...)

That's very strange. You said in your first post that you had a udp proxy running. Is it on this box? I'm not sure at what level a proxy hooks into the box, but I know that some programs read the data stream before netfilter sees it. If the proxy is in front of netfilter then netfilter would never see those packets. The port 137 packets are prolly just internet garbage.

The proxy has a udp socket bound to port 5000, and another udp socket bound to some other port, it reads from the first socket and does a sendto using the other socket (poll + read + write, no more)

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

You should see tons output in /var/log/messages including the packets you're looking for. If the packets aren't there, then they aren't making it to the box.

But the packets got to the INPUT rule, that should be after PREROUTING. And got to my socket.

Can you show these log entries? I don't even know how that could happen. Maybe someone else has some ideas.

Dec 14 15:57:22 ivrip kernel: INPUT: IN=eth0 OUT= MAC=00:0a:e6:fa:c6:09:00:09:12:2b:5e:fd:08:00 SRC
=200.61.169.146 DST=200.68.94.100 LEN=60 TOS=0x00 PREC=0xA0 TTL=251 ID=17815 PROTO=UDP SPT=17314 DP
T=5000 LEN=40
Dec 14 15:57:23 ivrip last message repeated 47 times
Dec 14 15:57:23 ivrip kernel: INPUT: IN=eth0 OUT= MAC=00:0a:e6:fa:c6:09:00:09:12:2b:5e:fd:08:00 SRC

=200.61.169.146 DST=200.68.94.100 LEN=41 TOS=0x00 PREC=0xA0 TTL=251 ID=17855 PROTO=UDP SPT=17314 DP T=5000 LEN=21

Lots of those. Only very sporadic, non related PREROUTING ones, like:

Dec 14 15:57:58 ivrip kernel: PREROUTING: IN=eth0 OUT= MAC=00:0a:e6:fa:c6:09:00:09:12:2b:5e:fd:08:0

0 SRC=217.126.141.13 DST=200.68.94.100 LEN=78 TOS=0x00 PREC=0x00 TTL=108 ID=31313 PROTO=UDP SPT=566 66 DPT=137 LEN=58

iptables-save says:

# Generated by iptables-save v1.2.9 on Sun Dec 14 15:59:05 2003 *nat
:PREROUTING ACCEPT [1474:107026]
:POSTROUTING ACCEPT [19:2376]
:OUTPUT ACCEPT [19:2376]
-A PREROUTING -p udp -j LOG --log-prefix "PREROUTING: " COMMIT
# Completed on Sun Dec 14 15:59:05 2003
# Generated by iptables-save v1.2.9 on Sun Dec 14 15:59:05 2003 *filter
:INPUT ACCEPT [28639:3847013]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [26167:3457193]
-A INPUT -p udp -j LOG --log-prefix "INPUT: "
COMMIT
# Completed on Sun Dec 14 15:59:05 2003

(Note that filter INPUT saw 28639 packets and PREROUTING just 1474 since last boot)

Quoted 1 line

Jeff

Saludos,
HoraPe
---
Horacio J. Peña
[email protected]
[email protected]

#6 lore raw
Quoted 19 lines · On Sunday 14 December 2003 11:04, [email protected] wrote:
Quoted 12 lines
Quoted 11 lines

I do:

iptables -t nat -A PREROUTING -p udp -j LOG --log-prefix "PREROUTING: " iptables -t filter -A INPUT -p udp -j LOG --log-prefix "INPUT: "

(I'm logged in that box via ssh, so I prefer not to do -p all)

There are no more rules than these ones.

In the log I see the INPUT ones but not the PREROUTING (only see on PREROUTING packets to port 137, maybe some worm...)

Quoted 6 lines

That's very strange. You said in your first post that you had a udp proxy running. Is it on this box? I'm not sure at what level a proxy hooks into the box, but I know that some programs read the data stream before netfilter sees it. If the proxy is in front of netfilter then netfilter would never see those packets. The port 137 packets are prolly just internet garbage.

Quoted 4 lines

The proxy has a udp socket bound to port 5000, and another udp socket bound to some other port, it reads from the first socket and does a sendto using the other socket (poll + read + write, no more)

It looks like the proxy is grabbing the packets first and then dropping them directly onto the INPUT chain. Try disabling the proxy and release the bound ports then try it again. Once the packets reach PREROUTING you can DNAT them to another port.

Jeff

#7 lore raw
Quoted 10 lines · Jeffrey Laramie
Quoted 3 lines · On Sunday 14 December 2003 11:04, [email protected] wrote:

The proxy has a udp socket bound to port 5000, and another udp socket bound to some other port, it reads from the first socket and does a sendto using the other socket (poll + read + write, no more)

It looks like the proxy is grabbing the packets first and then dropping them directly onto the INPUT chain. Try disabling the proxy and release the bound ports then try it again. Once the packets reach PREROUTING you can DNAT them to another port.

I could ubnderstand the proxy code managing to grab the packet off the wire before netfilter (PREROUTING) sees it, but I don't see how it would then get seen by the INPUT chain - as far as I know, it's not possible for a packet to reach netfilter's INPUT chain without first going through the PREROUTING
chain. If a packet bypasses one of these, it will bypass both.

However, the idea of disabling the proxy, and then seeing if the LOG rules show anything different, is a good one.

How is the proxy connected to the socket? Anything unusual?

Antony

Signature · 6 lines
Having been asked for a reference for this man,
I can confirm that you will be very lucky indeed if you can get him to work 
for you.

                                                     Please reply to the list;
                                                           please don't CC me.
#8 lore raw
Quoted 11 lines · Antony Stone
Quoted 9 lines · Jeffrey Laramie
Quoted 3 lines · On Sunday 14 December 2003 11:04, [email protected] wrote:

The proxy has a udp socket bound to port 5000, and another udp socket bound to some other port, it reads from the first socket and does a sendto using the other socket (poll + read + write, no more)

It looks like the proxy is grabbing the packets first and then dropping them directly onto the INPUT chain. Try disabling the proxy and release the bound ports then try it again. Once the packets reach PREROUTING you can DNAT them to another port.

Quoted 5 lines

I could ubnderstand the proxy code managing to grab the packet off the wire before netfilter (PREROUTING) sees it, but I don't see how it would then get seen by the INPUT chain - as far as I know, it's not possible for a packet to reach netfilter's INPUT chain without first going through the
PREROUTING chain. If a packet bypasses one of these, it will bypass both.

Well that's what I thought but I can't explain his results any other way. What are we missing here?

Jeff

#9 lore raw
In reply to Antony Stone
Quoted 10 lines
Quoted 4 lines

It looks like the proxy is grabbing the packets first and then dropping them directly onto the INPUT chain. Try disabling the proxy and release the bound ports then try it again. Once the packets reach PREROUTING you can DNAT them to another port.

I could ubnderstand the proxy code managing to grab the packet off the wire before netfilter (PREROUTING) sees it, but I don't see how it would then get seen by the INPUT chain - as far as I know, it's not possible for a packet to reach netfilter's INPUT chain without first going through the PREROUTING
chain. If a packet bypasses one of these, it will bypass both.

Quoted 4 lines

However, the idea of disabling the proxy, and then seeing if the LOG rules show anything different, is a good one.

How is the proxy connected to the socket? Anything unusual?

The proxy is just a normal udp socket. (socket, bind, poll, recvfrom...)

What I'm doing is an IVR over H.323, the program receives and send rtp packets until a conference is made, when the conference is made it starts working as a proxy (ie, it gets the packet with a recvfrom and sends by other socket with sendto) Nothing strange there.

Quoted 1 line

Antony

Saludos,
HoraPe
---
Horacio J. Peña
[email protected]
[email protected]