Learn / Stage 1: Foundations / Lesson 1.4

$ lesson 1.4 --stage foundations

Networking Basics: IP, Ports, DNS and HTTP

Almost every attack crosses a network, and almost every investigation reads network evidence. This primer gives you the working mental model: addresses, layers, ports, DNS and HTTPS, ready for the CCNA stage.

  • Stage 1 Foundations
  • Level Beginner
  • 55 min
  • 6 sections, quiz, lab

Start the lesson Jump to the lab

By the end of this lesson you can

  • Tell MAC addresses, IP addresses, switches and routers apart
  • Explain the TCP/IP layers and encapsulation
  • Read CIDR notation and recognise private and special IPv4 ranges
  • Explain TCP versus UDP, the handshake and the security meaning of common ports
  • Trace a DNS lookup and an HTTPS page load end to end
1.4.01

What a network is, from your Wi-Fi to the internet

A network is two or more devices that can exchange data. Each device has a network interface (Wi-Fi or Ethernet) with a hardware address, the MAC address: 48 bits written as six hex pairs like 3C:52:82:1A:9F:04. The first half usually identifies the manufacturer.

  • A switch connects devices on the same local network (LAN) and forwards frames by MAC address.
  • A router connects different networks and forwards packets by IP address. Your home "router" is really a router, switch, Wi-Fi access point and firewall in one box.
  • The internet is a network of networks: thousands of ISPs and companies whose routers exchange routes with each other.
A home network: devices with private addresses connect to a router that does NAT, then to the ISP and the internetLaptop192.168.1.10Phone192.168.1.11Smart TV192.168.1.12Home routerswitch + Wi-Fi + NATLAN side 192.168.1.1WAN side: one ISP addressISPJio, Airtel, BSNLInternetserversPrivate addresses inside. The router translates them (NAT) to the one public address your ISP gives you, or shares an ISP address with other customers (CGNAT).
Most Indian homes look like this. Many mobile and some broadband connections add carrier grade NAT, so even the router's outside address is shared.
1.4.02

Layers and encapsulation

Networking is split into layers so each part can change without breaking the others. The practical model is TCP/IP with four layers; the OSI model has seven and is used to talk about problems ("it is a layer 2 issue").

TCP/IP and OSI layers
TCP/IP layerOSI layersUnitExamples
Application7 Application, 6 Presentation, 5 SessiondataHTTP, DNS, SMTP, SSH, TLS (commonly placed here)
Transport4 Transportsegment (TCP) or datagram (UDP)TCP, UDP, port numbers
Internet3 NetworkpacketIPv4, IPv6, ICMP
Link2 Data link, 1 Physicalframe, bitsEthernet, Wi-Fi, MAC addresses, cables, radio
Encapsulation: application data gets a TCP header, then an IP header, then an Ethernet header and trailerHTTP data: GET /index.htmlApplicationTCP 443dataTransport: segmentIP src, dstTCP header + dataInternet: packetMAC headerIP packetFCSLink: frameEach layer wraps the one above in its own header. The receiver unwraps in reverse order.
Wireshark shows exactly these nested headers for every packet you capture.

For a deeper walk through both models see the guide OSI and TCP/IP explained.

1.4.03

IP addresses, subnets and private ranges

An IPv4 address is 32 bits, written as four bytes in decimal: 192.168.1.10. Part of it identifies the network and the rest the host. The split is set by the subnet mask, usually written in CIDR form as a slash and the number of network bits.

Common subnet sizes
CIDRMaskAddressesUsable hostsTypical use
/24255.255.255.0256254home or small office LAN
/16255.255.0.065,53665,534large campus
/30255.255.255.25242link between two routers
/32255.255.255.25511 (one host)a single address in a firewall rule

In a /24 like 192.168.1.0/24, the first address (.0) names the network and the last (.255) is the broadcast address, leaving .1 to .254 for devices. Your default gateway, usually the router, is where packets for other networks go.

Special ranges to recognise on sight

Special IPv4 ranges
RangeMeaning
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16private (RFC 1918), not routed on the internet
100.64.0.0/10shared address space for carrier grade NAT at ISPs
127.0.0.0/8loopback, the machine itself (127.0.0.1 is localhost)
169.254.0.0/16link local: the device gave itself an address because DHCP failed
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24reserved for documentation and examples

IPv6 uses 128-bit addresses like 2001:db8::1, so there are enough for every device without NAT. Indian mobile networks such as Jio rolled out IPv6 widely, so your phone very likely has one now.

Practise subnetting with the subnet calculator on the home page.

1.4.04

Ports, TCP and UDP

An IP address gets a packet to the right machine. A port number (0 to 65535) gets it to the right program on that machine. Ports 0 to 1023 are the well known ports for standard services. Your side of a connection uses a random high ephemeral port.

Two transport protocols carry almost everything:

  • TCP is connection based and reliable: it numbers bytes, resends lost data and delivers in order. Web, email, SSH.
  • UDP just sends datagrams with no setup and no guarantee. Faster and simpler: DNS queries, video calls, online games, and QUIC (HTTP/3).
TCP three way handshake: SYN from client, SYN-ACK from server, ACK from clientYour laptopclientWeb serverport 443SYN seq=1000SYN-ACK seq=5000 ack=1001ACK ack=5001: connection open
Every TCP connection starts with these three packets. Sequence numbers are random in real life.
Common ports
PortProtocolServiceSecurity note
20, 21TCPFTPfile transfer, sends passwords in clear text
22TCPSSHsecure remote shell; brute forced constantly on the internet
23TCPTelnetold remote shell with no encryption; should be off
25TCPSMTPmail between servers
53UDP and TCPDNSname lookups
67, 68UDPDHCPautomatic IP addresses
80TCPHTTPweb without encryption
110, 143TCPPOP3, IMAPreading mail (secure versions on 995, 993)
123UDPNTPtime sync, critical for logs
443TCP (and UDP for HTTP/3)HTTPSweb with TLS
445TCPSMBWindows file sharing; never expose to the internet
3306TCPMySQLdatabase
3389TCPRDPWindows remote desktop; a top ransomware entry point when exposed
1.4.05

DNS: the internet's phone book

People remember names, computers need IP addresses. DNS (Domain Name System) translates one into the other, and it does it through a hierarchy of servers.

DNS resolution: device asks a recursive resolver, which asks the root, the TLD and the authoritative server, then returns and caches the answerYour devicestub resolverRecursive resolverISP, 1.1.1.1, 8.8.8.8Root servers .TLD servers .inAuthoritative: example.in12 ask root, told: try .in3 ask .in4 get the A record5 answer, cached for TTL
Answers are cached for the record's TTL (time to live), so most lookups never go beyond the resolver.
DNS record types
RecordHoldsExample
AIPv4 addressexample.in to 203.0.113.20
AAAAIPv6 addressexample.in to 2001:db8::20
CNAMEan alias pointing to another namewww to example.in
MXmail servers for the domain10 mx1.example.in
TXTfree text, used for SPF, DKIM, DMARC and domain verificationv=spf1 include:... -all
NSwhich servers are authoritative for the domainns1.dns-host.example
$ nslookup cyberwithmadhav.com
$ dig +short A cyberwithmadhav.com
$ dig +short MX gmail.com
$ dig +trace example.com

You can check a real domain's email related DNS records with the DNS and Email Security Checker in the Security Lab.

1.4.06

HTTP and HTTPS: what really happens when you open a website

HTTP is a simple text conversation: the browser sends a request with a method, path and headers, and the server sends a response with a status code, headers and a body.

$ curl -sI https://example.com
HTTP/2 200
content-type: text/html
cache-control: max-age=3600
HTTP status codes
StatusMeaning
200OK
301 / 302moved, go to the Location header
401 / 403not logged in / not allowed
404not found
500server error

Methods you will meet: GET reads, POST submits data, PUT and DELETE change resources in APIs. Cookies are headers the server asks the browser to send back, which is how logins are remembered, and why stealing a session cookie can be as good as stealing the password.

HTTPS is HTTP inside TLS. TLS encrypts the conversation, protects it from tampering and proves the server owns the certificate for that domain.

You type https://www.example.in and press Enter

Seven things happen in well under a second.

    1. Do I already know?

    The browser checks its own DNS cache, then the OS cache and hosts file.

    2. DNS lookup

    If not cached, the OS asks the configured resolver for the A or AAAA record and gets back an IP address such as 203.0.113.20.

    3. Route

    The destination is not on your subnet, so the packet goes to the default gateway (your router), then through the ISP and other networks to the server.

    4. TCP handshake

    SYN, SYN-ACK, ACK on port 443 opens a connection. (HTTP/3 uses QUIC over UDP instead and combines this with the next step.)

    5. TLS handshake

    Browser and server agree on keys. The server sends its certificate; the browser checks it is valid, not expired, issued by a trusted authority and matches www.example.in.

    6. HTTP request and response

    Encrypted inside TLS, the browser sends GET / HTTP/2 with headers and cookies. The server answers 200 OK with HTML.

    7. Render, and repeat

    The browser reads the HTML, then requests CSS, scripts and images, often from other domains, repeating steps 1 to 6 for each new host.

    Flashcards: do you remember?

    Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.

    Quick quiz

    Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.

    Q1Which device forwards traffic between your home network and your ISP?

    Q2Which address is NOT private?

    Q3A DNS query for a short name is most often sent using:

    Q4You see SYN packets from one IP to ports 1 to 1024 on a server, one after another. What is likely happening?

    Q5Which statement about HTTPS is true?

    Q6In 192.168.10.0/24, what is the broadcast address?

    0 / 6

    Hands-on lab

    lab40 minutesyour own machines only

    Lab: see your own network

    You need: Your Ubuntu VM (NAT adapter is fine), and Wireshark (free, wireshark.org) on the VM or your own PC. Capture only on networks and devices you own.

    1. Find your addresses

      $ ip -br addr
      $ ip route
      $ resolvectl status | grep -A2 'DNS Servers'

      Write down your IP, prefix length, default gateway and DNS server. On Windows the same information is in ipconfig /all. In VirtualBox NAT mode you will usually see 10.0.2.15/24 with gateway 10.0.2.2.

    2. Test the path

      $ ping -c 3 10.0.2.2
      $ ping -c 3 1.1.1.1
      $ tracepath -n 1.1.1.1

      If the gateway answers but 1.1.1.1 does not, the problem is beyond your machine. If 1.1.1.1 answers but names fail, it is DNS. That split is the start of all network troubleshooting.

    3. Query DNS by hand

      $ sudo apt install -y dnsutils
      $ dig cyberwithmadhav.com A
      $ dig cyberwithmadhav.com MX
      $ dig cyberwithmadhav.com TXT
      $ dig +trace cyberwithmadhav.com

      Find the TTL of the A record and the SPF entry in the TXT records. In the trace, spot the root, the .com servers and the authoritative servers.

    4. Read HTTP headers

      $ curl -sI http://example.com
      $ curl -sI https://example.com
      $ curl -v https://example.com -o /dev/null 2>&1 | grep -E 'Connected|SSL|subject|issuer'

      Note the status code and the certificate subject and issuer.

    5. Capture a handshake in Wireshark

      Start a capture on your own interface, then run curl https://example.com. Stop and apply the display filter dns || tcp.flags.syn==1. Find the DNS query and response, then the SYN, SYN-ACK and ACK. Next filter tls.handshake and find the Client Hello and the server name (SNI) it carries.

    6. List your listening ports

      $ ss -tuln
      $ sudo ss -tulnp

      For each listening port, name the service. Anything you cannot explain is worth investigating, on your own machine.

    You are done when: You can name your IP, gateway and DNS server, explain a ping or DNS failure, and point to a DNS exchange and a TCP handshake in your own capture.

    Download the lab checklist (.txt)

    Key takeaways

    • MAC addresses work inside a LAN; IP addresses work across networks.
    • Layers wrap each other: frame, packet, segment, data.
    • Know the private ranges and what /24, /30 and /32 mean on sight.
    • Ports identify services. Exposed SMB and RDP are invitations to attackers.
    • DNS and HTTPS are where phishing lives. Read the domain, not the padlock.

    Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.