Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use this code to protect my ssh.

-A INPUT -p tcp --dport 22 -m state --state NEW -j SSH_CHECK
-A SSH_CHECK -m recent --set --name SSH
-A SSH_CHECK -m recent --update --seconds 900 --hitcount 2 --name SSH -j DROP
-A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
-A INPUT -p tcp --dport 25 -j DROP
-A INPUT -p udp --dport 25 -j DROP

How can I add port 21 to this list?

If I use

-A INPUT -p tcp --dport 21 -m state --state NEW -j SSH_CHECK

Is it same as using port 22?

share|improve this question

You can rate-limit new FTP connections from a host using the same method you're rate limiting FTP. I'd create another chain (something like FTP_CHECK rather than SSH_CHECK) and you'll want to use another list (say FTP rather than SSH) to keep the incoming FTP host addresses separate from SSH addresses. Something like:

-A INPUT -p tcp --dport 21 -m state --state NEW -j FTP_CHECK
-A FTP_CHECK -m recent --set --name FTP
-A FTP_CHECK -m recent --update --seconds 900 --hitcount 2 --name FTP -j DROP

Two FTP connections in 900 seconds is a little bit strict, though, in my opinion. I'd open that up a little bit more or legitimate users may find that, should they get disconnected, they won't be able to reconnect. Tune to suit your needs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.