Lesson 19 intermediate

Email, File Transfer and Management Protocols

The application protocols beyond the web: SMTP, POP3 and IMAP for email with SPF, DKIM and DMARC, FTP, SFTP, TFTP and SMB for files, LDAP for directories, NTP for time, SNMP for monitoring, SSH for remote access, MQTT for IoT, SIP for voice and NNTP for newsgroups, with their ports and test commands.

HTTP gets most of the attention, but a working organization depends on many other application protocols: mail must flow, file shares must mount, clocks must agree, users must log in against a directory and devices must report their health. This lesson tours them, with the port numbers you will meet in every firewall ticket and a quick way to test each one.

The port map

ProtocolPort(s)TransportPurpose
SMTP25 (server to server), 587 (submission, STARTTLS), 465 (implicit TLS)TCPSend mail
POP3 / POP3S110 / 995TCPDownload mail
IMAP / IMAPS143 / 993TCPAccess mail on the server
FTP21 (control), 20 or random (data)TCPFile transfer, unencrypted
SFTP / SCP (over SSH)22TCPEncrypted file transfer
TFTP69UDPTiny file transfer for network boot
SMB445TCPWindows file and printer sharing
NFS2049TCPUnix file sharing
LDAP / LDAPS389 / 636TCPDirectory queries and logins
NTP123UDPClock synchronization
SNMP / traps161 / 162UDPDevice monitoring
SSH22TCPRemote shell and tunnels
MQTT / MQTT over TLS1883 / 8883TCPIoT messaging
SIP / SIPS5060 / 5061UDP or TCP / TLSVoice and video call setup
NNTP / NNTPS119 / 563TCPUsenet newsgroups

Email: SMTP, POP3 and IMAP

Email uses separate protocols to send and to read:

  1. Your mail app submits a message to your provider’s server with SMTP on port 587, after logging in.
  2. Your provider looks up the recipient domain’s MX record and delivers it, server to server, with SMTP on port 25.
  3. The recipient’s app reads it with IMAP (or POP3).
POP3IMAP
ModelDownload and (usually) delete from the serverMail stays on the server, synced to every device
Folders and flagsLocal onlyShared across devices
TodayRareThe standard (or a provider’s own API, like Gmail’s or Microsoft Graph)

An SMTP conversation is readable text:

$ openssl s_client -starttls smtp -connect mail.example.com:587 -crlf -quiet
220 mail.example.com ESMTP ready
EHLO laptop.example.net
250-mail.example.com
250-AUTH PLAIN LOGIN
250 SIZE 52428800
QUIT
221 2.0.0 Bye

swaks (the “Swiss army knife for SMTP”) automates full test messages: swaks --to you@example.com --server mail.example.com:587 --auth-user you@example.com -tls.

Proving mail is genuine

SMTP itself does not check who the sender is, so three DNS-based standards fight spoofing:

  • SPF: a TXT record listing the servers allowed to send for the domain.
  • DKIM: the sending server signs each message; the public key is published in DNS.
  • DMARC: tells receivers what to do when SPF and DKIM fail (none, quarantine, reject) and where to send reports.
$ dig +short TXT example.com | grep spf
"v=spf1 mx include:_spf.mailprovider.example -all"
$ dig +short TXT _dmarc.example.com
"v=DMARC1; p=reject; rua=mailto:dmarc@example.com"

Large mailbox providers now reject or junk bulk mail that lacks all three.

File transfer: FTP, SFTP and TFTP

FTP is from 1971 and shows its age: credentials and data travel in clear text, and it uses a separate data connection that fights with NAT and firewalls (active mode connects back to the client; passive mode opens a random server port). FTPS adds TLS but keeps the two-connection mess.

Use SFTP instead: it runs over a single SSH connection on port 22, encrypted and simple to firewall.

$ sftp deploy@files.example.com
sftp> put release-1.4.2.tar.gz /srv/releases/
sftp> ls -l /srv/releases
$ rsync -avz --partial ./site/ deploy@files.example.com:/var/www/site/

rsync over SSH only sends what changed, which makes it the usual tool for syncing directories.

TFTP is “trivial”: UDP, no login, no directory listing, just get and put. It survives because tiny boot loaders can implement it: PXE network boot and loading firmware or configs onto routers and IP phones. Never expose it beyond a management network.

SMB and NFS: network file systems

SMB (Server Message Block, port 445) is how Windows shares files and printers; Samba implements it on Linux and macOS. Use SMB 3 with encryption, and keep the old SMBv1 disabled: it was the door used by the WannaCry worm. NFS is the Unix equivalent, common for Linux servers and Kubernetes volumes.

$ smbclient -L //fileserver.lan -U jeff
$ sudo mount -t cifs //fileserver.lan/projects /mnt/projects -o username=jeff,vers=3.1.1
$ showmount -e nfs-server.lan
Export list for nfs-server.lan:
/srv/share 10.10.0.0/24

LDAP: directories and logins

LDAP queries a directory: a tree of users, groups and devices such as Active Directory, OpenLDAP or FreeIPA. Applications use it to look up users and check passwords, and network devices use it (often through RADIUS) to authenticate admins. Always use LDAPS (636) or StartTLS; plain LDAP binds send passwords in clear text.

$ ldapsearch -H ldaps://dc1.corp.example.com -D 'svc-reader@corp.example.com' -W \
    -b 'dc=corp,dc=example,dc=com' '(sAMAccountName=jeff)' mail memberOf

NTP: keeping time

Logs, TLS certificates, Kerberos logins, databases and distributed systems all break when clocks drift. NTP (UDP 123) syncs clocks to within milliseconds over the internet. Servers form a hierarchy of strata: stratum 0 is an atomic clock or GPS, stratum 1 servers are attached to it, and so on.

$ chronyc tracking | grep -E 'Reference|Stratum|System time'
Reference ID    : A29FC87B (time.cloudflare.com)
Stratum         : 4
System time     : 0.000041306 seconds fast of NTP time
$ timedatectl | grep synchronized
System clock synchronized: yes

Kerberos (and therefore Active Directory) refuses logins when clocks differ by more than five minutes by default: a classic “network problem” that is really a time problem.

SNMP: monitoring devices

SNMP lets a monitoring system read counters from routers, switches, printers and UPSs: interface traffic, errors, CPU, temperature. Values live in a tree of OIDs described by MIBs. The manager polls agents on UDP 161; agents send traps on UDP 162 when something happens.

Use SNMPv3, which adds authentication and encryption. v1 and v2c send a “community string” in clear text, and the default public community has leaked many network maps.

$ snmpwalk -v3 -l authPriv -u monitor -a SHA -A 'auth-secret' -x AES -X 'priv-secret' switch1.lan IF-MIB::ifDescr
IF-MIB::ifDescr.1 = STRING: GigabitEthernet0/1
IF-MIB::ifDescr.2 = STRING: GigabitEthernet0/2

Newer platforms also stream telemetry with gNMI, but SNMP remains everywhere.

SSH

SSH gives an encrypted remote shell, file transfer (SFTP, SCP) and tunnels. Key-based login, no root password logins and a short list of allowed users are the standard hardening.

$ ssh -L 5433:db.internal:5432 bastion.example.com
$ ssh -J bastion.example.com app1.internal

The first command forwards local port 5433 through the bastion to an internal database; the second jumps through the bastion to reach a private server.

MQTT: messaging for IoT

MQTT is a tiny publish/subscribe protocol. Devices publish to topics (home/kitchen/temperature) on a broker such as Mosquitto, and anything subscribed receives the messages. It has three delivery levels (QoS 0 at most once, 1 at least once, 2 exactly once), a small header and keeps working over poor links, which suits sensors and home automation.

$ mosquitto_sub -h broker.lan -t 'home/+/temperature' -v &
$ mosquitto_pub -h broker.lan -t 'home/kitchen/temperature' -m '21.5'
home/kitchen/temperature 21.5

SIP: voice and video calls

SIP sets up, changes and ends calls: who is calling whom, which codecs to use and where to send the media. The voice itself travels separately in RTP streams over UDP (encrypted as SRTP). Because SIP messages carry IP addresses inside them, NAT breaks it easily, which is why VoIP systems lean on the NAT traversal tools from lesson 13 or session border controllers.

NNTP: Usenet

NNTP distributes and reads articles in Usenet newsgroups, a decentralized discussion system from 1980 where servers copy articles to each other. It is mostly historical today but still runs, and it influenced how mailing lists and forums work.

Exercise

A user’s mail app can receive email but sending fails. Which port is the most likely to be blocked?

  1. 993
  2. 587
  3. 110
  4. 143
Show answer

Answer: B. Clients submit outgoing mail with SMTP on port 587 (or 465). 993, 110 and 143 are for reading mail with IMAPS, POP3 and IMAP.

Exercise

Why is SFTP preferred over FTP for moving files across the internet?

  1. SFTP uses UDP, which is faster
  2. FTP cannot transfer binary files
  3. SFTP does not need a server
  4. SFTP is encrypted and uses a single SSH connection, while FTP sends passwords in clear text and needs a second data connection
Show answer

Answer: D. FTP exposes credentials and data and fights with NAT and firewalls. SFTP runs inside SSH on port 22, encrypted and easy to filter.

Exercise

Users suddenly cannot log in to Active Directory from one server, with Kerberos errors. Ping and DNS work. What should you check?

  1. The SNMP community string
  2. The MX record
  3. Whether the server’s clock has drifted, for example with chronyc tracking
  4. The MQTT broker
Show answer

Answer: C. Kerberos rejects tickets when clocks differ by more than five minutes by default. Fix NTP synchronization and logins return.

Key takeaways

  • Mail is sent with SMTP (25 between servers, 587 from clients) and read with IMAP or POP3.
  • SPF, DKIM and DMARC in DNS prove mail is genuine.
  • Prefer SFTP or rsync over SSH to FTP; keep TFTP and SMBv1 off untrusted networks.
  • LDAP, NTP and SNMP are infrastructure glue: encrypt LDAP, keep clocks synced, use SNMPv3.
  • MQTT, SIP and NNTP serve IoT, voice and newsgroups.

FAQ

Why does my cloud server fail to send mail on port 25?

Most cloud and residential providers block outbound port 25 to stop spam. Send through an email service on port 587 with authentication, or ask the provider to lift the block.

Is SCP still safe to use?

The scp command is fine for quick copies; since OpenSSH 9 it uses the SFTP protocol under the hood. For large or repeated transfers, rsync is more efficient.

What is the difference between SMB and NFS?

Both share files over the network. SMB is native to Windows and handles Windows users and permissions; NFS is native to Unix and Linux. Most NAS devices offer both.

Do I still need SNMP if I use Prometheus?

For servers, exporters cover it. For switches, routers, UPSs and printers, SNMP is often the only interface, and Prometheus collects it with the snmp_exporter.

↑ ↓ navigate Enter open Esc close