LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2016, 08:30 AM   #1
systemlordanubis
Member
 
Registered: Jun 2010
Distribution: Debian, Ubuntu, Win
Posts: 143

Rep: Reputation: 16
ipset not matching in mangle table


Hi All,

I have an ipset group which is configured with a hash:ip,port.

user@svr1:~# ipset list TestSet
Name: TestSet
Type: hash:ip,port
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 16656
References: 7
Members:
10.10.3.186,udp:12345
10.10.3.186,tcp:12345


When I add a record to the POSTROUTING table like this:

iptables -t mangle -I POSTROUTING 1 -m set --match-set TestSet src -j CLASSIFY --set-class 1:99

No packets are ever matched, yet, if I add this record:

iptables -t mangle -I POSTROUTING 1 -p udp -s 10.10.3.186 --sport 12345 -j CLASSIFY --set-class 1:99

It does successfully match the packets.

I can't find any reason why this wouldn't be matching packets as I have sets working fine in other sections.

Has anyone else ever encountered this or am I just overlooking something?

Thanks.
Anubis.
 
Old 11-05-2016, 08:59 AM   #2
systemlordanubis
Member
 
Registered: Jun 2010
Distribution: Debian, Ubuntu, Win
Posts: 143

Original Poster
Rep: Reputation: 16
After a lot more searching, I came across the solution from this source - http://thread.gmane.org/gmane.comp.s....general/46123


In the rules above you specified a single direction flag for a two
dimensional set, thus the matching returned "false". If in the first rule
the port is the destination, then it should be:


Which means my rule should have been listed as:

iptables -t mangle -I POSTROUTING 1 -m set --match-set TestSet src,src -j CLASSIFY --set-class 1:99


Once correcting the missing ",src" the rule's working perfectly.

Hope this is able to help some others in the future.

Anubis.
 
Old Today, 04:20 AM   #3
kerin444
LQ Newbie
 
Registered: Apr 2024
Posts: 1

Rep: Reputation: 0
I know it's an old thread but I wanted to say THANK YOU because it helped me to better understand and troubleshoot my IpSet problem.

It may help because documentation is very poor on IpSet and Iptables "set" module.

If you are using HASH:IP IpSet, you have to use Iptables rules like this "-m set --match-set myIpSet dst -j ACCEPT" with a sigle "tag"
If, like me, you are using HASH:IP,PORT IpSet, you have to use IpTables rules like this "-m set --match-set myIpSet dst,dst -j ACCEPT" with 2 tags to match the content of the IpSet
But you can also filter Source and Destination with IpSet described by HASH:NET,IP,PORT and have rules "-m set --match-set myIpSet src,dst,dst -j ACCEPT" with 3 tags this time
You can have up to 6 tags in one IpSet

Ex:
Code:
ipset create IpSetFilter1 hash:ip,port timeout 604800
# Allow SSH from 10.125.33.0/24 to 10.40.10.10 for 1 hour
ipset add IpSetFilter1 10.125.33.0/24,10.40.10.10,tcp:22 timeout 3600 
iptables -I FORWARD -m set ! --match-set IpSetFilter1 src,dst,dst -j DROP
iptables -I FORWARD -m set ! --match-set IpSetFilter1 src,dst,dst -j LOG --log-level info --log-prefix "DROP IPSET NOT MATCH"
iptables -I FORWARD -m set --match-set IpSetFilter1 src,dst,dst -j ACCEPT

I hope it will help people with IpSet!!

Best regards,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] iptables, iproute2: rerouting not triggered after setting MARK in mangle OUTPUT table fabioca Linux - Networking 1 11-10-2015 12:31 AM
Linux Firewall - (rpm package lacks the NAT/MANGLE table.) andalogokct CentOS 10 08-12-2015 05:00 PM
CentOS Firewall (rpm package lacks NAT/MANGLE table.) andalogokct Linux - Software 1 08-11-2015 06:36 PM
Meanings of IPTABLES mangle table mosharaf_linux Linux - Server 1 02-14-2011 06:53 AM
Mangle Table santhosh23 Linux - General 2 06-24-2007 08:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration