1. IP Addressing: IPv4, Subnets, Public and Private IPs
Chala mitrano, aaj aapan cyber security cha pahila dagad thevuya – IP address. Hacker aso kiwa defender, pahila prashna nehmi ekach asto: "target kuthe aahe?" Tyache uttar mhanje IP address. Aaj aapan IPv4, classes, CIDR, subnetting, static aani dynamic IP, public aani private IP aani NAT shiknar aahot. Pen aani paper ghya, fakt vachu naka – calculation swatah kara. Ekdum simple aahe, fakt dhyan dya.
What you will learn in this chapter
- What an IP address is and how an IPv4 address is built (32 bits, four octets)
- IPv4 classes A–E, loopback, and why classes were replaced by CIDR
- CIDR notation, subnet masks and basic subnetting (network, broadcast, usable hosts)
- Static vs dynamic IP and how DHCP hands out addresses (DORA)
- Public vs private IP (RFC 1918) and NAT (नेटवर्क पत्त्याचे भाषांतर)
- Why each of these matters for security
Concepts in this chapter
- 1.1What Is an IP Address?
- 1.2IPv4 Structure: Bits, Octets and the Subnet Mask
- 1.3IPv4 Classes (A to E) and Loopback
- 1.4CIDR Notation and Subnet Masks
- 1.5Subnetting Basics (Worked Example)
- 1.6Static vs Dynamic IP and DHCP
- 1.7Public vs Private IP (RFC 1918)
- 1.8NAT (Network Address Translation)
The chapter recap is at the end of the last concept page.
Chapter 1: IP addressing, subnets, public and private — practice tasks
Open chapter lessons · Full guided lab: find private public ip and gateway (not repeated here)
1.1 Find your own private IP, public IP and gateway
EasyITWhy: Every security check starts with knowing which address is yours. If you mix up private and public IPs you may scan the wrong machine.
What: On your own laptop or lab VM, write down your private IP, default gateway and public IP.
How:
- Linux/macOS: run
ip -4 addr show(orifconfig). Windows: runipconfig. - Find the line with
inet/ IPv4 Address that is not 127.0.0.1. - Run
ip route | grep default(Windows: Default Gateway line) to find the gateway. - Run
curl -s https://ifconfig.meto see your public IP. - Write the three values in a table.
Expected output: Private IP like 192.168.1.23, gateway like 192.168.1.1, public IP that is NOT in 10.x, 172.16–31.x or 192.168.x.
Hint
The gateway is usually your router and ends in .1 or .254.
Answer / how to check
- Private IP must be in 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16.
- Public IP from curl must be different from the private IP.
- If both are the same, you are on a cloud VM with a public IP directly attached.
1.2 Classify IPs in a bank branch device list
EasyBankingWhy: Banks must keep ATMs and staff PCs on private networks. Spotting a public IP on an internal device is a real audit finding.
What: Use the data file below. Mark each IP as Private, Public or Loopback.
Data file: branch-devices.csv
| Device | Branch | IP |
|---|---|---|
| ATM-01 | Pune (₹) | 10.20.1.15 |
| Teller-PC-3 | Mumbai | 192.168.5.40 |
| CCTV-NVR | London (£) | 172.20.3.9 |
| Printer-2 | Nagpur | 8.8.4.4 |
| Health-check | Berlin (€) | 127.0.0.1 |
About this file: A made-up list of devices in bank branches. Each row is one device. Columns: Device = device name; Branch = city; IP = the IPv4 address the device uses.
How:
- Open the CSV in any editor.
- Compare each IP with the three private ranges.
- 127.x.x.x is loopback (the machine itself).
- Write the class next to each row.
- Optional: check in Python with
import ipaddress; ipaddress.ip_address('10.20.1.15').is_private.
Expected output: ATM-01 Private, Teller-PC-3 Private, CCTV-NVR Private, Printer-2 Public, Health-check Loopback.
Hint
172.20 is inside 172.16–172.31.
Answer / how to check
- Run the Python one-liner for each IP; True means private.
- Printer-2 with a public IP is the finding to report.
1.3 Subnet math for a hospital network
MediumHealthcareWhy: Hospitals separate medical devices from guest Wi-Fi using subnets. You must know how many hosts fit.
What: For 10.50.8.0/22, find network address, broadcast, first host, last host and usable host count.
How:
- Run
python3 -c "import ipaddress as i;n=i.ip_network('10.50.8.0/22');print(n.network_address,n.broadcast_address,n.num_addresses-2)". - First host = network + 1, last host = broadcast − 1.
- Check by hand: /22 leaves 10 host bits, 2^10 = 1024.
Expected output: Network 10.50.8.0, broadcast 10.50.11.255, first 10.50.8.1, last 10.50.11.254, 1022 usable hosts.
Hint
A /22 covers four /24 blocks: .8, .9, .10, .11.
Answer / how to check
- Your Python output must print 10.50.8.0 10.50.11.255 1022.
Extended teaching notes
Why this lesson matters
Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.
Apply the fix across stacks
Same class of bug, same idea in every language.
Java / Spring Boot
Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.
ASP.NET Core
EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.
Node.js / Express
helmet, parameterised SQL, npm audit, avoid eval and shell concat.
Python / Django / Flask / FastAPI
ORM, autoescape, pip-audit, Bandit; never shell=True with user input.
PHP / Laravel
PDO/Eloquent, Blade escaping, composer audit.
Go / Ruby
database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.
nginx / Apache / Tomcat
Hide versions, TLS, security headers, least-open ports.
MySQL / PostgreSQL / MongoDB / Redis
Private networks, auth on, least-privilege users, no 0.0.0.0/0.
AWS / Azure / GCP
Roles not long-lived keys, private data stores, cloud audit logs on.
Mini case study
Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.
Defender's worksheet (do this today)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.
Indian workplace (sample data)
Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).
Global practice
Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.
Everyday analogy
Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.
Key terms
- Control: a safeguard (patch, config, process, detection).
- Finding: a weakness backed by evidence.
- Remediation: the fix plus how you verified it.
- Scope: systems you have written permission to touch.
- Least privilege: only the access the task needs.
- Defence in depth: several layers so one failure does not end the story.
Common mistakes
- Skipping written permission "just for a quick scan".
- Practising on hostel, office or public targets without authorisation.
- Collecting tool output without writing the fix.
- Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
- Publishing screenshots that contain secrets, cookies or internal hostnames.
Recap
- Evidence, fix, owner, date.
- Own lab only.
- Fix > spectacle.