Skip to contentSkip to conversation

iptables/ipset syntax

DISCUSSION Arthur Titeica 3 participants 4 messages Jan 20, 2011 – Jan 21, 2011

lore
Share & tools
lore
#0 lore raw

Hello

I'm having some trouble understanding the correct syntax for an iptables rule involving ipset.

I need to forward between IPs within the same ipset. So I've tried using something like this:

iptables -A FORWARD -i eth0 -o eth0 -m set --match-set testset src,dst -p tcp --dport 9000:9020 -j ACCEPT

However this allows forwarding to all the eth0 network for the 'testset' IPs.

Instead
iptables -A FORWARD -i eth0 -o eth0 -m set --match-set testset src -m set --match-set testset dst -p tcp --dport 9000:9020 -j ACCEPT seems to do what I need but I'm not 100% certain.

Anyone with a better understanding?

iptables v1.4.10
ipset v5.3.

Thank you.

Signature · 1 line
Arthur Titeica
#1 lore raw

20.01.2011 21:38, Arthur Titeica пишет:

Quoted 15 lines

Hello

I'm having some trouble understanding the correct syntax for an iptables rule involving ipset.

I need to forward between IPs within the same ipset. So I've tried using something like this:

iptables -A FORWARD -i eth0 -o eth0 -m set --match-set testset src,dst -p tcp --dport 9000:9020 -j ACCEPT

However this allows forwarding to all the eth0 network for the 'testset' IPs.

Instead
iptables -A FORWARD -i eth0 -o eth0 -m set --match-set testset src -m set --match-set testset dst -p tcp --dport 9000:9020 -j ACCEPT seems to do what I need but I'm not 100% certain.

Quoted 7 lines

Anyone with a better understanding?

iptables v1.4.10
ipset v5.3.

Thank you.

Unfortunately, the flags src|dst[, src|dst...] do another work than 90% of people that new to ipset suppose to.
Some of them think the rule 'iptables -A FORWARD -m set --set something src, dst -j SOMEWHERE' is a shortcut to 'iptables -A FORWARD -m set --set something src -j SOMEWHERE; iptables -A FORWARD -m set --set something dst -j SOMEWHERE' or something like that. Just read the man of ipset section of iptables and then you'll know what these flags do.

#2 lore raw
In reply to Arthur Titeica
Quoted 8 lines · Arthur Titeica

I'm having some trouble understanding the correct syntax for an iptables rule involving ipset.

I need to forward between IPs within the same ipset. So I've tried using something like this:

iptables -A FORWARD -i eth0 -o eth0 -m set --match-set testset src,dst -p tcp --dport 9000:9020 -j ACCEPT

It'd be good to know the type of "testset". Anyway, if you want to match the same IPs in both the source and destination directions by a set, then you should use a rule like this

iptables -A FORWARD -i eth0 -o eth0 \
	-m set --match-set testset src \
	-m set --match-set testset dst \
	-p tcp -dport 9000:9020 -j ACCEPT

The keywords "src" and "dst" instructs the set match which parameter to grab from the packet ("source IP" or "destination IP") and try to match it with the elements in the set. If it's a multidimensional set, then multiple "src", "dst" parameters can be used.

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
#3 lore raw
Quoted 20 lines · Jozsef Kadlecsik
Quoted 8 lines · Arthur Titeica

I'm having some trouble understanding the correct syntax for an iptables rule involving ipset.

I need to forward between IPs within the same ipset. So I've tried using something like this:

iptables -A FORWARD -i eth0 -o eth0 -m set --match-set testset src,dst -p tcp --dport 9000:9020 -j ACCEPT

It'd be good to know the type of "testset". Anyway, if you want to match the same IPs in both the source and destination directions by a set, then you should use a rule like this

iptables -A FORWARD -i eth0 -o eth0 \
	-m set --match-set testset src \
	-m set --match-set testset dst \
	-p tcp -dport 9000:9020 -j ACCEPT
Quoted 5 lines

The keywords "src" and "dst" instructs the set match which parameter to grab from the packet ("source IP" or "destination IP") and try to match it with the elements in the set. If it's a multidimensional set, then multiple "src", "dst" parameters can be used.

Thanks for replying. The ipsets used are hash:ip so no wonder it doesn't work as I thought.
In my defence the misleading part was the online iptables man [ http://ipset.netfilter.org/iptables.man.html ] which isn't quite clear.

Signature · 4 lines
Arthur Titeica
PharmEc Software Constanta
Mobil: 0729 290 969
Tel: 0241 616 747