📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is an IP address? Explain IPv4 vs IPv6, private vs public ranges, subnets and CIDR notation, and NAT, with examples from cloud or container networking.

IP addressing fundamentals: IPv4 and IPv6, CIDR and subnet sizing, private, loopback and link-local ranges, NAT, and how they show up in cloud VNets and Kubernetes.

Junior Theory Beginner cidr ip ipv6 nat networking subnet

🎯 Key points

  • An IP address identifies a network interface for routing: IPv4 is 32-bit (about 4.3 billion addresses), IPv6 is 128-bit and written in hex with :: compressing zeros.
  • CIDR /n means the first n bits are the network: /24 is 256 addresses, /16 is 65,536, /32 is a single host; hosts in the same network talk directly, others go via the default gateway.
  • Private IPv4 ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16; loopback is 127.0.0.1 and ::1; IPv6 has unique local fc00::/7 and link-local fe80::/10.
  • 169.254 (in the link-local 169.254.0.0/16 range) is the cloud instance metadata endpoint, which is why SSRF protections must block it.
  • NAT rewrites private source addresses to a shared public one; servers see the NAT or proxy IP, and heavy outbound traffic can exhaust SNAT ports on cloud NAT gateways.
  • Cloud subnets reserve addresses (5 per subnet on Azure and AWS), and CNIs that give pods VNet IPs consume them fast, so plan CIDRs for growth and avoid overlaps with peered or on-premises networks.
  • IPv6 removes the need for NAT but makes every host potentially reachable, so firewalls and security groups matter more; dual-stack hosts can resolve localhost to ::1 first.
  • In .NET, System.Net.IPNetwork (available in .NET 10) parses CIDR and offers Contains; call MapToIPv4 on IPv4-mapped IPv6 addresses such as ::ffff:10.0.0.5 before comparing.

⏱ 30-second answer

An IP address identifies a network interface so packets can be routed to it.

  • IPv4: 32 bits, written 192.168.1.10. About 4.3 billion addresses, which ran out, so most networks use private ranges behind NAT.
  • IPv6: 128 bits, written 2001:db8::1. Enough addresses for everything to be globally routable.
  • CIDR 10.0.1.0/24 means the first 24 bits are the network, leaving 8 bits (256 addresses) for hosts.
  • Private ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. Loopback: 127.0.0.1, ::1.
  • NAT rewrites private source addresses to a public one on the way out, so many machines share one public IP.

🗣 Full answer (senior)

IPv4 vs IPv6

IPv4 IPv6
Size 32 bits 128 bits
Notation 203.0.113.7 2001:db8:85a3::8a2e:370:7334 (zeros compressed with ::)
Loopback 127.0.0.1 ::1
Private/local 10/8, 172.16/12, 192.168/16 fc00::/7 (unique local), fe80::/10 (link-local)
NAT Common Usually not needed

CIDR and subnet sizes

CIDR Host bits Addresses Typical use
/32 0 1 A single host in a firewall rule
/28 4 16 Small subnet (e.g. a gateway subnet)
/24 8 256 Common subnet size
/16 16 65,536 A whole VNet / VPC
/8 24 16.7 million 10.0.0.0/8 private block

Cloud providers reserve a few addresses per subnet (Azure and AWS reserve 5), so a /24 gives 251 usable IPs.

Special ranges you will meet

  • 127.0.0.0/8: loopback, never leaves the machine.
  • 169.254.0.0/16: link-local. Cloud metadata services live at 169.254.169.254.
  • 100.64.0.0/10: carrier-grade NAT, also used by some Kubernetes and VPN setups.
  • 0.0.0.0: "all interfaces" when binding a server; "unknown" otherwise.

Production example

A team created an AKS cluster with Azure CNI in a /24 subnet. Each pod got a real VNet IP, so with 3 nodes × 30 pods plus nodes and reserved addresses, they ran out of IPs. New pods stuck in ContainerCreating with an IP allocation error. The fix was a larger subnet (/20) and later Azure CNI Overlay, where pods use a separate private CIDR that does not consume VNet addresses. The lesson: plan CIDR ranges for growth, and make sure they do not overlap with on-premises or peered networks.

🔍 What the interviewer is checking

Checks basic networking literacy that every backend and cloud engineer needs.

Green flags

  • Knows IPv4 vs IPv6 sizes and notation.
  • Can read CIDR and estimate subnet sizes.
  • Knows private ranges, loopback and NAT.
  • Bonus: cloud reserved IPs, Kubernetes pod CIDRs, IPv4-mapped IPv6.

Red flags

  • Cannot explain what /24 means.
  • Thinks every device has a unique public IPv4 address.

📚 Learn in depth

1. Reading a CIDR block

10.0.1.0/24

00001010 . 00000000 . 00000001 . 00000000
└───────── network (24 bits) ─────────┘ └ host (8) ┘

range: 10.0.1.0 – 10.0.1.255
mask:  255.255.255.0

Two hosts are on the same subnet if their network bits match; otherwise traffic goes via a router (the default gateway).

2. NAT

laptop 192.168.1.20:51544 ──► home router ──► 203.0.113.7:40001 ──► server 198.51.100.5:443
                              (rewrites source, remembers the mapping)
reply 198.51.100.5:443 ──► 203.0.113.7:40001 ──► router looks up mapping ──► 192.168.1.20:51544

Consequences:

  • Servers see the NAT's public IP, not the client's private IP.
  • Many clients behind one NAT share ports; heavy outbound traffic can exhaust SNAT ports (a common Azure and AWS NAT gateway issue).
  • Inbound connections to a private host need port forwarding or a load balancer.

3. IPv6 in practice

  • Addresses are often auto-configured (SLAAC) and every device can be globally reachable, so firewalls matter more than NAT.
  • Dual-stack hosts have both IPv4 and IPv6. localhost may resolve to ::1 first; a server bound only to 127.0.0.1 then refuses the connection.
  • .NET sockets created with AddressFamily.InterNetworkV6 and DualMode = true accept both.

4. Containers and Kubernetes

  • Docker's default bridge uses 172.17.0.0/16, and containers are NATed out through the host.
  • Kubernetes has a pod CIDR and a service CIDR. Service IPs are virtual; kube-proxy or eBPF translates them to pod IPs.
  • Overlapping CIDRs between a cluster and a peered VNet or VPN break routing in confusing ways.

5. .NET APIs

var ip = IPAddress.Parse("10.0.1.25");
var network = IPNetwork.Parse("10.0.0.0/16");   // System.Net.IPNetwork, .NET 8+
bool inside = network.Contains(ip);              // true
bool isLoopback = IPAddress.IsLoopback(ip);      // false

6. Try it yourself

  1. Run ip addr (Linux) or ipconfig (Windows) and identify your private IP, subnet mask and gateway.
  2. Visit a "what is my IP" site and compare with your private IP to see NAT.
  3. Calculate how many usable hosts are in 10.20.0.0/22 (1,024 minus reserved).
  4. In C#, check whether several IPs are inside 172.16.0.0/12 with IPNetwork.Contains.

💻 Code

// Allow-list check for an internal admin endpoint using CIDR ranges (.NET 8+ System.Net.IPNetwork)
var allowed = new[]
{
    IPNetwork.Parse("10.0.0.0/8"),
    IPNetwork.Parse("192.168.0.0/16"),
    IPNetwork.Parse("fd00::/8")
};

app.MapGet("/admin/health-details", (HttpContext ctx) =>
{
    var remote = ctx.Connection.RemoteIpAddress;
    if (remote is null) return Results.Forbid();
    if (remote.IsIPv4MappedToIPv6) remote = remote.MapToIPv4(); // ::ffff:10.0.0.5 → 10.0.0.5

    return allowed.Any(n => n.Contains(remote))
        ? Results.Ok(GetDetails())
        : Results.Forbid();
});
// Behind a proxy, RemoteIpAddress is the proxy's IP unless ForwardedHeaders is configured.
# Useful commands
ip addr show            # Linux interfaces and CIDRs
ip route                # default gateway and routes
ipconfig /all           # Windows
curl -s https://ifconfig.me   # public IP as seen from outside (after NAT)

⚠ Common mistakes

Mistake: Treating the IP the server sees as the user's real address. Why it is wrong: Behind NAT or a proxy it is the NAT gateway or proxy IP, and forwarded headers from untrusted sources can be spoofed. Instead: Read forwarded headers only from known proxies, and never use an IP alone as identity.

Mistake: Choosing tiny subnets for clusters. Why it is wrong: With CNIs that give pods VNet IPs (for example Azure CNI without overlay), a /24 fills up after a few nodes and new pods fail to start. Instead: Size for maximum nodes times pods per node plus reserved addresses, or use an overlay network.

Mistake: Overlapping CIDRs between networks that will be peered or joined by VPN. Why it is wrong: Routes become ambiguous and traffic silently goes to the wrong place. Instead: Plan one address scheme across environments and on-premises before creating networks.

Mistake: Comparing addresses without handling IPv4-mapped IPv6. Why it is wrong: A dual-mode Kestrel socket reports an IPv4 client as ::ffff:10.0.0.5, so a check against 10.0.0.0/8 fails and legitimate callers are blocked. Instead: Call MapToIPv4() when IsIPv4MappedToIPv6 is true, or include both forms in allow-lists.

Mistake: Thinking NAT is a security boundary. Why it is wrong: NAT only hides addresses; it does not filter outbound traffic, and with IPv6 there is often no NAT at all. Instead: Use firewalls, security groups and network policies explicitly for both IPv4 and IPv6.

🏛 Senior insight: trade-offs

Even as a junior topic, IP addressing drives real incidents: subnet exhaustion in Kubernetes, overlapping ranges after peering, SNAT port exhaustion on a NAT gateway, and allow-lists that break when traffic starts flowing through a proxy.

Topic IPv4 IPv6
Address shortage Yes, solved with private ranges and NAT No
NAT Common Usually unnecessary
Exposure Hidden behind NAT by default Globally routable; firewalls essential
Enterprise adoption Universal Growing; dual-stack is common during transition
Common pitfalls SNAT exhaustion, overlapping CIDRs Broken IPv6 paths causing slow fallback, missed firewall rules
Kubernetes networking choice IP usage Trade-off
Pods get VNet IPs (flat) High Direct routing to pods, needs large subnets
Overlay (separate pod CIDR) Low Saves VNet space, pods NATed for outbound

I keep in mind that IP addresses are routing information, not identity. I use them for coarse controls (private endpoints, firewall rules, network policies) and rely on authentication for anything that matters, and I block the metadata address for any feature that fetches user-supplied URLs.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions 0.0.0.0 or localhost Why: Checks ports, sockets and binding
    How to answer

    A port is a 16-bit number (0 to 65535) that lets one IP address host many services. A socket is the OS object for one endpoint: a listening socket bound to IP:port, and a connected socket for each accepted connection, identified by the 4-tuple (client IP, client port, server IP, server port).

    The Docker problem is almost always binding: the app listens on localhost (127.0.0.1) inside the container, which is unreachable from outside its network namespace, or it listens on a different port from the one you mapped. The official .NET 10 images set ASPNETCORE_HTTP_PORTS=8080, which binds all interfaces on 8080 (the default since .NET 8), so map it with -p 5000:8080 and do not override it with a localhost URL.

  2. When: Candidate mentions allow-lists or private ranges Why: Moves to firewalls and security groups
    How to answer

    A firewall allows or blocks traffic based on rules (source, destination, port, protocol, and for L7 firewalls/WAFs, HTTP content).

    • Stateful firewalls (Azure NSGs, AWS security groups, most host firewalls) track connections, so return traffic is automatically allowed. Stateless filters (AWS NACLs) need rules both ways.
    • Layers: host firewall (iptables/nftables, Windows Defender Firewall), cloud NSG/security group, network appliances, Kubernetes NetworkPolicy, and WAF at the edge.

    Troubleshoot by symptom: timeout usually means dropped by a firewall or routing, refused means reached the host but nothing listening, reset after idle often means a firewall or load balancer idle timeout removed the connection state. Test from the source (nc -vz, Test-NetConnection), check rules and flow logs in both directions, and set TCP keep-alives or shorter pool idle timeouts below the firewall's idle timeout.

↩ Usually asked after

More in Networking Basics

Last updated 23 Oct 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me