Networking for Security: TCP/IP, Ports, DNS and Wireshark Practice
You cannot secure what you do not understand, and almost every cyber attack travels over a network. Networking knowledge is the single most useful foundation for a security career. This lesson explains how data moves, what each layer does and where security problems appear, and then lets you see real traffic with Wireshark in your own lab.
The OSI and TCP/IP Models
Network communication is organised into layers, each with a job. The OSI model has seven layers; the TCP/IP model that the internet actually uses has four.
| OSI layer | TCP/IP layer | Function | Examples | Typical security issues |
|---|---|---|---|---|
| 7 Application | Application | User-facing services | HTTP, DNS, SMTP, SSH | Injection, weak authentication, misconfiguration |
| 6 Presentation | Data formats, encryption | TLS, character encoding | Weak ciphers, bad certificates | |
| 5 Session | Session management | Session tokens, RPC | Session hijacking | |
| 4 Transport | Transport | End-to-end delivery | TCP, UDP | Port scanning, SYN floods |
| 3 Network | Internet | Addressing and routing | IP, ICMP | Spoofing, routing attacks |
| 2 Data link | Network access | Local delivery | Ethernet, Wi-Fi, ARP, MAC | ARP spoofing, MAC flooding |
| 1 Physical | Signals and cables | Cables, radio | Tapping, jamming |
A handy memory aid for the OSI layers from the bottom up: Please Do Not Throw Sausage Pizza Away.
Encapsulation
When you load a web page, your data is wrapped at each layer: the application creates an HTTP request; TCP adds port numbers and sequencing (a segment); IP adds source and destination addresses (a packet); Ethernet adds hardware addresses (a frame). The receiver unwraps in reverse. Security devices work at different layers: switches at layer 2, routers and basic firewalls at layers 3 and 4, web application firewalls at layer 7.
IP Addressing and Subnets
An IPv4 address has 32 bits, written as four numbers, such as 192.168.56.101. A subnet mask or CIDR prefix such as /24 says which part is the network and which part is the host. A /24 network has 256 addresses (254 usable hosts).
| CIDR | Mask | Addresses | Use |
|---|---|---|---|
| /32 | 255.255.255.255 | 1 | A single host |
| /30 | 255.255.255.252 | 4 (2 usable) | Point-to-point links |
| /24 | 255.255.255.0 | 256 | Typical small network |
| /16 | 255.255.0.0 | 65,536 | Large network |
Private ranges (not routable on the internet): 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. Your home router uses NAT to let many private addresses share one public address. IPv6 uses 128-bit addresses and increasingly matters; security teams must secure both.
Ports and Protocols
An IP address finds a machine; a port finds a service on it. Ports range from 0 to 65535.
| Port | Protocol | Service | Security note |
|---|---|---|---|
| 20/21 | TCP | FTP | Cleartext; prefer SFTP |
| 22 | TCP | SSH | Use keys, restrict access |
| 23 | TCP | Telnet | Cleartext; should be disabled |
| 25 | TCP | SMTP | Mail transfer; abused for spam |
| 53 | UDP/TCP | DNS | Often abused for tunnelling and spoofing |
| 80 | TCP | HTTP | Cleartext web |
| 110/143 | TCP | POP3/IMAP | Prefer encrypted variants |
| 443 | TCP | HTTPS | Encrypted web |
| 445 | TCP | SMB | File sharing; should not be exposed to the internet |
| 3306 | TCP | MySQL | Databases should not face the internet |
| 3389 | TCP | Remote Desktop | Frequent target; protect with MFA and a gateway |
TCP vs UDP
TCP is connection-oriented and reliable. It begins with a three-way handshake: the client sends SYN, the server replies SYN-ACK, the client replies ACK. UDP is connectionless and faster but offers no delivery guarantees; DNS and streaming commonly use it. Many scanning and flooding techniques are variations on abusing the handshake, which is why you must understand it.
Key Supporting Protocols
- ARP maps IP addresses to hardware (MAC) addresses on a local network. It has no authentication, which is why local-network attacks exist. Defences are covered in Network Attacks and Defences.
- DHCP hands out IP addresses automatically. A rogue DHCP server can misdirect clients.
- DNS translates names to addresses. Attacks target its trust model (spoofing, poisoning, tunnelling).
- ICMP supports diagnostics such as
ping; attackers use it for discovery and sometimes covert channels. - HTTP/HTTPS carries web traffic; HTTPS adds TLS encryption (see PKI, Certificates and TLS).
Common Network Devices
- Switch: forwards frames inside a network based on MAC addresses.
- Router: connects networks and forwards packets between them.
- Firewall: permits or blocks traffic by rules.
- Proxy / reverse proxy / load balancer: intermediaries that handle traffic on behalf of clients or servers.
- VPN gateway: creates encrypted tunnels across untrusted networks.
- IDS/IPS: inspect traffic for malicious patterns; see Firewalls, IDS/IPS and Segmentation.
Practice Lab: Seeing Traffic With Wireshark
Wireshark is a free packet analyser. Use it only on your own lab network or home network.
- Install Wireshark on your analyst VM and start capturing on the host-only interface (
eth1or similar). - In a second terminal, run the commands below, then stop the capture.
ping -c 3 192.168.56.102
dig example.com
curl -I http://192.168.56.102/
Now use display filters in the filter bar:
icmp # ping traffic
dns # DNS queries and answers
http # unencrypted web traffic
tcp.flags.syn == 1 && tcp.flags.ack == 0 # first packet of new TCP connections
ip.addr == 192.168.56.102 # everything to or from one host
tcp.port == 443 # HTTPS traffic
Observe:
- Find the TCP three-way handshake for the
curlrequest (SYN, SYN-ACK, ACK). Right-click a packet and choose Follow, TCP Stream to view the conversation. - Find the DNS query and its answer. Which server answered?
- If you log in to a practice app such as DVWA over plain HTTP in your lab, use Follow TCP Stream to see how the username and password travel in cleartext. This one exercise explains why HTTPS matters more than any lecture.
- Repeat with an HTTPS site and notice that the content is encrypted.
Everyday commands to pair with Wireshark
ip neigh # ARP/neighbour table: IP to MAC mappings
ip route # default gateway and routes
ss -tn # current TCP connections
nslookup example.com
traceroute example.com
Practice Exercises
- Calculate the network address, broadcast address and number of usable hosts for
192.168.10.77/26. (Answer: network 192.168.10.64, broadcast 192.168.10.127, 62 usable hosts.) - For each of these ports, name the service and say whether it should be exposed to the internet: 22, 445, 3306, 443.
- Capture a ping between two lab VMs. Identify the source and destination MAC and IP addresses in the first ICMP packet.
- Explain what happens at each layer when you open a web page.
- Find your default gateway’s MAC address using
ip neigh, then find the same address in an ARP packet in Wireshark.
Mentor tip: Whenever you learn a new attack, ask: which layer does it abuse, and what would the traffic look like in Wireshark? This question converts memorised attack names into real understanding, and it is the habit that separates analysts from tool operators.
Educational use only: capture and analyse traffic only on networks you own or have explicit permission to monitor.
- Data travels in layers; security controls and attacks map to specific layers.
- IP addresses locate hosts, ports locate services, and the TCP handshake underlies many techniques.
- ARP, DHCP and DNS are trusted but weakly authenticated, so they are frequent abuse targets.
- Wireshark lets you verify theory with real packets, including why cleartext protocols are risky.
- Capture only on networks you own or are authorised to monitor.