Hostxpeed
Login Get Started →
Security

How to Use Port Knocking

6 min read
26 views
Jun 10, 2026

Step 1: Install knockd

sudo apt install knockd -y

Step 2: Configure knockd

sudo nano /etc/knockd.conf

Example configuration:

[options]
logfile = /var/log/knockd.log

[openSSH]
sequence = 7000,8000,9000
seq_timeout = 5
command = /sbin/iptables -A INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
tcpflags = syn

[closeSSH]
sequence = 9000,8000,7000
seq_timeout = 5
command = /sbin/iptables -D INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
tcpflags = syn

Step 3: Enable and Start

sudo systemctl enable knockd
sudo systemctl start knockd

Step 4: Knock from Client

knock YOUR_SERVER_IP 7000 8000 9000
ssh user@YOUR_SERVER_IP

Was this article helpful?