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 09-09-2023, 11:15 PM   #1
rutrow
LQ Newbie
 
Registered: Sep 2009
Distribution: Debian
Posts: 20

Rep: Reputation: 1
Connection rate limit per IP with nftables


I'm attempting to limit connections per IP to port 25 using nftables.

Snippet of my rules:

Code:
#!/usr/sbin/nft -f

flush ruleset

table ip filter {
  set ban {
    type ipv4_addr
    size 65535
    flags dynamic,timeout
    timeout 5m
  }
  chain input {
    type filter hook input priority filter; policy drop;
    iif "lo" accept
    ct state invalid drop
    ct state established,related accept
    ct state new tcp dport 25 limit rate over 1/second burst 1 packets add @ban { ip saddr }
    ip saddr @ban counter drop
    # other rules inserted here
  }
}
My understanding is this will allow one new connection every 1 second. Exceeding that rate will add the IP to the ban set for 5 minutes. Tested and seems to work. However, if the rate is currently exceeded by some IP address and a different IP tries to connect just once, it also gets added to the ban set. So it appears this is not a per IP rule, but rather a simple rate limit for the port. Is there a way to implement this per IP?

Thanks!
 
Old 09-25-2023, 05:28 PM   #2
GlennsPref
Senior Member
 
Registered: Apr 2004
Location: Brisbane, Australia
Distribution: Devuan
Posts: 3,658
Blog Entries: 33

Rep: Reputation: 283Reputation: 283Reputation: 283
Hi, "4.9 Dynamic blackhole" maybe adapted...

https://wiki.archlinux.org/title/nftables#Examples

I don't have an answer for your question, but maybe somewhere you can see how it might be done.

This may be useful as well...
https://wiki.nftables.org/wiki-nftab..._in_10_minutes
 
1 members found this post helpful.
Old 09-25-2023, 10:19 PM   #3
rutrow
LQ Newbie
 
Registered: Sep 2009
Distribution: Debian
Posts: 20

Original Poster
Rep: Reputation: 1
Hi GlennsPref,

The "Dynamic blackhole" link was helpful. It put me on the path to find https://wiki.nftables.org/wiki-nftab...dex.php/Meters. Appears I just need a minor modification. I'll do some testing as I get time...

Thanks!
 
  


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
iptables limit per IP per minute - "No chain/target/match by that name" no_root_no_cry Linux - Networking 3 12-25-2013 03:06 PM
In PPTP server, how to limit bandwidth per user, & no. of connection per account ? erv2 Linux - Networking 1 04-05-2010 08:03 AM
SQUID - connection limit per user not per IP adress iksik Linux - Software 3 03-10-2010 09:52 AM
When using ssh: limit the number of users, that can log on, per IP address -rate tuxhats Linux - Security 24 04-17-2009 03:23 AM
How do ISPs limit download rate per user? ganninu Linux - Networking 2 10-22-2003 12:13 PM

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

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