The IPv4 Protocol
1. IPv4 Overview
IPv4 (Internet Protocol version 4) is the core protocol of the Internet. It provides the network layer with a connectionless datagram service.
Basic Characteristics
- Connectionless protocol: every packet is handled independently
- Best effort service: reliable transfer is not guaranteed
- 32-bit addresses: roughly 4.3 billion addresses
- Globally unique: every device has a unique IP address
2. The IPv4 Datagram Structure
Version and Header Length
- Version (4 bits): the protocol version, 4 for IPv4
- Header length (4 bits): measured in 4-byte units, at most 60 bytes
Type of Service
- Precedence (3 bits): the packet priority
- D bit: the delay requirement
- T bit: the throughput requirement
- R bit: the reliability requirement
Total Length and Identification
- Total length (16 bits): the length of the whole packet
- Identification (16 bits): used to reassemble fragments
Flags and Fragment Offset
- Flags (3 bits):
- DF bit: the do-not-fragment flag
- MF bit: the more-fragments flag
- Fragment offset (13 bits): the position of the fragment within the original packet
Time To Live and Protocol
- Time To Live (8 bits): the maximum number of hops the packet may take
- Protocol (8 bits): the upper layer protocol type (TCP=6, UDP=17)
Checksum and Addresses
- Header checksum (16 bits): an integrity check of the header
- Source address (32 bits): the sender’s IP address
- Destination address (32 bits): the receiver’s IP address
Options and Data
- Options (variable): optional fields
- Data (variable): upper layer protocol data
3. IPv4 Addresses
Address Structure
- 32 bits in binary: divided into four 8-bit segments
- Dotted decimal: each segment written in decimal and separated by dots
- Network part: identifies the network
- Host part: identifies the host
Address Classes
Class A addresses:
- Range: 1.0.0.0 - 126.255.255.255
- Network bits: 8 bits
- Host bits: 24 bits
- Default mask: 255.0.0.0
Class B addresses:
- Range: 128.0.0.0 - 191.255.255.255
- Network bits: 16 bits
- Host bits: 16 bits
- Default mask: 255.255.0.0
Class C addresses:
- Range: 192.0.0.0 - 223.255.255.255
- Network bits: 24 bits
- Host bits: 8 bits
- Default mask: 255.255.255.0
Class D addresses:
- Range: 224.0.0.0 - 239.255.255.255
- Purpose: multicast addresses
Class E addresses:
- Range: 240.0.0.0 - 255.255.255.255
- Purpose: reserved addresses
Special Addresses
- Network address: the host part is all zeros
- Broadcast address: the host part is all ones
- Loopback address: 127.0.0.0/8
- Private addresses:
- Class A: 10.0.0.0/8
- Class B: 172.16.0.0/12
- Class C: 192.168.0.0/16
4. Subnetting
Subnet Masks
- Network part: the bits corresponding to 1s in the mask
- Host part: the bits corresponding to 0s in the mask
- CIDR notation: a slash followed by the number of network bits
Subnetting Steps
- Determine the number of subnets: how many subnets are needed
- Compute the number of network bits: 2^n ≥ the number of subnets
- Determine the subnet mask: the mask that corresponds to the number of network bits
- Compute the subnet addresses: the network address of each subnet
- Determine the host range: the range of host addresses in each subnet
Example
Network: 192.168.1.0/24, split into 4 subnets
- Number of subnets: 4, which requires 2 network bits
- New mask: 255.255.255.192 (/26)
- Subnets:
- 192.168.1.0/26 (0-63)
- 192.168.1.64/26 (64-127)
- 192.168.1.128/26 (128-191)
- 192.168.1.192/26 (192-255)
5. CIDR (Classless Inter-Domain Routing)
Basic Concepts
- Classless addressing: the address space is no longer split into classes A, B, and C
- Flexible allocation: networks are divided as needed
- Smaller routing tables: entries are aggregated
- Higher efficiency: the routing table shrinks
Address Aggregation
- Prefix matching: addresses that share a prefix can be aggregated
- Longest match: the most specific route is chosen
- Fewer entries: several routing entries merge into one
6. Supporting Protocols
The ARP Protocol (Address Resolution Protocol)
Function: convert an IP address into a MAC address
How it works:
- Send an ARP request packet
- The target host replies with an ARP reply packet
- Establish the mapping from IP address to MAC address
- Cache the mapping information
The ARP table: stores the mapping from IP address to MAC address
The DHCP Protocol (Dynamic Host Configuration Protocol)
Function: assign IP addresses automatically
How it works:
- DHCP Discover: the client broadcasts to find a DHCP server
- DHCP Offer: the server offers an IP address
- DHCP Request: the client requests to use the offered address
- DHCP Acknowledge: the server confirms the address assignment
What is assigned:
- IP address
- Subnet mask
- Default gateway
- DNS servers
The ICMP Protocol (Internet Control Message Protocol)
Function: network diagnostics and error reporting
Message types:
- Echo request/reply: the ping command
- Destination unreachable: a routing failure
- Time exceeded: the TTL was exhausted
- Redirect: a better route exists
Applications:
- ping: connectivity testing
- traceroute: path tracing
- network diagnostics
Exercise 1
What are the differences between IPv4 addresses and IPv6 addresses?
Approach: compare the two on six properties, in order of practical impact.
Steps:
The main differences are:
-
Address length:
- IPv4: 32-bit addresses
- IPv6: 128-bit addresses
-
Address space:
- IPv4: about 4.3 billion addresses
- IPv6: about 340 trillion addresses
-
Address notation:
- IPv4: dotted decimal (192.168.1.1)
- IPv6: colon-separated hexadecimal (2001:db8::1)
-
Header structure:
- IPv4: complex, with an options field
- IPv6: simplified, a fixed 40 bytes
-
Functional characteristics:
- IPv4: requires NAT, and security is weaker
- IPv6: security and mobility are built in
-
Address assignment:
- IPv4: manual or DHCP
- IPv6: automatic, using stateless address configuration
Answer: IPv6 doubles the address length to 128 bits, shrinks the header to a fixed 40 bytes, and adds built-in security, mobility, and stateless address configuration, which is what removes IPv4’s need for NAT and its address exhaustion problem.
Exercise 2
What is CIDR, and what are its advantages?
Approach: state the definition in three points, then list the five advantages.
Steps:
CIDR (Classless Inter-Domain Routing):
Definition:
- The address space is no longer divided into the traditional classes A, B, and C
- Networks are divided flexibly according to actual need
- Slash notation is used (for example 192.168.1.0/24)
Advantages:
-
High address utilization:
- avoids wasting addresses
- allocates addresses according to actual need
-
Fewer routing table entries:
- address aggregation reduces the number of routing entries
- improves routing lookup efficiency
-
Simpler management:
- flexible address allocation
- easier network planning
-
Supports supernetting:
- combines several small networks into one large network
- reduces the size of the routing table
-
Higher efficiency:
- fewer routing updates
- better network performance
Answer: CIDR replaces class-based addressing with variable-length prefixes, which raises address utilization, allows route aggregation to shrink the routing tables, and simplifies both address allocation and network planning.
| Term | Abbreviation | Explanation |
|---|---|---|
| Internet Protocol version 4 | IPv4 | The IP protocol with 32-bit addresses |
| Subnet Mask | - | Separates the network bits from the host bits |
| Classless Inter-Domain Routing | CIDR | Variable-length subnet masks |
| Network Address Translation | NAT | Converts private addresses into public addresses |
| Address Resolution Protocol | ARP | Converts an IP address into a MAC address |
| Internet Control Message Protocol | ICMP | Error and control messages |
| Dynamic Host Configuration Protocol | DHCP | Automatic IP address assignment |
| Time To Live | TTL | The maximum hop count of a packet |
| Fragmentation | - | Splitting a large packet into smaller fragments |
| Header Checksum | - | The checksum field of the IP header |
| Type of Service | ToS | The QoS priority field |
| Identification | - | The identifier used for fragment reassembly |
| Private Address | - | An internal address that is not routable |
| Broadcast Address | - | All the hosts on the same network |
