TCP/IP for Security: Ports, Protocols, and Encapsulation
Understand how TCP/IP works from a security perspective: the three-way handshake, ports, public versus private IP addresses, and why encapsulation matters.
TCP/IP is the language every device on the internet uses to talk to one another. To understand network security, you first need to understand how TCP/IP works, because nearly every attack exploits the way it operates.
The TCP/IP Model in Four Layers
| Layer | Role | Example Protocols |
|---|---|---|
| Application | Data that users understand | HTTP, HTTPS, DNS, SSH |
| Transport | Manages delivery between applications | TCP, UDP |
| Internet | Routing | IP, ICMP |
| Network Access | Physical connection between devices | Ethernet, WiFi |
When you open a website, data flows from the application layer, is wrapped (encapsulated) by each layer, sent over the wire, and then unwrapped again on the receiving side.
IP Addresses and Ports
Public and Private IPs
- Public IP: an address visible from the internet, unique worldwide.
- Private IP: an internal network address (for example: 192.168.x.x, 10.x.x.x, 172.16-31.x.x), which cannot be used directly from the internet without NAT.
Most homes have a single public IP for the entire network, with many devices using private IPs behind it. This in itself is a basic form of protection: internal devices are not directly reachable from the internet.
Ports
A port is a “cabinet” inside an IP address. One device can run many services, and ports distinguish one service from another. Common examples:
| Port | Service |
|---|---|
| 21 | FTP (insecure) |
| 22 | SSH |
| 25 | SMTP (outgoing email) |
| 80 | HTTP (insecure) |
| 443 | HTTPS |
| 3389 | Remote Desktop (Windows) |
Every open port is a door. The more doors, the larger the attack surface. The basic rule of security: close all ports, open only the ones you need.
Transport: TCP and UDP
TCP
TCP guarantees that data arrives intact and in order. Every TCP connection begins with a three-way handshake:
Client → Server: SYN
Server → Client: SYN-ACK
Client → Server: ACK
This handshake is the target of several types of attacks (for example SYN flood, which will be covered in the DDoS article). Security scanners exploit it to detect open ports: if the server replies with SYN-ACK, that port is alive.
UDP
UDP is lighter, with no acknowledgement of receipt. It is a good fit for video, games, and DNS. Because there is no handshake, spoofing is harder to detect with UDP, and it is frequently abused for reflection (amplification) attacks.
Encapsulation: Why Does It Matter for Security?
Suppose you send the message “hello” over HTTPS. Layer by layer:
[Ethernet header][IP header][TCP header][TLS header]["hello"]
Each header contains control information: where to, from where, which port, and so on. Attacks often work by manipulating these headers: writing a fake address (spoofing), changing the port, or fragmenting data so it slips past filters.
Encryption happens at the application layer (TLS). Only the message contents are encrypted, not the headers. That is why an eavesdropper can tell that you are visiting site X (from the IP address), but cannot read the contents of the page being sent.
Exercise
- Look at the open ports on your machine with the following command in PowerShell:
netstat -ano | findstr LISTENING
- Note the ports that appear and find out which service is behind each one.
- Open your browser to your public IP address, but do not do anything yet. Watch the router logs for any incoming probing.
Next in the curriculum: after understanding protocols, learn how to read network traffic with Wireshark for beginners.
References
- RFC 791, Internet Protocol, rfc-editor.org/rfc/rfc791 (IP specification).
- RFC 793, Transmission Control Protocol, rfc-editor.org/rfc/rfc793 (TCP and the three-way handshake).
- RFC 768, User Datagram Protocol, rfc-editor.org/rfc/rfc768 (UDP).
- James Kurose and Keith Ross, Computer Networking: A Top-Down Approach, Pearson (a thorough explanation of the TCP/IP model).
- RFC 1918, Address Allocation for Private Internets, rfc-editor.org/rfc/rfc1918 (private IPs).
Related Articles
Introduction to SSH: What It Is, How It Works, and Why Every Server Uses It
Learn SSH from scratch: its brief history, the transport protocol and cryptography, how it differs from telnet, and your first remote server login.
NetworkingWiFi Security: WPA2, WPA3, 802.1X, and Rogue AP
Secure wireless networks: strengths and weaknesses of WPA2 through WPA3, enterprise 802.1X, how to detect rogue access points, and safe home WiFi practices.
NetworkingTLS, IPsec, and VPN: Network Traffic Encryption
How TLS, IPsec, and VPNs protect data in transit: TLS handshake, tunnels, when to use what, and common homelab mistakes.
Your ideas deserve to be read by thousands of people.
ByteNesia is built for everyone. If you have experience, tutorials, or opinions about technology, write and share them here. Your name will be credited as a contributor.
Write anything: tool reviews, homelab tutorials, security tips, or your tech stories.