Port 21 is the FTP control channel, used for logging in and sending commands. In active mode the server opens data connections from port 20; in passive mode it uses a separate range of high ports. It should not be reachable from the public internet.
- Port
- 21
- Protocol
- TCP
- Service
- FTP
- Expose to internet?
- No
- Also used by
- vsftpd, ProFTPD, Pure-FTPd, FileZilla Server
Is port 21 safe to open?
Plain FTP sends usernames, passwords and file contents unencrypted, so anyone on the network path can read them. Public FTP servers attract constant password-guessing, and anonymous logins are often left enabled by mistake. Unless you must support legacy clients, use SFTP over SSH instead.
How to secure FTP
- Replace FTP with SFTP (port 22) where clients allow it.
- If you must keep FTP, require TLS (FTPS). In vsftpd set
ssl_enable=YESandforce_local_logins_ssl=YES. - Disable anonymous access:
anonymous_enable=NOin vsftpd. - Pin the passive range with
pasv_min_portandpasv_max_port, and open only that range in the firewall. - Jail users to their home directory with
chroot_local_user=YES.
Check if port 21 is open
Linux: what is listening on this port
sudo ss -tlpn | grep ':21 'Windows (PowerShell): what is listening
Get-NetTCPConnection -LocalPort 21 -State Listen | Select-Object LocalAddress, OwningProcess, @{n='Process';e={(Get-Process -Id $_.OwningProcess).Name}}From another machine: is it reachable
nc -zv HOST 21
# or
nmap -p 21 HOST
# Windows
Test-NetConnection HOST -Port 21Test the FTP service itself
curl -v ftp://HOST/ --user USERRestrict port 21 in the firewall
Replace 10.0.0.0/8 with the network or address that needs access. Docker publishes container ports through its own iptables rules, which bypass ufw; bind published ports to 127.0.0.1 (-p 127.0.0.1:21:21) instead of relying on the host firewall.
ufw: allow only your private network, deny everyone else
sudo ufw allow from 10.0.0.0/8 to any port 21 proto tcp
sudo ufw deny 21/tcpfirewalld: allow one source network only
sudo firewall-cmd --permanent --remove-port=21/tcp
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.0/8" port port="21" protocol="tcp" accept'
sudo firewall-cmd --reloadiptables
sudo iptables -A INPUT -p tcp --dport 21 -s 10.0.0.0/8 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 21 -j DROPWindows Firewall (PowerShell, as Administrator)
New-NetFirewallRule -DisplayName "Block 21 from internet" -Direction Inbound -Protocol TCP -LocalPort 21 -RemoteAddress Internet -Action BlockMonitor port 21
Run a TCP port monitor against your public IP on port 21: here, a failed connection is the healthy result, so you know the firewall is still doing its job. On Linux, the Statance agent also reports every listening port on the server. TCP port monitoring.
Related ports
FAQ
What is the difference between port 20 and port 21?
Port 21 carries FTP commands and replies. Port 20 is used for data transfers in active mode only. Most modern clients use passive mode, where the data connection goes to a high port the server announces instead.
Is SFTP the same as FTP on port 21?
No. SFTP is a file-transfer protocol that runs inside SSH on port 22. FTPS is FTP with TLS and still uses port 21 (or 990 for implicit TLS).
What is port 21 used for?
Port 21 is the FTP control channel, used for logging in and sending commands. In active mode the server opens data connections from port 20; in passive mode it uses a separate range of high ports. It is also used by vsftpd, ProFTPD, Pure-FTPd, FileZilla Server.
Is it safe to open port 21?
Not to the public internet. Plain FTP sends usernames, passwords and file contents unencrypted, so anyone on the network path can read them. Public FTP servers attract constant password-guessing, and anonymous logins are often left enabled by mistake. Unless you must support legacy clients, use SFTP over SSH instead.
Is port 21 TCP or UDP?
FTP uses TCP on port 21.
How do I check if port 21 is open?
On the server, run sudo ss -tulpn | grep ':21 ' (Linux) or Get-NetTCPConnection -LocalPort 21 (Windows) to see what is listening. From another machine, run nc -zv HOST 21 or Test-NetConnection HOST -Port 21.
Know the moment a port stops answering.
TCP, HTTP, DNS and SSL checks from six regions, plus server metrics from a one-line agent.