Networking Fundamentals

IP Addresses, Subnets and Routing

35 دقيقة

IPv4 addresses

An IPv4 address is 32 bits written as four numbers from 0 to 255: 203.0.113.10. There are only about 4.3 billion, which is why we have private ranges and NAT.

CIDR notation

10.0.1.0/24 means: the first 24 bits are the network, the remaining 8 bits identify hosts.

CIDR Addresses Typical use
/32 1 one specific host (firewall rules)
/24 256 a typical subnet
/16 65,536 a cloud VPC
/0 everything "anywhere" (0.0.0.0/0)

Each step down in the prefix doubles the size. /23 is 512 addresses, /25 is 128.

Private ranges

These never route on the public internet, so every home and cloud network can reuse them:

  • 10.0.0.0/8
  • 172.16.0.0/12
  • 192.168.0.0/16

Also special: 127.0.0.1 (localhost, this machine) and 0.0.0.0 (when a server listens on it, it means "all interfaces").

The difference matters on servers: an app listening on 127.0.0.1:8000 is reachable only from the machine itself; on 0.0.0.0:8000 it is reachable from any network the machine is on.

NAT

Your home router has one public IP. Network Address Translation rewrites outgoing packets from private addresses to that public one and tracks replies. Cloud "NAT gateways" do the same for private servers that need to download updates without being reachable from outside.

IPv6

128-bit addresses written in hex: 2001:db8::1. There are enough for every device to have a public address, so NAT is unnecessary. Firewalls matter even more for IPv6 because devices may be directly reachable. Many providers now give servers IPv6 by default; make sure your firewall rules cover it (ufw handles both).

Routing

Each machine has a routing table deciding where packets go.

ip route
# default via 10.0.0.1 dev eth0         <- everything else goes to the gateway
# 10.0.0.0/24 dev eth0 proto kernel     <- local subnet, deliver directly

The default gateway is the router that handles everything not on the local network. Wrong or missing default routes are a classic cause of "can reach the local network but not the internet".

Seeing your addresses

ip -brief addr
curl -4 ifconfig.me      # your public IPv4 as seen from outside

Check yourself

  • How many addresses are in a /26?
  • What is the difference between listening on 127.0.0.1 and 0.0.0.0?
  • Why does IPv6 make firewalls more important?

يُحفظ تقدّمك في هذا المتصفح فقط.

إرسال للمراجعة (10 نقطة)