Private vs Public IP Addresses — Understanding Internet and Internal Network Communication¶
Every device connected to a network requires an IP address, but not every IP address is accessible from the Internet. Some IP addresses are reserved for private internal networks, while others are globally unique and reachable across the Internet. Understanding the difference between Private and Public IP Addresses is essential for designing enterprise networks, configuring cloud infrastructure, implementing security, and troubleshooting connectivity issues. Every Linux administrator, DevOps engineer, Cloud Architect, Platform Engineer, Site Reliability Engineer (SRE), and Network Engineer should master this concept.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand Public IP addresses
- Understand Private IP addresses
- Identify private IP ranges
- Explain Network Address Translation (NAT)
- Understand Internet routing
- Design private enterprise networks
- Troubleshoot public/private IP issues
Prerequisites¶
Complete:
Why Learn Public and Private IP Addresses?¶
Suppose your laptop has the IP address:
Can someone on the Internet connect directly to your laptop?
The answer is:
Now consider a web server with the IP:
Anyone on the Internet can reach it (assuming firewall rules allow access).
Why?
Because one address is private, while the other is public.
What is a Public IP Address?¶
A Public IP Address is a globally unique IPv4 address that is routable on the Internet.
Public IP addresses are assigned by:
- Internet Service Providers (ISPs)
- Cloud Providers
- Regional Internet Registries (RIRs)
They allow devices and services to communicate across the Internet.
Public IP Example¶
These addresses are globally reachable.
Where Are Public IPs Used?¶
Public IPs are assigned to:
- Websites
- Cloud Virtual Machines
- Load Balancers
- Virtual Private Network (VPN) Gateways
- Mail Servers
- Domain Name System (DNS) Servers
- Internet-facing Application Programming Interfaces (APIs)
Characteristics of Public IP Addresses¶
- Globally unique
- Internet routable
- Assigned by authorised providers
- Reachable from anywhere (subject to security controls)
- Limited IPv4 resource
What is a Private IP Address?¶
A Private IP Address is reserved for use inside private networks.
Private IP addresses:
- Are not routable on the Internet
- Can be reused by different organisations
- Require NAT for Internet access
RFC 1918 Private Address Ranges¶
The following ranges are reserved for private use:
| Range | CIDR | Historical Class |
|---|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | Class A |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | Class B |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | Class C |
These ranges are defined in RFC 1918.
Private IP Examples¶
These addresses are valid only within private networks.
Public vs Private IP¶
| Public IP | Private IP |
|---|---|
| Internet Routable | Local Network Only |
| Globally Unique | Reusable |
| Assigned by ISP/Cloud | Assigned Locally |
| Used for Public Services | Used Inside Organisations |
| Accessible from Internet | Requires NAT for Internet Access |
Why Do We Need Private IP Addresses?¶
Imagine every smartphone, laptop, printer, and Internet of Things (IoT) device required a public IPv4 address.
The available IPv4 space would be exhausted very quickly.
Private addressing allows millions of devices to share a smaller pool of public addresses through NAT.
What is NAT?¶
Network Address Translation (NAT) converts private IP addresses into public IP addresses.
Example:
To Internet servers, the traffic appears to come from the public IP.
Example Communication¶
Laptop:
Website:
Communication:
The router replaces the private source IP with its public IP before sending packets to the Internet.
Why Can't Private IPs Reach the Internet Directly?¶
Internet routers do not forward RFC 1918 private addresses.
Example:
Internet routers discard these routes because they are intended only for private networks.
Home Network Example¶
All devices in the home share the router's public IP through NAT.
Enterprise Network Example¶
Thousands of internal devices may access the Internet using only a few public IP addresses.
Cloud Example¶
Cloud Virtual Private Clouds (VPCs) primarily use private IP addresses.
Example:
To make it accessible from the Internet:
This improves security by limiting direct exposure.
Kubernetes Example¶
Inside a Kubernetes cluster:
Pods:
Services:
These are private addresses.
External users connect through:
- Ingress
- Load Balancer
- Public IP
Advantages of Private IP Addresses¶
- Conserves public IPv4 addresses
- Improves security
- Supports internal communication
- Simplifies enterprise network design
- Reduces Internet exposure
Advantages of Public IP Addresses¶
- Internet accessibility
- Global uniqueness
- Required for public-facing services
- Enables external communication
Viewing Your Private IP¶
Display your private IP address.
or
Viewing Your Public IP¶
Display your Internet-facing IP address.
Example output:
This is the address visible to external systems.
Production Perspective¶
Enterprise environments commonly use:
Private IPs for:
- Application Servers
- Databases
- Kubernetes Nodes
- Internal APIs
- Storage Systems
Public IPs for:
- Load Balancers
- VPN Gateways
- Bastion Hosts
- Public APIs
- Web Applications
This separation enhances both security and scalability.
Cloud Perspective¶
Cloud providers typically assign:
Private IPs:
- Virtual Machines
- Kubernetes Nodes
- Databases
- Internal Load Balancers
Public IPs:
- Internet-facing Load Balancers
- Bastion Hosts
- NAT Gateways
- Public APIs
Most cloud workloads communicate internally using private IP addresses.
Hands-on Lab¶
Task 1¶
Display your private IP address.
Task 2¶
Display your assigned IP addresses.
Task 3¶
Display your public IP address.
Task 4¶
Determine whether the following addresses are public or private:
Task 5¶
Draw a home network showing:
- Laptop
- Router
- Internet
Identify the private and public IP addresses used.
Task 6¶
Draw an enterprise network showing:
- Users
- Firewall
- NAT Gateway
- Internet
Explain how NAT works.
Task 7¶
Research how your cloud provider assigns private and public IP addresses to virtual machines.
Task 8¶
Design a small office network using:
- 20 employee computers
- One file server
- One web server
- One Internet connection
Assign appropriate private IP addresses and explain which systems require public IP access.
Linux Commands¶
| Command | Purpose |
|---|---|
ip addr | Display private IP addresses |
hostname -I | Display assigned IPs |
ip route | Display default gateway |
curl ifconfig.me | Display public IP |
ping | Test connectivity |
Common Mistakes¶
❌ Assuming private IPs are Internet reachable.
✅ Private IPs require NAT or a VPN to communicate beyond private networks.
❌ Exposing every server with a public IP.
✅ Use private IPs wherever possible and publish services through load balancers or reverse proxies.
❌ Confusing private ranges with loopback addresses.
✅ Loopback uses 127.0.0.0/8; private ranges are defined by RFC 1918.
❌ Believing every cloud VM requires a public IP.
✅ Most cloud workloads operate using private IPs only.
❌ Ignoring NAT.
✅ Understand that NAT enables private networks to access the Internet.
Best Practices¶
- Use private IP addresses for internal systems.
- Expose only necessary services through public IP addresses.
- Implement NAT to provide Internet access for private networks.
- Restrict Internet-facing services with firewalls and security groups.
- Document IP address assignments and network architecture.
Interview Questions¶
Beginner¶
- What is a public IP address?
- What is a private IP address?
- List the RFC 1918 private IPv4 ranges.
- Why are private IP addresses used?
Intermediate¶
- Explain how NAT works.
- Why can't private IP addresses be routed over the Internet?
- Compare public and private IP addresses.
- When would you assign a public IP to a server?
Architect Level¶
- Design an enterprise network using public and private IP addresses.
- Explain how cloud providers separate internal and external traffic.
- How would you securely expose a Kubernetes application to the Internet?
Summary¶
In this lesson, you learned:
- Public IP addresses
- Private IP addresses
- RFC 1918 address ranges
- NAT (Network Address Translation)
- Internet routing
- Enterprise and cloud networking
- Linux commands for viewing public and private IPs
Private and public IP addresses work together to enable secure, scalable networking. Private IPs support internal communication while conserving IPv4 address space, and public IPs enable communication across the Internet. NAT bridges these two worlds, making modern enterprise and cloud networking possible.
Key Takeaways¶
- Public IP addresses are globally routable.
- Private IP addresses are reserved for internal networks.
- RFC 1918 defines the three private IPv4 ranges.
- NAT translates private addresses into public addresses for Internet access.
- Most enterprise and cloud workloads communicate using private IP addresses.