Linux online course

What Is an IP Address? IPv4, Private Addresses, and Public Addresses

Learn what an IP address is, how IPv4 addresses work, and the difference between private and public addresses. Includes DHCP, NAT, IPv6, and Linux commands.

An IP address is a logical network-layer identifier used by Internet Protocol networking. It identifies a network interface so that devices can determine the source and destination of network traffic.

IP addresses are part of the TCP/IP protocol suite, which includes IP and transport protocols such as TCP. When your computer sends data to another network, the IP address helps routers forward that data toward its destination. The receiving device uses the destination address to determine whether the traffic belongs to it.

A device can communicate locally at the link layer without a complete IP configuration in some situations, but it generally needs an IP address, a subnet configuration, and often a default gateway to communicate through an IP network or beyond the local network.

IPv4 Address Format

IPv4, or Internet Protocol version 4, uses a 32-bit address space. An IPv4 address is normally written as four decimal numbers separated by dots:

10.50.201.1

Each number is an octet, meaning an 8-bit component. Since an 8-bit value has 256 possible values, each octet ranges from 0 through 255. Four octets make 32 bits in total.

  • 10 is the first octet.
  • 50 is the second octet.
  • 201 is the third octet.
  • 1 is the fourth octet.

The address 10.50.201.1 is also inside the private 10.0.0.0/8 range. In introductory networking, the phrase “IP address” commonly refers to an IPv4 address, although IPv6 is also an IP addressing system.

What an IP Address Does

An IP address has two closely related purposes:

  • It identifies the source of an IP packet, or unit of network-layer traffic.
  • It identifies the destination to which routers and hosts should deliver that packet.

An IP address is assigned to a network interface, such as an Ethernet adapter, Wi-Fi adapter, or virtual interface. A single computer can have several interfaces and therefore several IP addresses. Addresses can also change when a device moves between networks or receives a new DHCP lease.

IP Addresses Versus MAC Addresses

An IP address and a MAC address identify interfaces at different networking layers and serve different purposes.

ConceptAddress size or layerPrimary roleExample
IPv432 bitsLogical addressing and routing between networks192.168.1.25
IPv6128 bitsLogical addressing and routing between networks2001:db8::10
MAC addressLink layerLocal network interface identification00:11:22:33:44:55

A MAC address is used for delivery on the local network, such as an Ethernet or Wi-Fi network. An IP address is used for logical routing between networks. IP configuration can be changed when an administrator or network service assigns a different address. A MAC address has a different purpose and is not necessarily permanently unchangeable: operating systems and hardware can support administrative changes or MAC randomization.

How IP Addresses Are Assigned

Static or Manual Assignment

A static IP address is configured manually or reserved so that a device can keep the same address. A static IPv4 setup normally requires:

  • An IPv4 address.
  • A subnet mask or prefix length, which identifies the local network portion of the address.
  • A default gateway, which is the router used for destinations outside the local subnet.
  • DNS servers, which translate domain names into IP addresses.

Servers may use stable addresses so that clients can consistently reach services. Static configuration must be planned carefully to avoid assigning the same address to two devices.

Dynamic Assignment with DHCP

DHCP, or Dynamic Host Configuration Protocol, automatically supplies network configuration. A DHCP server leases addressing information to a client. The lease commonly includes an IP address, subnet mask or prefix, default gateway, and DNS servers.

Home routers commonly provide DHCP to devices on the local network. A workstation can therefore connect to a home network and receive an address without an administrator entering every setting manually. The address may remain the same for a while, but a DHCP lease is not the same as a permanent static assignment.

Private IPv4 Addresses

A private IP address is an IPv4 address from address space intended for internal networks, such as a home, office, or organizational LAN. Private addresses are not globally routable on the public Internet. The same private ranges can be reused independently by many separate networks because those networks are not using one shared global address space.

CIDR blockFirst addressLast addressTypical use
10.0.0.0/810.0.0.010.255.255.255Large private networks
172.16.0.0/12172.16.0.0172.31.255.255Private organizational networks
192.168.0.0/16192.168.0.0192.168.255.255Home and small-office networks

For example, a home router might give a laptop the private address 192.168.1.25. That address is meaningful within the home network, but it is not a unique public identity that Internet routers can use to send traffic directly to the laptop.

Public IPv4 Addresses

A public IP address is an address that can be routed on the Internet when it is correctly configured and permitted by network policy. An ISP, or Internet Service Provider, commonly assigns a public address to an Internet-facing router or host.

In a typical home network, the laptop and other local devices have private LAN addresses. The router has a public address on its WAN, or Internet-facing, interface. The router uses NAT, or Network Address Translation, to allow several private-network devices to share one public IPv4 address for outbound Internet connections.

PropertyPrivate IPv4 addressPublic IP address
Internet routabilityNot directly globally routableRoutable on the Internet when properly configured
Typical assignment sourceLocal router, DHCP server, or manual setupISP or another Internet address provider
Typical locationLAN interfaceRouter WAN interface or directly connected host

NAT does not turn a private address into a public address on the device. Instead, the router tracks connections and translates traffic between private LAN addresses and its public address.

IPv6 Overview

IPv6, or Internet Protocol version 6, is the newer major IP addressing version. IPv6 addresses are 128 bits long, compared with IPv4's 32 bits. They are usually written as hexadecimal groups separated by colons.

2001:db8:1234::10

The example above is IPv6, not IPv4. IPv6 has a much larger address space and uses different address notation. This lesson focuses primarily on IPv4, private addresses, and public addresses.

Viewing IP Information on Linux

Modern Linux systems provide the ip command for inspecting interfaces and addresses. Interface names vary by system; common names include eth0, enp1s0, and wlan0.

Show All Interface Addresses

ip addr show

This displays interfaces and their assigned IPv4 and IPv6 addresses. An address such as 192.168.1.25/24 is a local address with a prefix length of 24.

Show Only IPv4 or IPv6 Addresses

ip -4 addr show
ip -6 addr show

Show Routes and the Default Gateway

ip route show

Look for a line beginning with default. It identifies the route used for destinations outside the local network and normally includes the default gateway.

Quickly Print Local Addresses

hostname -I

This is a convenient quick check, but it is not a reliable way to discover the public Internet-facing address. It normally prints addresses assigned to the local host, which may be private addresses.

Check the Public Address Observed Externally

curl https://api.ipify.org

If curl and Internet access are available, this asks an external service which public address it observes. On a home network, that result commonly differs from the private address shown by ip addr show because the router performs NAT.

Typical Home Network Example

Suppose a home router runs a DHCP service. A laptop joins Wi-Fi and receives 192.168.1.25. The laptop also receives a subnet configuration, the router's local address as its default gateway, and DNS server information.

When the laptop connects to a website, it sends traffic to the router. The router translates the laptop's private source address and connection details to its public WAN address, then forwards the traffic to the Internet. Replies return to the router, which translates them back and delivers them to the laptop.

Office Network Example

An organization can use private addresses from the 172.16.0.0/12 range for internal departments. A firewall or edge router controls traffic between internal networks and the Internet. Different organizations can reuse the same private range without conflict because their internal networks are separate.

Troubleshooting IP Connectivity

No Usable IP Address

If a system has no usable IP address, possible causes include a disconnected or disabled interface, a failed DHCP request, or an incomplete static configuration.

  1. Run ip addr show and inspect the interface state and assigned addresses.
  2. Check the Ethernet cable or Wi-Fi connection.
  3. Review the DHCP client or network manager status.
  4. If the address is static, verify the address, prefix length, gateway, and DNS settings.

Private Address but No Internet Access

A private address alone does not guarantee Internet access. Possible causes include a missing default gateway, an offline router, DNS failure, or firewall and NAT policy blocking traffic.

  1. Run ip route show and look for a default route.
  2. Test connectivity to the local gateway.
  3. Test a known public IP address.
  4. Test a domain name to distinguish general connectivity problems from DNS problems.

Intermittent Connectivity Between Devices

Two devices with the same manually assigned IPv4 address can intermittently lose connectivity or reach the wrong host. Verify that every host has a unique address in the subnet. DHCP reservations can provide stable addresses while avoiding conflicts, and manually assigned addresses should be excluded from the DHCP allocation pool.

Local and External Addresses Differ

It is normal for ip addr show to display a private address while an external IP-check service reports a different public address. This usually means the device is behind a NAT router. The local address identifies the device inside the LAN; the external service sees the router's public address.

Key Points

  • An IP address is a logical identifier assigned to a network interface for Internet Protocol communication.
  • IPv4 uses 32 bits and four decimal octets, each ranging from 0 through 255.
  • IP addresses support logical routing between networks; MAC addresses support local link-layer delivery.
  • DHCP leases addresses and related settings automatically; static addresses are configured or reserved for stability.
  • RFC 1918 private ranges are 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16.
  • Home devices commonly use private addresses while the router uses an ISP-provided public address.
  • NAT allows multiple private devices to share a public IPv4 address.
  • IPv6 uses 128-bit addresses written in colon-separated hexadecimal notation.