Ports / FTP

TCP port

Port 21: FTP

TCP port 21 is where an FTP server listens for commands: log in, list, get, put. The files themselves travel on a second connection, on another port.

  • In active mode the server opens the data connection from its port 20 to a port the client names. In passive mode the client opens it to a port the server names.
  • That second connection is why FTP breaks behind NAT and behind firewalls that only allow port 21.
  • FTP sends the password and the files unencrypted.

Check port 21 on Linux

Put the server's name or address in place of HOST.

ss -tlnp 'sport = :21'
On the server: is a program listening on TCP port 21, on which address, and which program? How to read ss.
nc -zv HOST 21
From a client: does a TCP connection to port 21 open, get refused, or time out? How to read nc.
tcpdump -ni any tcp port 21
On either end: the packets to and from TCP port 21, as they cross the card. How to read tcpdump.
nmap -p 21 HOST
From outside: is TCP port 21 open, closed or filtered? How to read nmap.

What runs on it

FTP
File transfer over two kinds of connection: commands on port 21, and a separate data connection per transfer.
Stateful firewall
A firewall that remembers connections, so it can allow replies while refusing new connections in.
NAT
A router rewriting addresses as packets pass, usually to hide many private devices behind one address.

Use port 21 on real machines

Open File transfer: why the login works and the list hangs

Sources

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab