Skip to main content

Command Palette

Search for a command to run...

From Zero to Understanding: DNS, IPs, CIDR, Subnets & Ports

Updated
14 min read
M
QA Engineer transitioning into DevOps with 13+ years of experience in software testing, automation, CI/CD, Docker, Kubernetes, and cloud technologies. Sharing real-world DevOps learning, hands-on projects, and career transformation experiences.

When I first started learning networking, everything felt overwhelming — DNS, IPs, CIDR, subnets, ports. None of it made sense. But once I broke it down step by step, it all started connecting.

Understanding networking is not just theory — it’s the foundation of how real systems communicate in a DevOps environment.


What happens when you type a website in a browser?

When you type something like:

google.com

A lot happens behind the scenes:

  1. Your browser checks cache (already known IP?)

  2. Your system asks DNS: “What is the IP address for this domain?”

  3. DNS responds with an IP (like 142.x.x.x)

  4. Your browser connects to that IP using a port (usually 80 or 443)

  5. A request is sent to the server

  6. The server responds with the website

👉 So the full chain is:

Domain → DNS → IP → Port → Server → Response

👉 Think of it like:

Typing a contact name → phonebook → dialing the number


What is an IP address?

An IP address is like a home address for a device.

An IPv4 address looks like:

192.168.1.10

👉 It has 4 parts (octets):

  • Each part ranges from 0–255

Why 255?

Because each octet = 8 bits And 2⁸ = 256 values (0–255)

  • Total = 32 bits

Think of it as the identity of a machine in a network.


What is DNS?

  • DNS (Domain Name System) is like a phonebook.

  • Instead of remembering IPs like: 142.250.73.142

We use: google.com

DNS translates: Domain → IP address

DNS exists because humans can’t remember IP addresses easily.


DNS Record Types

Record Meaning
A Domain → IPv4 address
AAAA Domain → IPv6 address
CNAME Alias to another domain
MX Mail server
NS DNS servers for domain

Example:


How DNS connects to IP

DNS = translates human names → IP addresses

DNS converts google.com → 142.250.x.x so computers can talk.

  • User enters domain

  • DNS resolves it

  • IP is returned

👉 This is how human-friendly names connect to machine-level communication.


Real-life analogy

Think of your phone:

You save: “Mom” Phone actually uses: +91-XXXXXXXXXX

👉 DNS works the same way:

  • You type: google.com

  • Internet uses: an IP address


Now let’s go deeper into how DNS actually works:

Step-by-step (what actually happens)

  1. You type a domain
google.com
  1. Browser asks DNS resolver
 “What is the IP for this domain?”
  1. DNS looks up records

It checks different record types:

  • A record → IPv4 address

  • AAAA record → IPv6 address

4. DNS returns IP

Example:

google.com → 142.250.73.142

5. Your system connects to that IP

👉 Now networking begins:

  • TCP connection

  • Port (like 80 or 443)

  • Data transfer


Where DNS gets the answer from

DNS is like a chain:

  1. Your system cache

  2. ISP / local DNS server

  3. Root servers

  4. TLD servers (.com)

  5. Authoritative DNS

👉 Finally returns the IP


Example from command

You ran:

dig google.com

You saw:

google.com. 141 IN A 142.250.73.142

👉 This means:

  • Domain → google.com

  • Record type → A

  • IP → 142.250.73.142

  • TTL → 141 seconds

Why this matters

Without DNS:

👉 You would have to remember:

142.250.73.142

Instead of:

google.com

Remember:

  • DNS = phonebook

  • Domain = contact name

  • IP = phone number

DNS connects domain names to IP addresses so computers can locate each other on the internet.


Public vs Private IP

→ tells you what kind of IP it is

  • Public IP → accessible from internet

    • Example:

      8.8.8.8
      
  • Private IP → used inside networks

    • 10.x.x.x

    • 172.16–31.x.x

    • 192.168.x.x

    Example:

    172.31.32.167
    

    👉 Private = internal use
    👉 Public = internet facing


What is a Subnet?

Subnet = a smaller network inside a bigger network

That’s it.


Real-life analogy

Think of:

Internet = country

Network = city

Subnet = neighborhood

👉 You divide a big area into smaller manageable parts.


In networking terms

A subnet is:

A group of IP addresses that belong to the same network range

Defined using:

  • CIDR (/24, /20, etc.)

  • or Subnet mask (255.255.255.0)

Example

192.168.1.10/24

👉 This means:

  • Network (subnet) = 192.168.1.0

  • Range = 192.168.1.0 → 192.168.1.255

👉 All these IPs are in one subnet


Why subnetting is used

1. Organization

Split big network into smaller ones

2. Security

Control access between subnets

3. Performance

Reduce unnecessary traffic


Example in real world

Let’s say a company has:

10.0.0.0/16

👉 Huge network (65,536 IPs)

They divide it:

Subnet Use
10.0.1.0/24 Backend
10.0.2.0/24 Frontend
10.0.3.0/24 Database

👉 Each is a subnet


Key Idea

👉 Subnet = CIDR-defined range of IPs


Remember:

  • IP → one house

  • Subnet → group of houses

  • Network → city

A subnet is a logical division of an IP network defined by a CIDR range.


What is CIDR?

CIDR looks like:

192.168.1.10/24

The /24 means:

👉 First 24 bits = network

👉 Remaining bits = hosts

How big the network is

Core Idea

  • IP = address

  • CIDR = range size

Example: /24

192.168.1.10/24

👉 Means:

  • Network: 192.168.1.0

  • Range: 192.168.1.0 → 192.168.1.255

  • Total IPs: 256


192.168.1.0/24  
→ Total IPs: 256  
→ Network: .0  
→ Broadcast: .255  

Example: /20

172.31.32.167/20

👉 Step:

  • Mask = 255.255.240.0

  • Block size = 256 - 240 = 16

👉 Range:

172.31.32.0 → 172.31.47.255

👉 Total IPs:

4096

CIDR Memory Trick

CIDR Size
/24 256
/20 4096
/16 65536

👉 Lower CIDR = bigger network
👉 Higher CIDR = smaller network


Key Table

Value Bits
255 8
254 7
252 6
248 5
240 4
224 3
192 2
128 1
0 0

Subnet Mask from CIDR

Example:

/20

Step:

20 bits = 8 + 8 + 4 + 0

Binary: 11111111.11111111.11110000.00000000

Convert:

255.255.240.0

👉 Final: CIDR /20 = Subnet Mask 255.255.240.0


Reverse (Subnet Mask → CIDR)

Example:

255.255.255.0 → /24

👉 Count 255s:

  • 255 = 8 bits
8 + 8 + 8 = /24

Example:

255.255.192.0 → /18

👉 192 = 2 bits

8 + 8 + 2 = /18

Subnet/CIDR concepts are best understood using ranges, examples, and breakdowns.

Example:

192.168.1.0/24
→ 256 IPs
→ .0 network
→ .255 broadcast

What is Block Size?

Formula:

Block size = 256 − subnet value

Example:

/20 → mask

20 = 8 + 8 + 4 +0 → 255.255.240.0

/20 → 255.255.240.0

👉 Focus on 240

256 - 240 = 16

👉 Blocks:

0–15
16–31
32–47 ✅
48–63

👉 Since 32 falls in 32–47, that’s your range.


What does Block Size mean?

It means how the network is divided.

Example block size 16:

  • 0–15

  • 16–31

  • 32–47

  • 48–63


Example: 172.31.32.167/20

Step 1: Block size = 16

Step 2: Find where 32 fits:

0–15

16–31

32–47 ✅

Final Range:

172.31.32.0 → 172.31.47.255

👉 Always subtract using mask, not IP


Fast Method (No Binary)

Steps:

  1. Find CIDR → get mask

  2. Find block size

  3. Look at octet

  4. Place IP in range


How to Identify Range in 5 Seconds

Example:

192.168.70.10/18

18 = 8 + 8 + 2 +0 = 255 + 255 + 192 + 0

👉 Block size = 256 − 192 = 64

0–63
64–127 ✅
128–191
192–255

👉 So range:

Network: 192.168.64.0 → 
Broadcast: 192.168.127.255

Remember:

CIDR → Mask → Block Size → Buckets → Range


CIDR Extremes (Very Important)

Refer: https://cidr.xyz/

/32 — Single IP

10.88.135.144/32
  • Only ONE IP

  • Mask = 255.255.255.255

👉 Use:

  • Firewall rules

  • Exact machine targeting


/0 — Entire Internet

0.0.0.0/0
  • All IPs included

  • Mask = 0.0.0.0

  • Total = 4.29 billion IPs

👉 Use:

  • Default route

  • Allow from anywhere


Comparison

CIDR Meaning
/32 One device
/24 Small network
/16 Large network
/0 Entire internet

What are Ports?

Ports are like doors on a server.

  • One machine → many services

Examples:

  • 80 → HTTP

  • 443 → HTTPS

  • 22 → SSH

  • 3306 → MySQL

👉 Ports allow multiple services to run on the same machine without conflict.


What Happens in:

Command:

curl http://myapp.com:8080

Steps:

  1. DNS resolves myapp.com

  2. IP returned (multiple A records)

  3. Connect to port 8080

  4. TCP handshake

  5. HTTP request sent

If it fails:

Check:

  1. DNS → does domain resolve?

  2. IP → is it reachable?

  3. Port → is 8080 open?

  4. Firewall → blocking?

  5. Service → running?


Real Debugging Example

ubuntu@ip-172-31-32-167:~$ curl http://myapp.com:8080
curl: (28) Failed to connect to myapp.com port 8080 after 300353 ms: Timeout was reached

You saw:

curl timeout

But:

dig myapp.com → works

👉 Means:

  • DNS ✅ working

  • Network ❌ or port ❌

What to Check

  1. Is port 8080 open?

  2. Firewall rules?

  3. Server running?

  4. Security group (cloud)?

  5. Correct IP?


Test commands:

ping myapp.com
nc -zv myapp.com 8080
curl http://google.com

Real DevOps Use Cases

Think of it like a delivery system

Concept What it does Analogy
CIDR / VPC Defines network range Your city
Subnet Splits network Neighborhoods
DNS Converts name → IP Contact name → phone number
Port Identifies service on server Apartment number
Load Balancer Distributes traffic Receptionist

Let’s clarify each one (simple)

1. CIDR (VPC)

Example: 10.0.0.0/16 Defines how many IPs you have Used when creating VPC

👉 This is your network boundary


2. Subnets

Example: Public: 10.0.1.0/24 Private: 10.0.2.0/24

Splits your VPC into parts

👉 This is network organization + security


3. DNS

Converts: google.com → 142.x.x.x

👉 This is name → IP lookup


4. Ports

Example: 80 → HTTP 443 → HTTPS

👉 This is which service on the server


5. Load Balancer

Receives traffic Sends it to backend servers

👉 This is traffic manager


AWS section:

VPC + Subnet → tells you where and how those IPs are used


Think of it like a house with rooms

  • VPC (10.0.0.0/16) = your entire house

  • Subnets = different rooms inside the house


Inside your “house” (VPC)

Public Subnet (10.0.1.0/24)

  • Connected to the internet

  • Anyone can reach here (with permission)

Used for:

  • Load Balancer

  • Bastion Host

👉 Visitors are allowed here


Private Subnet (10.0.2.0/24)

  • NOT connected to the internet directly

  • Only accessible internally

Used for:

  • Backend servers

  • Databases

👉 Only trusted systems inside can access


How they all work together (this is the key)

User types domain
   ↓
DNS → gives IP
   ↓
Request goes to Load Balancer (Public Subnet)
   ↓
Forwarded to App Server (Private Subnet)
   ↓
App talks to Database (Private Subnet)
   ↓
Response goes back

End-to-end flow (compressed)

User → DNS → Internet → Public Subnet (LB)
     → Private Subnet (App → DB)
     → Response back to user

Important correction

❌ DNS is NOT routing traffic like a load balancer

✅ Correct:

  • DNS → tells you WHERE to go (IP address)

  • Load Balancer → decides WHICH server handles request


  • DNS = Address finder

  • Load Balancer = Traffic controller

  • Subnet = Security zones

  • Port = Service gate

  • CIDR = Network size


In real DevOps environments, these concepts are used daily:

  • CIDR is used while creating VPCs in cloud platforms like AWS

  • Subnets divide public and private networks

  • Ports are controlled using security groups and firewalls

  • DNS is used for routing traffic to services and load balancers


Real-world importance:

  • Subnets are used in cloud isolation and routing

  • CIDR defines IP allocation and scaling


Simple analogy

  • Public subnet = Shop front

  • Private subnet = Storage room

Customers → shop front Internal systems → storage room


NETWORK FLOW DIAGRAM

End-to-End Request Flow

User (Browser)
      ↓
DNS → Converts domain → IP
      ↓
Internet Routing
      ↓
Server IP (inside subnet)
      ↓
Port (80 / 443 / custom)
      ↓
Application (Nginx / Backend)
      ↓
Response sent back to user

How Everything Connects

When you open a website:

1. DNS converts domain → IP
2. IP identifies the server
3. Subnet determines network grouping
4. Port routes request to correct service

Key Takeaways

  • DNS converts names → IPs (like a phonebook)

  • Subnet = grouping

  • IP identifies machines = address = identity

  • CIDR defines network size = area size

  • Subnet splits networks

  • Block size creates ranges

  • Ports identify services = door = process routing

  • curl = knocking


Conclusion

Networking isn’t magic — it’s just layers:


- IP addresses (identity)
- Find IP (DNS)
- Identify network (CIDR)
- Reach machine (IP)
- Access service (port)

Final Understanding

Before:

Everything looked random and confusing

Now:

Everything follows a simple flow:

👉 Name → IP → Network → Range → Port → Service

Networking looks complex at first, but once you understand:

  • how CIDR maps to subnet masks

  • how block size creates ranges

  • how IP fits into those ranges

…it becomes predictable and logical.


#90DaysOfDevOps #DevOpsKaJosh #TrainWithShubham