linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Networking: L2 / L3/ipv4-addressing

kb/network-l2-l3 ── Networking: L2 / L3 ── beginner

IPv4: Addressing and CIDR

An IPv4 address is 32 bits written as `a.b.c.d`. The **/N** suffix is the prefix length: `/24` fixes the first 24 bits for the network and leaves 8 bits for hosts (256 addresses).

view as markdownaka: ipv4, cidr, subnet

Address structure

An IPv4 address is a 32-bit number written as four decimal bytes separated by dots: 192.168.1.10. That is simply 0xC0A8010A, or 11000000.10101000.00000001.00001010 in binary.

The network prefix (CIDR) specifies how many left-hand bits belong to the network portion. 192.168.1.0/24 means the first 24 bits (192.168.1) are the same for every address in that network; the remaining 8 bits form the host range.

How many hosts fit in /N

prefixsubnet maskhost rangeexamples
/8255.0.0.016 777 21410.0.0.0/8 (RFC1918)
/16255.255.0.065 534172.16.0.0/16
/24255.255.255.0254192.168.1.0/24 (home network)
/29255.255.255.2486small point-to-point for 4 devices
/30255.255.255.2522classic p2p link
/31255.255.255.2542 (RFC 3021)optimized p2p, no reserved addresses
/32255.255.255.2551single address (loopback, host route)

The N-2 subtraction applies because the network address (all zeros in the host part) and the broadcast address (all ones) are normally reserved.

Reserved ranges (RFC 1918 and others)

rangepurpose
10.0.0.0/8private networks (large)
172.16.0.0/12private (Docker default)
192.168.0.0/16private (home routers)
127.0.0.0/8loopback (local interfaces)
169.254.0.0/16link-local (assigned when DHCP gives no address)
224.0.0.0/4multicast
0.0.0.0/0"any address", used as the default route

Addresses from private ranges are not routed to the internet, so reaching the outside requires nat.

Viewing addresses on a machine

bash
ip -4 addr                    # all IPv4 addresses on all interfaces
ip -4 -br addr                # compact view: name/state/IP/prefix
hostname -I                    # all host IP addresses (no mask)

An address can have one of three scopes:

  • scope global - reachable publicly (or privately via NAT)
  • scope host - loopback only (for example 127.0.0.1)
  • scope link - reachable only within one broadcast domain

§ команды

bash
ip -4 addr show

Show all IPv4 addresses on every interface, including prefix length.

bash
ipcalc 192.168.1.10/24

Calculate network address, broadcast, and host range (requires `ipcalc` to be installed).

bash
sudo ip addr add 10.0.0.5/24 dev eth0

Add an IP address to an interface. Requires NET_ADMIN capability.

bash
sudo ip addr del 10.0.0.5/24 dev eth0

Remove an IP address from an interface.

bash
ip route get 8.8.8.8

Show which source IP and interface the kernel would use for a packet to 8.8.8.8, including the automatically selected source address.

§ см. также

  • subnetting-cidrSubnetting and CIDRCIDR /N specifies how many of the 32 bits (or 128 for IPv6) belong to the network. /24 gives 256 addresses, /30 gives 4 (p2p), /16 gives 65536. A host in a subnet can communicate directly only with hosts that share the same prefix.
  • routing-tableRouting tableThe routing table lists where to send packets for each destination. The longest matching prefix wins.
  • arpARP: Address Resolution ProtocolARP answers the question "who has MAC = ?" for a given IP inside one network. Linux keeps the result in the neighbor table (`ip neigh`).
  • dhcp-protocolDHCP: Dynamic Host Configuration ProtocolDHCP gives a host its IP address, subnet mask, gateway, and DNS via broadcast. 4 packets: DORA = Discover (client), Offer (server), Request (client), Ack (server). The lease renews at 50% of the TTL.

§ упоминается в уроках

  • ›intermediate-01-network-101
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.