0

I'm trying to build a SSH system that lets me in using SSH (port 22). Then If I block the port using iptables:

sudo iptables -I INPUT -p tcp --destination-port 22 -j DROP

It would keep the previous connection(s) alive.

Is it possible?

System: Ubuntu 20

4
  • What Linux flavor are you using and which one? What is the goal here? Sep 16, 2021 at 13:48
  • Linux system Ubuntu. I'll update the question as well :)
    – PaxPrz
    Sep 16, 2021 at 13:56
  • 1
    i suggest you need an allow established connections rule prior/before the drop rule like sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT Sep 16, 2021 at 13:59
  • @Pax then you most probably want to work with firewalld. Having that said, have a look at iptables-apply command. It does exactly what you want. Sep 16, 2021 at 14:04

1 Answer 1

1

If you want to block attempts to make new TCP connections on port 22 while existing connections remain unaffected, try using

# iptables -A INPUT -j DROP -p tcp --syn --destination-port 22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .