Networking Fundamentals

How Networks Actually Work

TCP/IP, OSI, DNS, ARP, and routing — the plumbing under every attack

15 min readUpdated 2026-04-18
#tcp-ip#osi#dns#arp#routing#protocols
TL;DR
  • Every network attack exploits a protocol — understanding protocols beats memorising tools
  • The OSI model is a mental map, not a rulebook; use it to reason about where in the stack something breaks
  • IP routes packets between networks; ARP resolves IPs to MAC addresses on the same network
  • DNS is one of the richest attack surfaces in any environment — and one of the most overlooked
  • TCP's three-way handshake is the basis for port scanning, session hijacking, and firewall evasion

The OSI Model — Your Mental Map

The OSI model describes network communication in 7 layers. You don't need to worship it — but you do need it to reason about where attacks happen.

7 · Application
HTTP, DNS, SMTP — the actual protocol
SQLi, XSS, credential theft
6 · Presentation
Encryption, encoding
SSL stripping, encoding tricks
5 · Session
Session management
Session hijacking, token theft
4 · Transport
TCP/UDP — ports, reliability
Port scanning, SYN floods
3 · Network
IP — routing between networks
IP spoofing, ICMP attacks
2 · Data Link
MAC addresses — same network delivery
ARP spoofing, VLAN hopping
1 · Physical
Cables, wireless signals
Wiretapping, RF jamming
How to use this

When something doesn't work — or when you're planning an attack — ask "which layer is this happening at?" That question focuses your diagnosis immediately.


IP Addresses — The Routing System

Every device on a network has an IP address. IPv4 uses 32 bits (192.168.1.1). IPv6 uses 128 bits (fe80::1).

Public vs Private

RangeClassCommon Use
10.0.0.0/8Class A privateLarge corporate networks
172.16.0.0/12Class B privateMedium networks
192.168.0.0/16Class C privateHome/small office
127.0.0.0/8LoopbackLocal machine only

Private IPs don't route over the internet. NAT (Network Address Translation) translates them to a public IP at the router.

Subnets and CIDR

192.168.1.0/24 means: 192.168.1.x where x is 0–255. The /24 is the subnet mask — it defines how many bits belong to the network vs the host.

bash
# See your IP and subnet
ip addr show
ip route show

# Calculate subnet ranges
ipcalc 192.168.1.0/24
Why this matters for hacking

Knowing the subnet tells you exactly how many hosts exist on the network. /24 = 254 hosts. /16 = 65,534 hosts. That shapes your scanning strategy.


TCP — The Reliable Transport

TCP (Transmission Control Protocol) guarantees delivery and ordering. It's used by HTTP, HTTPS, SSH, FTP, SMB — most of what you'll attack.

The Three-Way Handshake

TCP Three-Way Handshake
ClientServer
ClientServerSYN
ServerClientSYN-ACK
ClientServerACK
connection open
step 1SYNattackerClient sends SYN packet to port
step 2SYN-ACKserverOpen port responds
step 3ACKattackerConnection established
step 4Data ExchangeHTTP, SSH, SMB etc.

Nmap exploits this. A SYN scan (-sS) sends SYN and reads the response without completing the handshake:

  • SYN-ACK > port open
  • RST > port closed
  • No response > port filtered (firewall)

TCP Flags

FlagNameMeaning
SYNSynchroniseInitiate connection
ACKAcknowledgeConfirm receipt
RSTResetHard close connection
FINFinishGraceful close
PSHPushSend data immediately
URGUrgentPriority data

UDP — The Fire-and-Forget Transport

UDP (User Datagram Protocol) sends packets without waiting for acknowledgement. Faster, but unreliable.

Used by: DNS (port 53), DHCP (67/68), SNMP (161), NTP (123), VoIP, game servers.

TIP

UDP services are often forgotten during hardening. SNMP with default community strings (public, private) is a classic find during recon.


Ports — The Application Addressing System

Ports are 16-bit numbers (0–65535) that direct traffic to the right service on a host.

RangeNameWho uses it
0–1023Well-known portsSystem services (HTTP=80, SSH=22, HTTPS=443)
1024–49151Registered portsApplication servers
49152–65535Dynamic/ephemeralOS-assigned for outgoing connections

Most Important Ports to Know

PortProtocolServiceAttack relevance
21TCPFTPAnonymous login, cleartext creds
22TCPSSHBrute force, key exploitation
23TCPTelnetCleartext — sniff credentials
25TCPSMTPEmail relay, enumeration
53TCP/UDPDNSZone transfers, tunnelling
80TCPHTTPWeb application attacks
110TCPPOP3Email credential harvesting
139/445TCPSMBEternalBlue, Pass-the-Hash
443TCPHTTPSWeb + cert analysis
1433TCPMSSQLDB attacks, xp_cmdshell
3306TCPMySQLDB attacks
3389TCPRDPBrute force, BlueKeep
5985TCPWinRMPowerShell remoting
8080/8443TCPHTTP altDev servers, admin panels

ARP — Glue Between IP and MAC

ARP (Address Resolution Protocol) answers: "Who has IP 192.168.1.1? Tell me your MAC address."

Every device on the same network segment uses ARP before sending traffic. The responses are cached in an ARP table.

bash
# View your ARP table
arp -a
ip neigh show

ARP Spoofing — Why This Matters

ARP has no authentication. Anyone can send a gratuitous ARP reply claiming any IP. This is the basis for:

  • ARP Spoofing / Poisoning — tell host A you're the gateway; tell the gateway you're host A > MITM
  • Tool: arpspoof, ettercap, bettercap
bash
# Tell 192.168.1.5 that you are the gateway (192.168.1.1)
arpspoof -i eth0 -t 192.168.1.5 192.168.1.1
DANGER

ARP spoofing is noisy and detectable. Modern managed switches with Dynamic ARP Inspection (DAI) block it. Wireless networks with client isolation block it too.


DNS — The Internet's Phone Book

DNS resolves domain names to IP addresses. It runs on port 53, usually UDP (TCP for large responses or zone transfers).

DNS Record Types

RecordPurposeHacking value
ADomain > IPv4Maps hostnames to IPs
AAAADomain > IPv6IPv6 infrastructure discovery
CNAMEAlias > another domainSubdomain takeover opportunities
MXMail serverEmail infrastructure mapping
TXTArbitrary textSPF, DKIM, internal info leaks
NSName serverZone transfer targets
PTRIP > domain (reverse)Reverse DNS enumeration
SRVService locatorActive Directory service discovery

DNS Enumeration

bash
# Query specific record types
dig A target.com
dig MX target.com
dig TXT target.com
dig NS target.com

# Attempt zone transfer (dumps all records if misconfigured)
dig axfr @ns1.target.com target.com

# Reverse DNS lookup
dig -x 93.184.216.34

# Brute-force subdomains
gobuster dns -d target.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt
Zone Transfer — Easy Win

A zone transfer (AXFR) is supposed to be restricted to trusted secondary DNS servers. Misconfigured public DNS servers return the full zone — every hostname, IP, and record in the domain. Always try it.


Routing — How Packets Find Their Way

Routers forward packets between networks using routing tables. Each entry says: "for packets going to network X, send them out interface Y."

bash
# View routing table
ip route show
route -n       # older syntax

# Trace the path packets take
traceroute google.com
traceroute -T -p 443 google.com   # TCP traceroute (bypasses ICMP blocks)

Default Gateway

Your default gateway (0.0.0.0/0) is where packets go when no more specific route matches. In a pentest, compromising the gateway means all traffic flows through you.


ICMP — Network Diagnostics (and Recon)

ICMP (Internet Control Message Protocol) handles network error messages and diagnostics.

ICMP TypeNameUse
0Echo ReplyPing response
3Destination UnreachablePort/host not reachable
8Echo RequestPing
11Time ExceededTTL expired (traceroute uses this)
bash
ping -c 4 target.com
ping -c 1 -W 1 192.168.1.1   # Quick alive check
WARNING

Many firewalls block ICMP. A host that doesn't respond to ping might still be alive and running services. Always follow up failed pings with a port scan.


Practical: Reading a Packet Capture

Understanding packet structure lets you read Wireshark captures and tcpdump output fluently.

bash
# Capture all traffic on interface eth0
tcpdump -i eth0

# Capture only HTTP traffic
tcpdump -i eth0 port 80

# Save to file for Wireshark analysis
tcpdump -i eth0 -w capture.pcap

# Read a capture file
tcpdump -r capture.pcap

A packet = Headers + Payload. Each layer wraps the layer above:

  • Ethernet frame wraps > IP packet wraps > TCP segment wraps > HTTP data

Operational Notes

  • Subnetting in your head: /24 = 256 IPs, /25 = 128, /26 = 64, /27 = 32, /28 = 16. Halve it for each extra bit.
  • Wireshark filter syntax differs from tcpdump syntax — tcp.port == 80 vs port 80. Both are worth learning.
  • IPv6 is not optional — modern environments dual-stack. Many tools default to IPv4. Add -6 flags and check ::1 and fe80:: ranges.
  • DNS over HTTPS (DoH) breaks traditional DNS sniffing — traffic goes to port 443, not 53.

  • Linux Fundamentals for Hackers — everything here runs from a Linux terminal
  • Reconnaissance — apply this knowledge to systematically map a target's network
  • Network Traffic Analysis — go deeper into reading and interpreting captures