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
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.
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 layer | OSI layers | Unit | Examples |
|---|---|---|---|
| Application | 7 Application, 6 Presentation, 5 Session | data | HTTP, DNS, SMTP, SSH, TLS (commonly placed here) |
| Transport | 4 Transport | segment (TCP) or datagram (UDP) | TCP, UDP, port numbers |
| Internet | 3 Network | packet | IPv4, IPv6, ICMP |
| Link | 2 Data link, 1 Physical | frame, bits | Ethernet, Wi-Fi, MAC addresses, cables, radio |
For a deeper walk through both models see the guide OSI and TCP/IP explained.
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.
| CIDR | Mask | Addresses | Usable hosts | Typical use |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 | home or small office LAN |
| /16 | 255.255.0.0 | 65,536 | 65,534 | large campus |
| /30 | 255.255.255.252 | 4 | 2 | link between two routers |
| /32 | 255.255.255.255 | 1 | 1 (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
| Range | Meaning |
|---|---|
| 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 | private (RFC 1918), not routed on the internet |
| 100.64.0.0/10 | shared address space for carrier grade NAT at ISPs |
| 127.0.0.0/8 | loopback, the machine itself (127.0.0.1 is localhost) |
| 169.254.0.0/16 | link local: the device gave itself an address because DHCP failed |
| 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 | reserved 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.
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).
| Port | Protocol | Service | Security note |
|---|---|---|---|
| 20, 21 | TCP | FTP | file transfer, sends passwords in clear text |
| 22 | TCP | SSH | secure remote shell; brute forced constantly on the internet |
| 23 | TCP | Telnet | old remote shell with no encryption; should be off |
| 25 | TCP | SMTP | mail between servers |
| 53 | UDP and TCP | DNS | name lookups |
| 67, 68 | UDP | DHCP | automatic IP addresses |
| 80 | TCP | HTTP | web without encryption |
| 110, 143 | TCP | POP3, IMAP | reading mail (secure versions on 995, 993) |
| 123 | UDP | NTP | time sync, critical for logs |
| 443 | TCP (and UDP for HTTP/3) | HTTPS | web with TLS |
| 445 | TCP | SMB | Windows file sharing; never expose to the internet |
| 3306 | TCP | MySQL | database |
| 3389 | TCP | RDP | Windows remote desktop; a top ransomware entry point when exposed |
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.
| Record | Holds | Example |
|---|---|---|
| A | IPv4 address | example.in to 203.0.113.20 |
| AAAA | IPv6 address | example.in to 2001:db8::20 |
| CNAME | an alias pointing to another name | www to example.in |
| MX | mail servers for the domain | 10 mx1.example.in |
| TXT | free text, used for SPF, DKIM, DMARC and domain verification | v=spf1 include:... -all |
| NS | which servers are authoritative for the domain | ns1.dns-host.example |
$ nslookup cyberwithmadhav.com
$ dig +short A cyberwithmadhav.com
$ dig +short MX gmail.com
$ dig +trace example.comYou can check a real domain's email related DNS records with the DNS and Email Security Checker in the Security Lab.
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| Status | Meaning |
|---|---|
| 200 | OK |
| 301 / 302 | moved, go to the Location header |
| 401 / 403 | not logged in / not allowed |
| 404 | not found |
| 500 | server 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.
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?
Routers connect different networks. The home box includes a router.
Q2Which address is NOT private?
8.8.8.8 is a public address (Google Public DNS).
Q3A DNS query for a short name is most often sent using:
DNS normally uses UDP 53, falling back to TCP 53 for large answers.
Q4You see SYN packets from one IP to ports 1 to 1024 on a server, one after another. What is likely happening?
Probing many ports in order is a port scan.
Q5Which statement about HTTPS is true?
TLS gives confidentiality and integrity to the named server, nothing more.
Q6In 192.168.10.0/24, what is the broadcast address?
The last address of the block is the broadcast address.
Hands-on lab
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.
Only on machines you own. Do this lab on your own VM or computer. Scanning, testing or accessing anyone else's system without written permission can be an offence under the Information Technology Act, 2000 (for example Sections 43 and 66).
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.Test the path
$ ping -c 3 10.0.2.2 $ ping -c 3 1.1.1.1 $ tracepath -n 1.1.1.1If 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.
Query DNS by hand
$ sudo apt install -y dnsutils $ dig cyberwithmadhav.com A $ dig cyberwithmadhav.com MX $ dig cyberwithmadhav.com TXT $ dig +trace cyberwithmadhav.comFind 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.
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.
Capture a handshake in Wireshark
Start a capture on your own interface, then run
curl https://example.com. Stop and apply the display filterdns || tcp.flags.syn==1. Find the DNS query and response, then the SYN, SYN-ACK and ACK. Next filtertls.handshakeand find the Client Hello and the server name (SNI) it carries.List your listening ports
$ ss -tuln $ sudo ss -tulnpFor 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.
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.