SkillPilotAI

Public vs private IP and special addresses

Not every IPv4 address can travel on the internet. Private addresses (RFC 1918) work only inside a LAN, public addresses are unique worldwide, and special ranges like loopback, APIPA, 0.0.0.0 and CGNAT each have a fixed meaning you must recognise on sight.

8.1 Why is it used?

  • Your laptop and your neighbour's laptop can both be 192.168.1.10 with no conflict: each address is used only inside its own home LAN.
  • Such reusable addresses are private IPs; they save the limited IPv4 space (about 4 billion addresses).
  • A reply sent on the internet directly to 192.168.1.10 is dropped: the address is not unique there.
  • Public IPs are unique on the whole internet, like a postal address.

8.2 How it works: NAT in one picture

NAT: private inside, public outside
  1. 1.Laptop sends a request with source 192.168.1.10

  2. 2.Home router replaces the source with its public IP 203.0.113.7

  3. 3.Packet crosses the internet to the website server

  4. 4.Server replies to 203.0.113.7

  5. 5.Router forwards the reply back to 192.168.1.10

Full NAT details come in a later video

8.3 RFC 1918: the three private ranges

RangeCoversTypical use
10.0.0.0/810.x.x.x (16+ million addresses)Big companies, cloud networks
172.16.0.0/12172.16.x.x to 172.31.x.xCompanies, Docker networks
192.168.0.0/16192.168.x.xHome routers (most common)
  • Free for anyone to use without permission, but never routed on the internet.
  • Public IPs flow IANA -> regional registry (APNIC for Asia) -> ISPs and companies; your ISP gives your router its public (WAN) IP.

8.4 Special addresses

Address / rangeNameMeaning
127.0.0.0/8LoopbackPacket never leaves the machine (localhost)
169.254.0.0/16APIPA / link-localDHCP failed; the OS picked its own address
0.0.0.0UnspecifiedServer: listen on all interfaces. Routing table 0.0.0.0/0: default route
255.255.255.255Limited broadcastAll devices on your own LAN; never forwarded by a router
Last address of a subnet (e.g. 192.168.1.255)Directed broadcastBroadcast for that network
100.64.0.0/10Shared / CGNATInside an ISP, many customers behind one public IP
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24TEST-NET (RFC 5737)Reserved for documentation and examples

8.5 Loopback and APIPA

  • ping 127.0.0.1: the OS receives the packet right back; the router never sees it.
  • The whole 127.0.0.0/8 is loopback; developers call it localhost to test a server on their own laptop.
  • Router off: the laptop's DHCP Discover broadcast gets no reply, so Windows picks e.g. 169.254.37.12 (APIPA, Automatic Private IP Addressing).
  • ipconfig shows 169.254.x.x = DHCP failed, internet will not work.
How APIPA happens
  1. 1.Router is off; laptop boots

  2. 2.Laptop broadcasts DHCP Discover

  3. 3.No DHCP reply comes back

  4. 4.Windows auto-configures 169.254.37.12

  5. 5.Only link-local talk works; no gateway, no internet

8.6 CGNAT: 100.64.0.0/10

  • IPv4 ran out, so many ISPs and mobile networks no longer give every home a public IP.
  • Your router gets a WAN IP like 100.72.15.9; your neighbour gets 100.72.15.10.
  • The ISP's CGNAT router replaces both sources with one shared public IP 198.51.100.20.
  • The website sees both homes as 198.51.100.20: Carrier Grade NAT.
CGNAT: two homes, one public IP
  1. 1.Your router (WAN 100.72.15.9) sends a request

  2. 2.ISP CGNAT replaces the source with 198.51.100.20

  3. 3.Neighbour's router (WAN 100.72.15.10) also goes through the same CGNAT

  4. 4.Website server sees both as 198.51.100.20

8.7 Practical: private IP vs public IP

Docker lab: laptop 192.168.28.10, server 192.168.28.20. iptype.sh is a small lab script that names the range of an IPv4 address.

Terminal
ip -4 addrcurl -s ifconfig.me | sh iptype.sh - --hide
Output
$ ip -4 addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536    inet 127.0.0.1/8 scope host lo2: eth0@if279: <BROADCAST,MULTICAST,UP,LOWER_UP>    inet 192.168.28.10/24 brd 192.168.28.255$ curl -s ifconfig.me | sh iptype.sh - --hidex.x.x.x (hidden) -> public (internet pe unique)
  • 192.168.28.10/24 is private; 127.0.0.1/8 on lo is loopback.
  • ifconfig.me replies with the address it saw: your public IP (hidden here because it is an office network).
  • On Windows compare ipconfig with ifconfig.me opened in a browser.

8.8 Practical: classify addresses

Terminal
sh iptype.sh 192.168.28.10sh iptype.sh 10.20.30.40sh iptype.sh 172.20.5.10sh iptype.sh 172.32.5.10sh iptype.sh 8.8.8.8sh iptype.sh 127.0.0.1sh iptype.sh 169.254.37.12sh iptype.sh 100.72.15.9sh iptype.sh 203.0.113.5sh iptype.sh 0.0.0.0sh iptype.sh 255.255.255.255
Output
192.168.28.10 -> private (RFC 1918, 192.168.0.0/16)10.20.30.40 -> private (RFC 1918, 10.0.0.0/8)172.20.5.10 -> private (RFC 1918, 172.16.0.0/12)172.32.5.10 -> public (internet pe unique)8.8.8.8 -> public (internet pe unique)127.0.0.1 -> loopback (127.0.0.0/8)169.254.37.12 -> link-local APIPA (169.254.0.0/16)100.72.15.9 -> shared CGNAT (100.64.0.0/10)203.0.113.5 -> documentation (RFC 5737)0.0.0.0 -> unspecified (this host / any)255.255.255.255 -> limited broadcast
  • 172.32.5.10 is public: the private 172 range ends at 172.31.
  • 169.254.37.12 = APIPA, 100.72.15.9 = CGNAT, 203.0.113.5 = documentation.

8.9 Practical: loopback ping

Terminal
ping -c 2 127.0.0.1ping -c 1 127.10.20.30
Output
$ ping -c 2 127.0.0.164 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.353 ms64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.047 ms2 packets transmitted, 2 received, 0% packet loss$ ping -c 1 127.10.20.3064 bytes from 127.10.20.30: icmp_seq=1 ttl=64 time=0.788 ms1 packets transmitted, 1 received, 0% packet loss$ ping -n 2 127.0.0.1   (Windows host)Reply from 127.0.0.1: bytes=32 time<1ms TTL=128Reply from 127.0.0.1: bytes=32 time<1ms TTL=128$ ping -n 1 127.10.20.30   (Windows host)Reply from 127.10.20.30: bytes=32 time<1ms TTL=128
  • Reply in under 1 ms: the packet never left the machine.
  • 127.10.20.30 also replies: the whole /8 is loopback (on Linux and Windows).

8.10 Practical: 127.0.0.1 vs 0.0.0.0

Terminal
nc -lk 127.0.0.1 8080nc -lk 0.0.0.0 9090ss -ltnnc -zv -w 2 192.168.28.20 8080nc -zv -w 2 192.168.28.20 9090
Output
$ ss -ltn   (on n008-server)State  Recv-Q Send-Q Local Address:Port  Peer Address:PortLISTEN 0      1          127.0.0.1:8080       0.0.0.0:*LISTEN 0      1            0.0.0.0:9090       0.0.0.0:*$ nc -zv -w 2 192.168.28.20 8080nc: connect to 192.168.28.20 port 8080 (tcp) failed: Connection refused$ nc -zv -w 2 192.168.28.20 9090Connection to 192.168.28.20 9090 port [tcp/*] succeeded!
  • Listener on 127.0.0.1:8080 is reachable only from the server itself: the laptop gets Connection refused.
  • Listener on 0.0.0.0:9090 accepts on all interfaces: the laptop connects successfully.
Why the laptop is refused on 8080
  1. 1.Laptop 192.168.28.10 connects to 192.168.28.20:8080

  2. 2.Server listens on 127.0.0.1:8080 only (loopback) -> Connection refused

  3. 3.Laptop connects to 192.168.28.20:9090

  4. 4.Server listens on 0.0.0.0:9090 (all interfaces) -> succeeded!

8.11 Common mistakes

  • Treating 127.0.0.1 and 0.0.0.0 as the same: loopback = only this machine, 0.0.0.0 = all addresses of this machine.
  • Binding a container or server to 127.0.0.1 and wondering why other machines cannot reach it.
  • Thinking 172.x is always private: only 172.16 to 172.31.
  • Ignoring a 169.254.x.x address: it means DHCP failed, not that the network is fine.

8.12 Interview tips

  • Private vs public: private = RFC 1918 ranges, unique only inside the LAN, not routed; public = unique on the internet, allotted by the ISP. NAT replaces the private source with the public IP.
  • Recite the three ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16.
  • 127.0.0.0/8 loopback, 169.254.0.0/16 APIPA, 100.64.0.0/10 CGNAT.
  • 0.0.0.0 = any / all interfaces (and 0.0.0.0/0 = default route); 255.255.255.255 = limited broadcast.
  • 172.25.10.5 private, 172.40.10.5 public, 100.70.1.1 CGNAT.