Find a course

Module 4: Networks and EncryptionLesson 7 of 1213 min

How Networks Work

Understand IP addresses, subnets, ports, TCP and UDP, and DNS well enough to see where attacks happen and what defenders watch.

Step 1 of 11Learn

Addresses for machines

You can't defend a network you don't understand, so let's follow what happens when you open a website.

Every device on a network has an IP address. The older and still most common version, IPv4, writes addresses as four numbers from 0 to 255, like 192.168.1.20. That's 32 bits in total, giving about 4.3 billion possible addresses, which isn't enough for every device on Earth. The newer IPv6 uses 128-bit addresses written in hexadecimal, like 2001:db8::1, with an almost unlimited supply.

To stretch IPv4, homes and offices use private address ranges that are not routed on the public internet: 10.0.0.0 to 10.255.255.255, 172.16.0.0 to 172.31.255.255, and 192.168.0.0 to 192.168.255.255. Your router uses network address translation (NAT) to let all your devices share one public IP address.

A subnet is a block of addresses that belong together. In the common notation 192.168.1.0/24, the "/24" means the first 24 bits identify the network, leaving 8 bits, or 256 addresses, for devices (254 usable, because the first and last are reserved). A /16 leaves 16 bits, or 65,536 addresses.

Why security people care: IP addresses appear in every firewall rule and every log file. When an alert says "10.0.4.17 connected to 203.0.113.50 on port 443," you need to recognize that the first is an internal device and the second is somewhere out on the internet.

Step 2 of 11Practice · Sort into groups

Is each IPv4 address private (internal only) or public?

Tap an item, then tap its group (or drag it there).

Step 3 of 11Practice · Work it out

How many total addresses are in a /26 subnet? (IPv4 addresses have 32 bits.)

Step 4 of 11Practice · Chart

Addresses in a subnet by prefix length

Each extra prefix bit halves the block: total addresses = 2^(32 − prefix). In a typical subnet two of them (network and broadcast) cannot be assigned to devices.

A team needs about 100 device addresses in one subnet. Tap the smallest prefix that fits.

Tap the bar that answers the question, then press Check.

Addresses in a subnet by prefix lengthBar chart with 7 categories: /22: 1,024; /23: 512; /24: 256; /25: 128; /26: 64; /27: 32; /28: 16.02505007501,0001,250Total addresses/22/23/24/25/26/27/28Prefix1,024512256128643216
Addresses in a subnet by prefix length
PrefixAddresses
/221,024
/23512
/24256
/25128
/2664
/2732
/2816

Step 5 of 11Learn

Ports, TCP and UDP

An IP address gets data to the right machine. A port number gets it to the right program on that machine. Ports run from 0 to 65535, and well-known services use standard ones: a web server listens on 443 for HTTPS, a mail server on 25 for SMTP. Think of the IP address as a building's street address and the port as the apartment number.

Data travels using one of two main transport protocols:

  • TCP (Transmission Control Protocol) is reliable. It starts with a three-way handshake (SYN, SYN-ACK, ACK), numbers every piece of data, resends anything lost and delivers it in order. Web pages, email and file transfers use TCP.
  • UDP (User Datagram Protocol) just sends packets with no handshake and no guarantee of delivery. It's faster and lighter, so it suits video calls, online games, streaming and DNS lookups, where speed matters more than a perfect delivery of every packet.

Attackers use ports for reconnaissance. A port scan checks which ports on a machine accept connections, revealing which services are running and possibly which software versions. An open port isn't automatically a vulnerability, but every open port is a service that must be patched and configured correctly. Exposing remote desktop (port 3389) or database ports directly to the internet is a classic, frequently exploited mistake.

Step 6 of 11Practice · Match the pairs

Match each well-known port to its service.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. 22
  2. 53
  3. 80
  4. 443
  5. 25
  6. 3389

Step 7 of 11Learn

DNS: the internet's phone book

People remember names like example.com; computers need IP addresses. The Domain Name System (DNS) translates one into the other.

When you type a web address, your device asks a DNS resolver, usually run by your internet provider or a public service. If the resolver doesn't have the answer cached, it asks the root servers, then the servers for the top-level domain (.com), then the domain's own authoritative servers, and returns the IP address. This usually takes a fraction of a second, and the answer is cached for a time.

DNS matters for security in several ways:

  • DNS spoofing or cache poisoning: tricking a resolver into giving out a false address, sending users to an attacker's server. DNSSEC adds digital signatures to DNS records to detect tampering.
  • Look-alike domains: attackers register names such as examp1e.com or example-login.com for phishing.
  • Malware communication: infected machines often look up the attacker's command server by name, so DNS logs are a goldmine for spotting infections. Some organizations block known malicious domains at the resolver.
  • Privacy: traditional DNS queries travel unencrypted, so anyone on the network path can see which sites you look up. DNS over HTTPS (DoH) and DNS over TLS encrypt them.

When a whole set of websites suddenly stops working, experienced engineers have a saying: it's always DNS. For defenders, it's also often where the first clue of an attack shows up.

Step 8 of 11Practice · Diagram

A DNS lookup when nothing is cached

Cache poisoning feeds a false answer to one box so that all its users are misled. Which box?

Tap the shape that answers the question, then press Check.

A DNS lookup when nothing is cachedProcess diagram: Your device asks → DNS resolver → Root server → .com servers → Authoritative server.Your device asksDNS resolverRoot server.com serversAuthoritative server
Your device asks

The question: what is the IP address of example.com?

DNS resolver

Usually your provider or a public service; it answers from cache when it can.

Root server

Points to the servers responsible for .com.

.com servers

Point to example.com’s authoritative name servers.

Authoritative server

Gives the real answer, which the resolver caches and returns.

Step 9 of 11Tap to reveal

The layers of a network connection

  1. Application layer

    The protocols programs speak: HTTP for the web, SMTP for email, DNS for name lookups, SSH for remote administration. Most attacks people hear about target this layer.

  2. Transport layer

    TCP and UDP, which use port numbers to deliver data to the right program and, for TCP, guarantee reliable delivery.

  3. Internet layer

    IP addressing and routing, which move packets between networks across the world, hop by hop through routers.

  4. Link layer

    The local hop over Ethernet cables or Wi-Fi radio, using hardware MAC addresses. Attacks here include rogue access points and spoofing devices on the same local network.

Step 10 of 11Practice · Put in order

Put the steps of loading https://example.com in a sensible order.

Drag the items, or use the arrow buttons, to put them in order.

  1. Your browser opens a TCP connection to that IP on port 443
  2. TLS sets up an encrypted session
  3. The browser sends the HTTP request and receives the page
  4. The resolver returns the site's IP address
  5. Your device asks a DNS resolver for example.com

Step 11 of 11Practice · Choose one

Which transport protocol would a live video call most likely use for its audio and video stream, and why?