1. IP Addressing: IPv4, Subnets, Public and Private IPs
1.7 Public vs Private IP (RFC 1918)
In short: A public IP is globally unique and routable on the internet. A private IP is used only inside a local network (home, institute, VPC) and is not routable on the internet.
Also in the AWS course: this lesson is the same as 1.7 Public vs private IP in the AWS course, which is the main version of this page.
Aata ek khup important farak – public aani private IP. Ha samjla nahi tar pudhe NAT, VPC, security groups sagla gondhalat padel.
A public IP is globally unique and routable on the internet. A private IP is used only inside a local network (home, institute, VPC) and is not routable on the internet. RFC 1918 reserves three private ranges:
| Class | Private range (RFC 1918) | CIDR | Typical use |
|---|---|---|---|
| A | 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 |
Large companies, AWS VPCs |
| B | 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 |
AWS default VPC uses 172.31.0.0/16 |
| C | 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 |
Home Wi-Fi routers |
Other special ranges: 100.64.0.0/10 (carrier-grade NAT used by mobile ISPs) and 169.254.0.0/16 (link-local; on EC2, 169.254.169.254 is the instance metadata service).
Check your own IPs:
# Private IP(s) of this machine
ip -4 addr show
hostname -I
# Public IP as seen by the internet
curl -s https://checkip.amazonaws.com
Why this matters for security
Private addresses are not routable on the internet, so a database with only a private IP cannot be reached directly from outside – a strong first layer of defence. But "private" is not "secure": anyone who gets inside the network (a compromised server, a malicious insider, a VPN user) can still reach it. That is why we still use security groups, strong passwords and least privilege inside the network. Also remember 169.254.169.254 – the EC2 metadata address is a favourite SSRF target (Part 11).
Ravindra Bagale's Tip
Is 172.32.1.1 private? Many students say "it starts with 172, so it's private" – wrong! The private range is only 172.16.0.0 to 172.31.255.255. Remember the ranges: 10/8, 172.16/12, 192.168/16. Everything outside these three is public.
Ravindra Bagale's Tip – मराठी
172.32.1.1 private आहे का? बरेच students "172 ने सुरू होतो म्हणजे private" असं म्हणतात – चूक! Private range फक्त 172.16.0.0 ते 172.31.255.255 आहे. Ranges लक्षात ठेवा: 10/8, 172.16/12, 192.168/16. या तीन सोडून बाकी सगळे public.
Ravindra Bagale's Tip – हिंदी
क्या 172.32.1.1 private है? बहुत से students कहते हैं "172 से शुरू होता है तो private है" – गलत! Private range सिर्फ़ 172.16.0.0 से 172.31.255.255 तक है. Ranges याद रखो: 10/8, 172.16/12, 192.168/16. इन तीन के अलावा बाकी सब public हैं.
Practice task
Which of these are private: 10.10.10.10, 172.32.1.1, 192.168.100.1, 100.64.1.1, 8.8.8.8? Then run curl -s https://checkip.amazonaws.com and compare it with your laptop IP.
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.