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 layerTCP/IP layerFunctionExamplesTypical security issues
7 ApplicationApplicationUser-facing servicesHTTP, DNS, SMTP, SSHInjection, weak authentication, misconfiguration
6 PresentationData formats, encryptionTLS, character encodingWeak ciphers, bad certificates
5 SessionSession managementSession tokens, RPCSession hijacking
4 TransportTransportEnd-to-end deliveryTCP, UDPPort scanning, SYN floods
3 NetworkInternetAddressing and routingIP, ICMPSpoofing, routing attacks
2 Data linkNetwork accessLocal deliveryEthernet, Wi-Fi, ARP, MACARP spoofing, MAC flooding
1 PhysicalSignals and cablesCables, radioTapping, 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).

CIDRMaskAddressesUse
/32255.255.255.2551A single host
/30255.255.255.2524 (2 usable)Point-to-point links
/24255.255.255.0256Typical small network
/16255.255.0.065,536Large 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.

PortProtocolServiceSecurity note
20/21TCPFTPCleartext; prefer SFTP
22TCPSSHUse keys, restrict access
23TCPTelnetCleartext; should be disabled
25TCPSMTPMail transfer; abused for spam
53UDP/TCPDNSOften abused for tunnelling and spoofing
80TCPHTTPCleartext web
110/143TCPPOP3/IMAPPrefer encrypted variants
443TCPHTTPSEncrypted web
445TCPSMBFile sharing; should not be exposed to the internet
3306TCPMySQLDatabases should not face the internet
3389TCPRemote DesktopFrequent 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.

  1. Install Wireshark on your analyst VM and start capturing on the host-only interface (eth1 or similar).
  2. 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 curl request (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

  1. 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.)
  2. For each of these ports, name the service and say whether it should be exposed to the internet: 22, 445, 3306, 443.
  3. Capture a ping between two lab VMs. Identify the source and destination MAC and IP addresses in the first ICMP packet.
  4. Explain what happens at each layer when you open a web page.
  5. 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.

Key takeaways
  • 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.

Related Lessons