Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
IP — The Layer Underneath  ›  Lesson

IP Addresses — IPv4, IPv6 and DNS

IP Addressing 12 minEvery host is reached by an IP address, 32-bit IPv4 or 128-bit IPv6, which a program usually gets from DNS, and home routers rewrite addresses and ports with NAT.

IP Addresses — IPv4, IPv6 and DNS

Every TCP connection and UDP datagram so far has quietly needed one thing: an address for the other end. The Manja Arena client knows only a name, mumbai.manja-arena.example. Getting from that name to a machine in Mumbai takes two ideas, IP addresses and DNS.

The rule

Names are for people, addresses are for routers; DNS translates between them.

An IP address identifies a network interface on the internet. Two versions are in use:

  • IPv4 — 32 bits, written as four numbers from 0 to 255: 203.0.113.10. That allows about 4.3 billion addresses, which is not enough for every device on Earth.
  • IPv6 — 128 bits, written as eight groups of four hex digits separated by colons. Leading zeros in a group may be dropped, and one run of all-zero groups may be shortened to ::, so 2001:0db8:0000:0000:0000:0000:0000:0007 becomes 2001:db8::7. The :: may appear only once, or nobody could tell how many zeros each one hides.

DNS, the Domain Name System, turns names into addresses. The client asks about a name and gets back records: an A record holds an IPv4 address and an AAAA record holds an IPv6 address. Answers are cached for as long as each record says, so repeat lookups are almost instant.

Most homes have a single public IPv4 address shared by many devices. The home router performs NAT, network address translation: it rewrites each outgoing packet's private source address, such as 192.168.1.23, into its own public one, and it often changes the source port as well. The Mumbai server therefore sees the router's address and a port the router chose. If the router restarts, or forgets a mapping that sat idle, that port can change in the middle of a match.

The shortcut

To reach a server: name → DNS → addresses → try them in turn. To recognise a player: use a session token, never the address alone.

A Delhi player joins a matchStep 1 of 4
  1. Resolve

    The client asks DNS about mumbai.manja-arena.example and gets an A record, 203.0.113.10, and an AAAA record, 2001:db8::7.

Drills

Answer fast — trust the rule.

quick drill

How many bits are in an IPv4 address?

quick drill

Which of these is a valid IPv6 address?

quick drill

Which DNS record type holds an IPv6 address?

quick drill

A player's laptop has the address 192.168.1.23 on their home network. Which address does the Mumbai server see?

quick drill

Why does Manja Arena recognise players by a session token rather than by address and port alone?

Remember

  • Names are for people, addresses are for routers; DNS translates between them.
  • IPv4 is 32 bits in dotted decimal; IPv6 is 128 bits in hex, with at most one ::.
  • Trap: using address and port as a player's identity when NAT can change them.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainFrom a name to the first packet

Walk through what happens from the moment a Manja Arena client knows only the name mumbai.manja-arena.example to the server receiving its first packet, and explain why the server should not identify the player by address and port alone.