LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 03-11-2017, 09:09 AM   #1
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 110

Rep: Reputation: Disabled
Configure Iptables with ipset trouble


Hello there,

I would highly appreciate it if someone could help on a quite simple ipset rule I am trying to set up. I cannot really understand why it does not seem to work. So here it goes:

1. I create a simple file with IP addresses I would like to block and call it blocklist

2. Then I create my ipset and reference it like this:

ipset create blocklist nethash
for i in $(cat /path/to/blocklist); do ipset add blocklist $i; done
-A INPUT -p tcp --match multiport --dport 25,587 -m set --match-set blocklist src -j DROP

When I verify it with:
ipset test blocklist (IP address here) and press enter
it says the IP address is on the list.

When I verify it with:
iptables -L -n -v
it says my iptables' rule is there and in action.

However, when I connect from the IP address that is on the blocklist it does not block this IP address by saying connection timed out, it simply gets connected and goes right through... I am lost... Could anybody advise, please where is there a mistake in my setting? Any pointers / assistance / suggestions, etc. are most welcome! Many thanks in advance!
====
P.S. It works OK when I set it without any multiport options and blocks only one port like this:

-A INPUT -p tcp --dport 80 -m set --match-set blocklist src -j DROP

but when I do the same thing but on the 25th port it won't work:

-A INPUT -p tcp --dport 25 -m set --match-set blocklist src -j DROP

I cannot really figure it out. I have Postfix running OK and listening onto my 25th port.

P.S.S. The only thing that comes to my mind is that there is a limit of ipset's sets that I can have (is that possible at all?) that's why my last rule does not work because it's being pushed out of the allowed limit... clueless...

Last edited by Klaipedaville; 03-11-2017 at 01:34 PM.
 
Old 03-12-2017, 06:21 AM   #2
camp0
Member
 
Registered: Dec 2016
Location: Dublin
Distribution: Fedora
Posts: 70

Rep: Reputation: 4
Hi

May be if you just create a diferent iptables with different ports and works, that mey be is the solution, however, it looks that when you use the ipset the iptables use a lookup algorithm that may be don't have support for multiple ports. Go to the netfilter mailing list and probably you will find the solution, and on the meanwhile you can use the iptables rules by select the single port.
 
Old 03-15-2017, 12:47 PM   #3
end
Member
 
Registered: Aug 2016
Posts: 266

Rep: Reputation: Disabled
re

Quote:
-A INPUT -p tcp --match multiport --dport 25,587 -m set --match-set blocklist src -j DROP
try OUTPUT

check

https://www.linuxquestions.org/quest...ip-4175601788/

i didn see that you fix it

but check this

-A INPUT -p tcp -m tcp --match multiport --dports 25,587 -m set --match-set blocklist src -j DROP

with multi port you need dports not dport and try sports on input.

Last edited by end; 03-15-2017 at 01:37 PM.
 
Old 03-16-2017, 11:47 AM   #4
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by Klaipedaville View Post
-A INPUT -p tcp --match multiport --dport 25,587 -m set --match-set blocklist src -j DROP
syntax is wrong
Code:
-A INPUT -p tcp -m multiport --dport 25,587 -m set --match-set blocklist src -j DROP
One question I have is are only blocking them from certain ports or do you want to block them from everything? Normally when I block you, you're blocked from everything not just a few ports.

Quote:
P.S. It works OK when I set it without any multiport options and blocks only one port like this:

-A INPUT -p tcp --dport 80 -m set --match-set blocklist src -j DROP

but when I do the same thing but on the 25th port it won't work:

-A INPUT -p tcp --dport 25 -m set --match-set blocklist src -j DROP

I cannot really figure it out. I have Postfix running OK and listening onto my 25th port.

P.S.S. The only thing that comes to my mind is that there is a limit of ipset's sets that I can have (is that possible at all?) that's why my last rule does not work because it's being pushed out of the allowed limit... clueless...
There are limits to everything but in this case it would not be ipset that is limiting you as you can see the ip addresses

Since you are not showing your entire firewall rule set it is hard to pin-point the issue. You could have other rules that allow things to connect that you are trying to block. Because IPTABLES works in top down mode if you have a rule before your DROP rules that allows said IP Address then your DROP rules are useless.
 
Old 03-16-2017, 01:56 PM   #5
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 110

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by lazydog View Post
syntax is wrong
Code:
-A INPUT -p tcp -m multiport --dport 25,587 -m set --match-set blocklist src -j DROP
One question I have is are only blocking them from certain ports or do you want to block them from everything? Normally when I block you, you're blocked from everything not just a few ports.
Thank you for replying and your suggestions. I appreciate. The syntax is perfectly correct as it is working well. My iptables are not of the latest version and that's most probably why you thought it was outdated.

The rule clearly shows which ports I would like to be blocked. I do not intend to block everything.

I figured it out myself though. The trouble is in -A INPUT that amends (-A = amend) the rules and puts them "at the end". It all works successively as you correctly mentioned in your reply therefore the solution was to -I INPUT which creates a new rule (-I = input) and does the trick.
 
Old 03-16-2017, 02:50 PM   #6
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
If you're good to go then mark this puppy as resolved. Thnx.
 
  


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
ipset with iptables not working wolfsden3 Linux - Security 2 09-09-2014 08:09 PM
[SOLVED] iptables/ipset match-set not working freeindy Linux - Networking 1 08-14-2014 01:58 AM
[SOLVED] ipset and iptables - recompile iptables? Habitual Linux - Server 2 02-19-2014 08:12 AM
iptables / ipset, redirect a set to another host/ip? i5050net Linux - Networking 1 09-16-2013 01:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:30 PM.

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