Skip to contentSkip to conversation

Howto match only the first connection from an IP

DISCUSSION Damjan 2 participants 3 messages Nov 18, 2003

lore
Share & tools
lore

Damjan

author
#0 lore raw

My goal is to set-up an iptables rule that will match and DNAT the first HTTP(port 80) connection from a client (IP address).

The first connection is defined as the first established TCP session from the time the iptables rule is inserted. No other TCP connection should match nor should be DNAT-ed.

Is there any easy way to do this with current Netfilter/Iptables/pom.

(I have installed almost all the patches from pom)

Signature · 2 lines
Damjan Georgievski
jabberID: [email protected]
#1 lore raw
Quoted 8 lines · Damjan

My goal is to set-up an iptables rule that will match and DNAT the first HTTP(port 80) connection from a client (IP address).

The first connection is defined as the first established TCP session from the time the iptables rule is inserted. No other TCP connection should match nor should be DNAT-ed.

Is there any easy way to do this with current Netfilter/Iptables/pom.

I can't think of a way to do this with netfilter on its own.

A slightly convoluted, although probably effective, way to do it might be to add one rule to LOG the packet you're interested in, and another rule just
after it to perform the NAT. You then pipe the output of syslog into a
script which watches out for the netfilter entry, and then issues a "netfilter -D ....." command to delete the NAT rule.

The only flaw I can see here (aside from the inefficiency) is that there will be a certain time delay between the first packet being seen and logged, and the NAT rule getting deleted by the script, during which time a packet could get through on a second connection.

Whether that's important to you, and how long the time period might be, I can't say.

It's an idea, anyway.

Antony.

Signature · 5 lines
Mahatma Gandhi was once asked what he thought of Western Civilisation.

He replied, "That would be a very good idea."
                                                     Please reply to the list;
                                                           please don't CC me.
author
#2 lore raw
Quoted 10 lines
Quoted 8 lines

My goal is to set-up an iptables rule that will match and DNAT the first HTTP(port 80) connection from a client (IP address).

The first connection is defined as the first established TCP session from the time the iptables rule is inserted. No other TCP connection should match nor should be DNAT-ed.

Is there any easy way to do this with current Netfilter/Iptables/pom.

I can't think of a way to do this with netfilter on its own.

Well I've come to this solution, but I wonder how reliable it is

iptables -t nat -p tcp --dport 80 -s 171.68.1.1 -m quota --quota 40 \
    -j REDIRECT --to-ports 9999

This seems to match only the first connection.

Any other ideas???

Signature · 2 lines
Damjan Georgievski
jabberID: [email protected]