LinuxQuestions.org
Review your favorite Linux distribution.
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 10-15-2023, 10:56 AM   #1
kenw232
Member
 
Registered: May 2006
Posts: 125

Rep: Reputation: 12
iptables connlimit-mark question


I've been doing this to rate limit Amazon connections to my server. My question is, is this correct?

Code:
/usr/sbin/iptables -I INPUT -p tcp --syn --dport 443 -s 3.238.56.0/24 -m connlimit --connlimit-above 3 --connlimit-mask 32 -j LOG_REJECT
The concern is the source of 3.238.56.0/24 where I am trying to include all IP addresses between 3.238.56.0 and 3.238.56.255. Is this correct considering the connlimit-mask of 32 is still there? Am I going to get my expected result of throttling all hits from 3.238.56.0/24 to be less then 3 no matter what?
 
Old 10-19-2023, 03:18 AM   #2
Person_1873
Member
 
Registered: Sep 2007
Location: Australia
Distribution: Gentoo / Debian / Rasbian / Proxmox
Posts: 519

Rep: Reputation: 44
the connlimit mask calculates how many addresses surrounding the current address are added to the filter after the connection attemps.
a mask of 32, means that only that single IP gets added to the reject list
Otherwise you end up adding multiple IP's to the reject list even though those IP's weren't spamming you.

Personally i'd be using Fail2Ban as it has functionality to automatically unban after a timeout and is designed for this task.
 
Old 10-19-2023, 06:05 PM   #3
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
Right, but again, what is the point of the netmask? 3.238.56.0/24? I should not be doing a /24 then? is it ignored? If I'm using a connlimit-mask 32, then what single IP is being blocked if my source is 3.238.56.0/24? All 255 "single" IPs?
 
Old 10-19-2023, 11:18 PM   #4
Person_1873
Member
 
Registered: Sep 2007
Location: Australia
Distribution: Gentoo / Debian / Rasbian / Proxmox
Posts: 519

Rep: Reputation: 44
The point of the netmask is to limit the range of addresses that could be rate limited.
The connlimit mask dictates how many addresses are added to the ban list each time the rule is triggered
 
Old 10-19-2023, 11:22 PM   #5
Person_1873
Member
 
Registered: Sep 2007
Location: Australia
Distribution: Gentoo / Debian / Rasbian / Proxmox
Posts: 519

Rep: Reputation: 44
With a netmask of 3.238.56.0/24 and a connlimit-mask of 32.

If 3.238.56.5 attempts to connect 3 times or more, then 3.238.56.5 gets added to the reject list.
But if 3.238.57.5 did the same thing then nothing would happen, this rule won't trigger.
 
Old 10-20-2023, 08:21 AM   #6
kenw232
Member
 
Registered: May 2006
Posts: 125

Original Poster
Rep: Reputation: 12
I see, so with 3.238.56.0/24 it is obviously checking for 3.238.56.*. But when it does find something in 3.238.56.* then only that single IP address that is found is blocked.
 
Old 10-20-2023, 11:11 PM   #7
Person_1873
Member
 
Registered: Sep 2007
Location: Australia
Distribution: Gentoo / Debian / Rasbian / Proxmox
Posts: 519

Rep: Reputation: 44
That's correct.
subnetting is a whole skillset in it's self & is worth looking into
 
  


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
I cannot find my mark after using "iptables --set-mark" hebothu Linux - Networking 1 09-04-2015 09:22 AM
Need an alternative to connlimit in iptables. teek5449 Linux - Security 8 02-28-2012 06:15 PM
IPTables (connLimit vs hashlimit) nanogoo Linux - Security 3 01-24-2011 04:51 AM
iptables - connlimit doesnt work dlugasx Linux - Server 1 12-30-2010 03:12 AM
Centos 5.0 x86_64: need help adding connlimit module to iptables thanhlong Linux - Enterprise 4 07-14-2008 03:14 AM

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

All times are GMT -5. The time now is 09:47 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