TCP, UDP, DNS, HTTP, and TLS in Practice
Follow one request from port number to encrypted response: read TCP and UDP behaviour, DNS answers, HTTP messages, and TLS negotiation with command-line tools.
By the end, you’ll be able to…
- Identify common ports and the services that usually listen on them.
- Describe the TCP handshake and teardown, and explain when UDP is the better transport.
- Explain DNS record types and the recursive resolution path.
- Read HTTP methods, status codes, and security-relevant headers.
- Compare TLS 1.2 with TLS 1.3 and gather reproducible evidence with dig, curl, openssl s_client, and ss.
01Ports and Services: The Address Book of a Conversation
A port is a 16-bit number that tells a host which application should receive a packet. Ports 0 through 1023 are called well-known ports and are conventionally reserved for core services. Ports 1024 through 49151 are registered ports used by products and protocols. Ports 49152 through 65535 are dynamic or ephemeral ports that clients usually choose for their side of a conversation. A connection is identified by the five-tuple: source address, source port, destination address, destination port, and transport protocol.
These numbers are conventions, not proof of identity. An administrator can run a web server on port 2222, and malware can listen on port 443 to blend in. When you see port 443 open, you know which transport port answered; you do not yet know whether the service speaks TLS, which software is running, or whether it is trustworthy. Confirm the service with a version probe, a banner, or a protocol handshake before you write it in a report.
A small port map is worth memorising because it speeds up reading logs, firewall rules, and scan results. The table below lists the pairs you will meet most often. Treat the service column as a strong hint, never as a conclusion. A port is a door; the protocol behind the door is a separate question.
PORT/PROTOCOL TYPICAL SERVICE WHAT IT OFTEN REVEALS21/tcp FTP cleartext file transfer and credentials22/tcp SSH remote shell; version banner exposure25/tcp SMTP mail transfer between servers53/udp, 53/tcp DNS name resolution; TCP for large answers67, 68/udp DHCP address assignment on a local network80/tcp HTTP unencrypted web traffic123/udp NTP time synchronisation161/udp SNMP device management, often weak community strings389/tcp LDAP directory services443/tcp HTTPS HTTP inside TLS443/udp QUIC HTTP/3 and other QUIC services445/tcp SMB Windows file sharing3306/tcp MySQL database protocol3389/tcp RDP remote desktop5432/tcp PostgreSQL database protocol6379/tcp Redis in-memory data store8080/tcp HTTP alternate proxies, development servers02TCP: Handshake, Stream, and Teardown
TCP turns an unreliable packet network into an ordered byte stream. Before application data flows, the client sends a SYN segment with an initial sequence number. The server answers with SYN-ACK, acknowledging the client's sequence number and offering its own. The client sends ACK, and the connection is established. This three-way handshake proves that both sides can send and receive, and it establishes the sequence numbers used to detect loss, duplication, and reordering.
Closing a connection normally takes four steps because each direction closes independently: one side sends FIN, the other acknowledges it, then the second side sends its own FIN and receives the final ACK. The side that closes first waits in TIME-WAIT so late duplicate packets cannot confuse a new connection using the same port pair. An abrupt close uses RST, which is what a host sends when a port is closed or a connection is refused. RST is normal, but a flood of RSTs can indicate scanning, a middlebox policy, or a broken application.
For an analyst, TCP states and flags are a timeline. A firewall log that records only the first SYN shows an attempted connection, not a completed one. A server with many half-open connections may be under a SYN flood. Retransmissions suggest packet loss or a path problem, while repeated zero-window advertisements suggest a slow reader. The ss command shows the local view of sockets, their states, and, with privilege, the owning process.
# Listening sockets and the processes that own them.sudo ss -tulpn# All TCP sockets with state and timers.ss -tan# Watch established connections appear and disappear.watch -n 2 "ss -tan state established"State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 511 127.0.0.1:3000 0.0.0.0:* ESTAB 0 0 10.10.10.20:51342 203.0.113.10:443 TIME-WAIT 0 0 10.10.10.20:51880 203.0.113.10:443
03UDP: Stateless, Fast, and Easy to Spoof
UDP is a thin wrapper around IP. Its header contains source port, destination port, length, and checksum, and that is essentially all. There is no handshake, no acknowledgement, no retransmission, and no ordering. An application that uses UDP must provide any reliability it needs, or accept that some messages will be lost. The trade-off buys low latency and low overhead, which matters for short request-response exchanges and real-time media.
DNS queries normally use UDP port 53 because a question and answer usually fit in one packet and a retry is cheaper than a handshake. DHCP uses UDP 67 and 68 because clients do not yet have an address and need to broadcast. NTP uses UDP 123 to keep time synchronisation cheap. Voice and video use RTP over UDP because a late packet is less useful than a missing one. QUIC, the transport behind HTTP/3, runs over UDP 443 and implements its own congestion control and reliability in user space.
UDP's lack of a handshake also makes source-address spoofing easy. An attacker can send a query with a forged source address and make a server send a large reply to the victim, which is the basis of reflection and amplification attacks. Defenders should rate-limit UDP services, disable unnecessary ones, and validate that replies are proportional to requests. When scanning UDP, expect ambiguity: no reply can mean the port is open and filtered, or the service simply does not answer unrecognised packets.
04DNS: Records, Resolvers, and the Resolution Chain
DNS is a distributed database organised as a tree. A stub resolver on your machine asks a recursive resolver, often provided by your ISP, your router, or a public service. If the answer is not cached, the recursive resolver walks from the root servers to the top-level domain servers and then to the authoritative name servers for the domain. The authoritative server returns the record, and the recursive resolver caches it for the number of seconds in the TTL field.
The record types you will meet most often are A for IPv4, AAAA for IPv6, CNAME for an alias, MX for mail exchangers, TXT for arbitrary text such as SPF and domain verification, NS for the delegated name servers, SOA for zone authority and timing, PTR for reverse lookups, SRV for service location, and CAA for which certificate authorities may issue certificates. A single name can have several records, and a CNAME can point to another name that resolves through several more hops.
DNS evidence is valuable because it is a timestamped record of intent. A query for a newly registered lookalike domain, a burst of TXT queries with long encoded names, or a sudden change in an A record can each be the first visible sign of an attack. Encrypted DNS such as DNS over HTTPS and DNS over TLS protects privacy but removes that visibility from the network, so endpoint and resolver logs become more important.
# Ask for the address records and show the full response.dig example.com A# Ask a specific resolver and show only the answer.dig @1.1.1.1 example.com A +short# Follow the delegation chain from the root.dig +trace example.com A;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41237 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; QUESTION SECTION: ;example.com. IN A ;; ANSWER SECTION: example.com. 300 IN A 203.0.113.10
05HTTP: Intent, Outcome, and Context in the Headers
HTTP is a request-response protocol. A request starts with a method and a target, followed by headers and an optional body. A response starts with a status code and reason phrase, followed by headers and an optional body. Methods carry intent: GET retrieves, HEAD retrieves headers only, POST submits data or creates a resource, PUT replaces, PATCH partially updates, DELETE removes, and OPTIONS asks what is allowed. GET and HEAD are meant to be safe, meaning they should not change state; badly designed applications violate that expectation all the time.
Status codes are grouped by purpose: 1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error. Common examples include 200 OK, 204 No Content, 301 Moved Permanently, 302 Found, 304 Not Modified, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 405 Method Not Allowed, 429 Too Many Requests, 500 Internal Server Error, 502 Bad Gateway, and 503 Service Unavailable. The distinction between 401 and 403 matters during testing: 401 means authentication is missing or failed, while 403 means the server understood the identity but refused the action.
Headers carry the context that turns a URL into a meaningful request. Host selects the virtual host. User-Agent identifies the client, though it can claim anything. Cookie carries session state. Authorization carries credentials, which is why cleartext HTTP is dangerous. Content-Type describes the body. On the response side, Strict-Transport-Security asks browsers to use HTTPS in future, Content-Security-Policy restricts resource loading, Set-Cookie can mark a cookie Secure, HttpOnly, and SameSite, and Cache-Control decides whether sensitive content may be stored. Inspect headers with curl rather than relying on the rendered page.
GET /account HTTP/1.1Host: shop.example.comUser-Agent: Mozilla/5.0Accept: text/htmlCookie: session=abc123HTTP/1.1 200 OKContent-Type: text/html; charset=UTF-8Strict-Transport-Security: max-age=31536000Content-Security-Policy: default-src 'self'Cache-Control: no-storeSet-Cookie: session=abc123; Secure; HttpOnly; SameSite=Lax06TLS 1.2 and TLS 1.3: Encryption With an Identity Check
TLS has three jobs: keep the conversation confidential, detect tampering, and let the client verify that it is talking to the server named in the URL. The handshake negotiates a protocol version and cipher suite, authenticates the server with a certificate, and derives shared session keys. The certificate binds a public key to names, and the chain links that certificate to a root authority that the client already trusts.
TLS 1.2 needs two round trips for a full handshake and allows a wide range of cipher suites, including older constructions that are now deprecated. TLS 1.3 reduces the full handshake to one round trip, removes static RSA key exchange and legacy ciphers, requires forward secrecy for the main handshake, and encrypts more of the handshake, including the server certificate. Both versions support session resumption, and TLS 1.3 adds 0-RTT data, which is faster but replayable and should be limited to idempotent requests.
TLS protects bytes in transit; it does not protect the application. A valid certificate does not mean the site is honest or free of vulnerabilities, and it does not hide the destination IP, the volume of traffic, or, in most deployments, the server name sent in the SNI extension. Encrypted Client Hello can hide that name from the network, but endpoints still see it. For investigations, the certificate, negotiated version, cipher, and timing are evidence about the connection, not about the content.
# Show the negotiated protocol, cipher, and certificate chain.openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null 2>/dev/null# Test whether the server accepts each protocol version.openssl s_client -connect example.com:443 -servername example.com -tls1_2 </dev/null 2>/dev/null | grep -E "Protocol|Cipher"openssl s_client -connect example.com:443 -servername example.com -tls1_3 </dev/null 2>/dev/null | grep -E "Protocol|Cipher"# Inspect the leaf certificate.openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates -ext subjectAltNameProtocol : TLSv1.3
Cipher : TLS_AES_256_GCM_SHA384
subject=CN = example.com
issuer=C = US, O = Example CA, CN = Example CA R1
notBefore=Jan 1 00:00:00 2026 GMT
notAfter=Apr 1 00:00:00 2026 GMT
X509v3 Subject Alternative Name:
DNS:example.com, DNS:www.example.com07What Each Protocol Reveals to an Analyst
Each protocol gives the analyst a different slice of the story. Port numbers reveal which service was contacted. TCP flags and sequence behaviour reveal whether a connection opened, stalled, or was refused. DNS reveals names and resolution timing. HTTP reveals methods, hosts, paths, user agents, and cookies when it is not encrypted. TLS reveals the server name from SNI, certificate details in a TLS 1.2 handshake, the negotiated version, and the amount of data exchanged.
None of these views is complete. A proxy or content delivery network hides the origin. NAT hides the internal client. DNS over HTTPS hides queries from the network. TLS 1.3 with Encrypted Client Hello hides the requested name. A compromised endpoint can generate perfectly valid encrypted traffic to a malicious server. The analyst's job is to combine independent sources and state the limits of each one.
The practical habit is to timestamp everything and keep the raw output. Record the source host, resolver, interface, command, and time zone. A screenshot of a browser page is not evidence that a connection used TLS 1.3 or that a certificate was valid. A terminal transcript with the command and the response is reproducible, and reproducibility is what makes an observation useful to another person.
PROTOCOL USEFUL EVIDENCE BLIND SPOTSTCP endpoints, ports, flags, retransmits payload, user identityUDP endpoints, packet sizes, timing delivery, orderingDNS queried name, record, resolver, TTL DoH/DoT payloads, cache contentsHTTP method, host, path, headers, cookies body of HTTPS trafficTLS SNI, certificate, version, cipher plaintext after encryptionThe ideas worth keeping.
- Port numbers are conventions that identify a transport endpoint, not proof of the service or its safety.
- TCP provides ordered delivery through a handshake and tracked state; UDP trades reliability for latency and is easier to spoof.
- DNS resolution is a chain of cached answers, and its records and timing are valuable evidence.
- HTTP headers and TLS metadata reveal a lot about a connection while leaving application content and identity questions open.
Make it yours.
Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.
Exercise 1: Read a connection from three angles
Three commands produce the following results. First, dig example.com A returns 203.0.113.10 with TTL 60. Second, ss -tan shows an ESTAB connection from 10.10.10.20:51342 to 203.0.113.10:443. Third, openssl s_client reports Protocol TLSv1.3, Cipher TLS_AES_256_GCM_SHA384, and a certificate for example.com that expires in six days. State what each result proves, what none of them proves, and one check you would perform next.
Explore a worked solution
The dig result proves that the resolver returned an A record for example.com with address 203.0.113.10 and a 60-second TTL at that moment; it does not prove that the address is the real or only origin. The ss result proves that a local TCP socket was established to that address on port 443; it does not prove which application used it or that the traffic was HTTP. The openssl result proves that the server presented a certificate for example.com that this client accepted, and that TLS 1.3 with that cipher was negotiated. None of the results proves that the site is trustworthy, that the application is secure, or that the content was not modified after decryption. Next, verify the certificate chain and expiry, compare the certificate issuer and SAN with the expected deployment, and check whether the connection is proxied or load-balanced.Each tool answers a different question. Combining them gives a stronger story, but you must keep the limits of each observation explicit.
Exercise 2: Diagnose an unexpected listener
A lab server shows tcp LISTEN 0.0.0.0:6379 owned by redis-server and tcp LISTEN 127.0.0.1:5432 owned by postgres. Explain the exposure difference, the risk you would investigate first, and two checks you would run before changing anything.
Explore a worked solution
Redis is listening on every IPv4 interface, so any host that can route to this server may reach port 6379. Postgres is bound to loopback, so only processes on the server can connect directly. The first risk is an unauthenticated or weakly configured Redis service exposed to the lab network, because Redis is often deployed without authentication and can be abused to read or modify data. Checks: run ss -tulpn to confirm the process and bind address, inspect the Redis configuration for bind and requirepass or ACL settings, check host and network firewall rules with ufw status or iptables -S, and test reachability from a second lab VM with a simple TCP connection. Do not expose the service to the internet, and snapshot the VM before changing configuration.Bind address is an exposure boundary. Loopback is narrower, but it is not a security control against local compromise. Verify the service configuration and the firewall, not just the port list.
What stayed with you?
Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.
Keep exploring.
The official references behind this lesson, when you want a second angle or the full details.
One lesson closer.
Reading is a start. Trying it yourself makes the connection.