Subnetting, Ports and Common Services

Read CIDR notation, carve networks into subnets, and know the common ports and services you will see in scans and logs.

Beginner · about 5 hours · difficulty 2/5

Learn first: How the Internet and TCP/IP Work

Scope documents, firewall rules and scan targets are all written as network ranges. Service ports tell you what a machine is doing.

CIDR and subnetting

An IPv4 address is 32 bits. 10.0.5.0/24 means the first 24 bits are the network and the last 8 identify hosts: 256 addresses, 254 usable. A /16 holds 65,536 addresses; a /30 just 4. Private ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. You should be able to answer "is 10.0.6.20 inside 10.0.4.0/22?" quickly, because getting it wrong can mean scanning a system that is out of scope.

IPv6 uses 128-bit addresses and is increasingly common; attackers sometimes use it to bypass IPv4-only firewall rules.

Ports to know by heart

  • 22 SSH, 21 FTP, 23 Telnet (insecure), 25 SMTP
  • 53 DNS, 80 HTTP, 443 HTTPS, 123 NTP
  • 88 Kerberos, 389/636 LDAP, 445 SMB, 3389 RDP
  • 3306 MySQL, 5432 PostgreSQL, 6379 Redis, 27017 MongoDB

Seeing 3389 or 445 exposed to the internet is a serious finding: those services are frequent ransomware entry points. Databases should almost never be internet-facing.

Pitfalls

  • Assuming a service runs on its default port. Scanners detect the actual service, not just the number.
  • Forgetting that a /24 "network" and "broadcast" address are not usable hosts.

Move on when you can subnet a /24 into four equal parts, list the ranges, and name the service behind twenty common ports without looking.

Key concepts

  • Binary and CIDR notation
  • Subnet masks and host counts
  • Private address ranges
  • IPv6 basics
  • Well-known ports
  • Risky exposed services (RDP, SMB)

Mini project

Write a small script that takes a CIDR range and an IP and prints whether the IP is in range, the network address, broadcast address and host count.

Check yourself

How many usable hosts are in a /27, and why would an exposed port 445 worry you?

Free resources