Part 4 · The web and everyday protocols

Email, SSH, NTP and WebRTC: other protocols you should know

lesson 11 / 1915 min1 labpublished updated
Course contents
On this page
  1. Email: SMTP, IMAP and sender authentication
  2. SSH: a secure shell and an all-purpose tunnel
  3. NTP: why time matters to the network
  4. Management and infrastructure protocols
  5. Messaging and IoT
  6. Real time: RTP, SIP, WebRTC and NAT traversal

You now know the protocols behind a web page: DNS, TCP, TLS and HTTP. This lesson is a guided tour of the other protocols you’ll run into. Don’t try to memorize it. For each protocol, take away what it’s for, whether it runs over TCP or UDP, and its port, so that when you meet it in a firewall rule, a config file or a tcpdump capture, you recognize it. The tables near the end are reference material to come back to.

Beyond DNS, HTTP and TLS, a handful of protocols show up in almost every engineer’s work: SMTP and IMAP move email, SSH gives you a secure shell and tunnels, NTP keeps clocks in sync, and RTP, SIP and WebRTC carry real-time audio and video. Along the way you will also meet the management, directory and messaging protocols, and the ports you should recognize on sight.

Email: SMTP, IMAP and sender authentication

The path of an email:

  1. Your email program (the MUA, mail user agent) hands the message to your own outgoing server with SMTP, on port 587 (submission with STARTTLS) or 465 (direct TLS), always with authentication.
  2. Your server (the MTA, mail transfer agent) looks up the recipient domain’s MX record in DNS and delivers the message to that server with SMTP on port 25 (server to server).
  3. The recipient reads the message with IMAP (port 143 with STARTTLS, or 993 with TLS) or POP3 (110 and 995).

Like HTTP/1.1, SMTP is a text protocol: the client sends commands and the server answers with numeric codes.

C: EHLO client.example
S: 250-mx.example.net ... 250 STARTTLS
C: MAIL FROM:<a@example.com>
S: 250 OK
C: RCPT TO:<b@example.net>
S: 250 OK
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: Subject: hi ... (message) ... .
S: 250 Queued
C: QUIT

SMTP originally had no sender authentication at all: anyone could write MAIL FROM:<ceo@bank.com>. Three layers of defense are close to mandatory today (Gmail and Yahoo made them a requirement for bulk senders in 2024):

  • SPF (a TXT record): which IPs may send email for this domain. v=spf1 include:_spf.google.com -all
  • DKIM: the sending server signs the headers and the body, and the public key lives in DNS at selector._domainkey.example.com.
  • DMARC (a TXT record at _dmarc.example.com): what to do when SPF or DKIM doesn’t align with the From domain (p=none, quarantine, reject), and where to send reports.
  • Also: a correct PTR record for the server’s IP, plus MTA-STS and TLS-RPT to enforce TLS between servers.
  • Cloud providers usually block outbound port 25 to fight spam. To send email from the cloud, use a service such as SES, SendGrid or Postmark on port 587.

SSH: a secure shell and an all-purpose tunnel

SSH (port 22, RFC 4251 to 4254) has three layers: transport (key exchange, encryption, and server authentication with the host key), user authentication (public key, password, certificate), and connection (many channels over one connection: shell, command execution, SFTP, port forwarding).

  • On the first connection, SSH shows you the host key’s fingerprint and saves it in ~/.ssh/known_hosts. If it changes later, the REMOTE HOST IDENTIFICATION HAS CHANGED warning means either the server was replaced or someone is attempting a MITM attack. Don’t ignore it.
  • Generate keys with ssh-keygen -t ed25519, and turn off password authentication on servers.
  • In organizations, SSH certificates (an internal CA for user and host keys) make management much simpler than copying authorized_keys files around.

Port forwarding: three kinds of tunnel

# Local forward: localhost:5433 on YOUR machine -> db.internal:5432 as seen from the bastion
ssh -L 5433:db.internal:5432 user@bastion.example.com
# Remote forward: port 8080 on the SERVER -> localhost:3000 on your machine (expose a dev server)
ssh -R 8080:localhost:3000 user@server.example.com
# Dynamic forward: a SOCKS5 proxy on localhost:1080 that exits from the server
ssh -D 1080 user@server.example.com
# Jump through a bastion host to an internal machine
ssh -J user@bastion.example.com user@10.0.3.17

To avoid typing the jump every time, put it in your SSH config:

# ~/.ssh/config
Host bastion
  HostName bastion.example.com
  User deploy
Host db-*
  ProxyJump bastion
  User admin

NTP: why time matters to the network

NTP (UDP port 123, RFC 5905) keeps the system clock in sync to within milliseconds. A wrong clock means TLS certificates that are “not yet valid” or “expired”, rejected Kerberos tickets and JWTs, logs from different systems that can’t be compared, and distributed databases that behave strangely. Servers should run chronyd or systemd-timesyncd, and cloud providers offer a local NTP server (for example 169.254.169.123 on AWS). For microsecond accuracy, there is PTP (IEEE 1588).

Management and infrastructure protocols

These run inside companies and data centers. Skim the table now; come back to it when you meet one of them.

ProtocolPortPurpose
SNMPUDP 161 (traps on 162)Device stats and status; v3 adds authentication and encryption, v1/v2c have only a “community string”
SyslogUDP/TCP 514 (TLS on 6514)Sends logs to a central server
NetFlow / IPFIX / sFlowUsually UDP 2055, 4739, 6343Traffic flow summaries (who talked to whom, how much) for monitoring and security
LDAP / LDAPS389 / 636Directory of users and groups (Active Directory, OpenLDAP)
Kerberos88Ticket-based authentication in Active Directory
RADIUSUDP 1812, 1813Network authentication: enterprise Wi-Fi, VPN, 802.1X
SMBTCP 445Windows file sharing; never expose it to the Internet
NFSTCP 2049File sharing on Unix and Linux
FTP21 (plus data ports)Old and unencrypted; use SFTP (over SSH) or HTTPS instead
TFTPUDP 69Simple file transfer; network boot (PXE)

Messaging and IoT

  • MQTT (1883, or 8883 over TLS; an OASIS standard): lightweight publish/subscribe for IoT, with QoS levels 0, 1 and 2 and retained messages.
  • AMQP (5672): RabbitMQ’s protocol.
  • Kafka (9092): its own binary protocol over TCP.
  • CoAP (UDP 5683): a lightweight HTTP for small devices.

Real time: RTP, SIP, WebRTC and NAT traversal

  • RTP and SRTP carry audio and video over UDP (low latency matters more than reliability), with RTCP for quality statistics.
  • SIP (5060 and 5061): signaling for VoIP calls.
  • WebRTC: voice calls, video calls and data channels directly between browsers, without a server in the middle. Audio and video travel over SRTP; the data channels use their own small transport protocol on top of UDP, encrypted with DTLS (TLS adapted for UDP).

The main obstacle to a direct connection between two devices is NAT. The solution comes in three pieces:

  • STUN (port 3478): the device asks a public server, “What is my public IP and port as seen from outside?”
  • ICE: both sides exchange all their “candidates” (local address, public address from STUN, relay address) and try every pair. Usually UDP hole punching finds a direct path.
  • TURN: if no direct path works (for example, behind a strict firewall, or a NAT that picks a different public port for every destination, which defeats hole punching), the traffic is relayed through an intermediate server. Expensive, but it always works.

The same techniques are behind mesh VPNs such as Tailscale and peer-to-peer online games.