Sub topic 3
File Transfer, Infrastructure, and Service Ports
Assume you know basic IP addressing, the client-server model, terminal commands, and short Python scripts. A port identifies a service endpoint for a particular transport protocol. The same number can mean different things for TCP and UDP.
File transfer: FTP, SFTP, and TFTP
- FTP uses TCP port 21 for commands. Its data connection uses TCP port 20 in active mode or negotiated ports in passive mode. Firewalls must therefore account for more than port 21.
- SFTP is file transfer over SSH. It uses one encrypted TCP connection, normally port 22.
- TFTP is a small, unauthenticated file-transfer protocol over UDP port 69. Devices often use it for boot images or network configuration. It is unsuitable for general file sharing.
Infrastructure and directory services
DHCP uses UDP 67 on servers and UDP 68 on clients. NTP normally uses UDP 123. SNMP uses UDP 161 for queries and UDP 162 for traps. Traditional syslog uses UDP 514; encrypted syslog commonly uses TCP 6514.
LDAP uses TCP or UDP 389, while LDAP over TLS commonly uses TCP 636. SMB file and printer sharing normally uses TCP 445. These services should be reachable only from the networks that need them.
Common database ports
| Service | Default port | Transport |
|---|---|---|
| PostgreSQL | 5432 | TCP |
| MySQL or MariaDB | 3306 | TCP |
| Microsoft SQL Server | 1433 | TCP |
| Redis | 6379 | TCP |
A default port is a convention, not a guarantee. Database access should normally be restricted to application hosts, not exposed to the public internet.
Listing, testing, and filtering ports
On a Linux host, list local listeners with:
ss -tulnpFrom an authorized machine, test whether a TCP service accepts connections:
nc -vz 192.0.2.10 5432A successful test proves that a connection reached something that accepted it. It does not prove that authentication works or that the expected application is running.
Non-standard ports
Administrators sometimes move a service to another port to avoid collisions or reduce automated noise. This does not add encryption or authentication. Firewalls and monitoring should identify the actual service and configuration, rather than trusting a number. Port 443 may carry something other than HTTPS, and a database on port 443 remains a database.
Exercise
Why does allowing FTP TCP port 21 alone often fail for a passive FTP client?
Show answer
Passive FTP negotiates additional data ports, so the firewall must allow the configured passive range as well as the control connection.