PortScan › Port guide › Port 21

Port 21 (FTP): Why an Open FTP Port Is Dangerous and How to Close It

TCP 21FTPFile transferExposure risk: High

Port 21 is the FTP control channel. Credentials travel in plaintext, and anonymous access can expose files outright. How to check it, move to SFTP, and close it.

What is port 21?

FTP (File Transfer Protocol), first defined in 1971, is the oldest file transfer method on the internet. Port 21 is the control channel that carries commands; the files themselves travel over a separate data channel. In active mode, data flows from the server's port 20 to the client; in passive mode, it flows to an arbitrary high port the server announces (for example 50000–51000).

That is why putting an FTP server behind a firewall takes more than opening port 21: you also have to open the passive port range. Put the other way round, a server with port 21 open usually has a wide port range open as well.

When it is normally open

Risks if it is open

Passwords are sent in plaintext

FTP sends the USER and PASS commands unencrypted. Anyone who can see the packets — on the same Wi-Fi, on the corporate network, or anywhere along the path — can read the account. If that account shares a password with the server's SSH login or control panel, the damage does not stop at FTP.

Anonymous access

A configuration where the username anonymous with any password gets you in. Internet search engines such as Shodan still index countless servers exposing backups, database dumps and company documents through anonymous FTP.

Brute-force attacks

Bots hammer port 21 around the clock. If 530 Login incorrect entries pile up in your logs every minute, you are already on a target list.

Vulnerabilities in old server software

The classic example is vsftpd 2.3.4, whose distribution archive was backdoored in 2011: putting :) in the username opened a root shell on port 6200. FTP servers bundled into router and NAS firmware are often slow to get updates.

Security checklist

How to check whether port 21 is open

From outside (is it exposed to the internet?)

Whether your server or home router accepts port 21 from the internet can only be confirmed by connecting from outside. A check from inside the same network bypasses the router's firewall and gives a different answer.

PortScan opens a real TCP connection from the Cloudflare edge and reports Open, Closed or Filtered. Members can scan every port on their own IP for free and other targets free once a day.

Check port 21

On the server (what is listening?)

Windows (PowerShell):

netstat -ano | findstr ":21 "
Get-NetTCPConnection -LocalPort 21 -State Listen | Select LocalAddress,OwningProcess

Linux:

sudo ss -tlnp | grep ':21 '

If it listens on 0.0.0.0 or [::] it is open on every network; 127.0.0.1 means only that machine can connect. To test port 21 on a server from another computer, use Test-NetConnection server-address -Port 21 on Windows or nc -vz server-address 21 on Linux and macOS.

How to close or restrict port 21

The best fix is to turn the service off or make it listen only on 127.0.0.1 (see the checklist above). If you need the service but must keep it off the internet, use a firewall.

Windows Firewall

# Administrator PowerShell
New-NetFirewallRule -DisplayName "Block TCP 21" -Direction Inbound -Protocol TCP -LocalPort 21 -Action Block
# To allow a single IP instead (block rules take precedence, so use this instead of the rule above)
New-NetFirewallRule -DisplayName "Allow TCP 21 from office" -Direction Inbound -Protocol TCP -LocalPort 21 -RemoteAddress 203.0.113.10 -Action Allow

Linux (ufw)

sudo ufw deny 21/tcp
# Allow a single IP only
sudo ufw allow from 203.0.113.10 to any port 21 proto tcp

On a cloud server, also check port 21 in the security group (inbound rules), which is separate from the OS firewall. For services running in Docker, the rules Docker creates can bypass ufw, so binding the port to localhost with -p 127.0.0.1:21:21 is the reliable option.

Router

At home or in a small office, open the router's admin page and check whether port 21 is in the port forwarding list, whether DMZ is enabled, and whether any program opened ports by itself through UPnP. If any of the three applies, port 21 on your PC is directly visible from the internet.

How to read the scan result

The verdict can depend on where you connect from. Many ISPs (including most Korean ISPs) block some ports such as 135, 139 and 445 on their network, so the same server can look Filtered from inside that network and Closed from abroad.

FAQ

Are FTP and SFTP the same thing?
No. The names are similar, but they are completely different protocols. SFTP runs inside an SSH connection and uses port 22. FTPS is FTP wrapped in TLS and uses port 21 (explicit) or 990 (implicit).
I closed port 21, but FTP still shows up
Either the server is configured to accept FTP on another port (for example 2121), or a port-forwarding rule is still active on your router. Widen the port range and scan again.
22 SSH990 FTPS445 SMB

Last updated 2026-11-04 · Use this guide to check systems you manage. Scanning systems without permission may carry legal liability.