LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-09-2016, 12:14 PM   #1
elalexluna83
Member
 
Registered: Mar 2012
Posts: 55

Rep: Reputation: Disabled
Iptables - limit incoming connection


Hello Guys!
I'd like to limit the number of ssh connections to my server.
I'd like to do it using the match limit, but i keep being kicked out. Any clue??

here's my rules so far.
iptables -A INPUT -p tcp -s 0/0 --destination-port 22 -m limit --limit 3/s --limit-burst 5 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 --destination-port 22 -j LOG --log-level debug --log-prefix "NETFILTER - SSH: "
iptables -A INPUT -p tcp -s 0/0 --destination-port 22 -j REJECT --reject-with tcp-reset

i have done this on the past, using connlimit/hashlimit, but i'd really want to do it using -m limit so i can learn something new.

# OLD RULES (BOTH WORKING)
# -m connlimit
iptables -A INPUT -p tcp -s 0/0 --destination-port 22 -m connlimit --connlimit-above 2 -j LOG --log-prefix "NETFILTER - CONNLIMIT: "
iptables -A INPUT -p tcp -s 0/0 --destination-port 22 -m connlimit --connlimit-above 2 -j REJECT --reject-with tcp-reset
iptables -A INPUT -p tcp -s 0/0 --destination-port 22 -j ACCEPT

# -m hashlimit
iptables -A INPUT -p tcp --dport 22 -m hashlimit --hashlimit-mode srcip --hashlimit-above 3/minute -j DROP
 
Old 03-10-2016, 08:10 AM   #2
serafean
Member
 
Registered: Mar 2006
Location: Czech Republic
Distribution: Gentoo, Chakra
Posts: 997
Blog Entries: 15

Rep: Reputation: 136Reputation: 136
Hi,

AFAIK connlimit limits the number of active connections, limit limits the number of packets that go through. My first recommendation would be to limit the mlimit rule only to SYN packets. I last used limit quite some time ago, so my knowledge might be a bit rusty, but in nftables I hit this problem a week ago.

S.
 
Old 03-10-2016, 10:36 AM   #3
elalexluna83
Member
 
Registered: Mar 2012
Posts: 55

Original Poster
Rep: Reputation: Disabled
Thanks mate, that's enough for me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Strongswan 5.2.0 - rate limit incoming connection attempts? psycroptic Linux - Server 0 10-26-2014 06:45 AM
[SOLVED] Limit incoming HTTP bandwith usage with IPTABLES EricTRA Linux - Security 6 05-05-2011 06:21 PM
iptables port connection limit rule Shwick Linux - Security 18 10-09-2008 09:26 PM
Limit incoming smtp connection by ip using iptables lynksinc Linux - Security 4 11-03-2005 12:27 PM

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

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