Skip to contentSkip to conversation

query regarding hashlimit using ipset src,dst tuple

DISCUSSION Manish Jain 3 participants 4 messages Oct 15, 2006 – Oct 16, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

I have a requirement as follows -

Say there are 2 source IPs - src1 and src2, and 2 destination IP - dst1, dst2.
I need to limit src1->dst1 as well as src2-dst2 communication but want unlimited src2->dst1 communication.
I have a ipset KNOWN, which contains src1, src2, dst1, dst2

Now i write a rule as follows -
iptables -A INPUT_CHAIN --match hashlimit --hashlimit 1000/s --hashlimit-mode srcipdstip --hashlimit-name foo -m set --set KNOWN src,dst -j ACCEPT

But this will limit the src2->dst1 communication as well, which I dont want.

1. Is there a way to add ip1,ip2 as a tuple in a ipset the way we can do for ip1%port?
2. Is there a mode which can help me do this, using a single iptable rule as above?
3. Is there a way to specify multiple ipsets in 1 iptable rule?

Thanks & Regards
Manish Jain

#1 lore raw
Quoted 5 lines · Manish Jain

Say there are 2 source IPs - src1 and src2, and 2 destination IP - dst1, dst2.
I need to limit src1->dst1 as well as src2-dst2 communication but want unlimited src2->dst1 communication.
I have a ipset KNOWN, which contains src1, src2, dst1, dst2

What type of set is it?

Quoted 9 lines

Now i write a rule as follows -
iptables -A INPUT_CHAIN --match hashlimit --hashlimit 1000/s --hashlimit-mode srcipdstip --hashlimit-name foo -m set --set KNOWN src,dst -j ACCEPT

But this will limit the src2->dst1 communication as well, which I dont want.

1. Is there a way to add ip1,ip2 as a tuple in a ipset the way we can do for ip1%port?

No, such type of set currently does not exist.

Quoted 2 lines

2. Is there a mode which can help me do this, using a single iptable rule as above?

I don't think so.

Quoted 1 line

3. Is there a way to specify multiple ipsets in 1 iptable rule?

Yes, you can specify as many same kind maches as you want, but please keep in mind that the matches are AND-ed.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary
#2 lore raw

Hi Jozsef
Can you let us know the way to AND 2 ipsets, with an example. It will be really useful.

Thanks
Retesh Chadha

#3 lore raw
Quoted 2 lines · Retesh

Can you let us know the way to AND 2 ipsets, with an example. It will be really useful.

Let's assume a bunch of servers (the IP addresses stored in the set 'servers') and a bunch of clients (the IP addresses stored in 'clients') and one wants to allow any listed client to access any listed server:

iptables -A <chain> -m set --set clients src \
	            -m set --set servers dst \
		    -j ACCEPT

Or if you want to restrict the access to the given list of services on the servers (port numbers are stored in 'services'), assuming the same list of services on each server:

iptables -A <chain> -m set --set clients src \
	            -m set --set servers dst \
		    -m set --set services dst \
		    -j ACCEPT

Or if the list of services are different on the servers, then one can use an ipporthash type of set to store (server IP, service port) pairs in 'server-service' and write:

iptables -A <chain> -m set --set clients src \
	            -m set --set server-service dst,dst \
		    -j ACCEPT

Hope it helps,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary