IPv4 Addressing
This page provides introduction to IPv4 Addressing.
Overview
Layer uses MAC addresses, which are assigned to a device during manufacturing. At layer , IP addresses serve as logical addresses that are assigned during device configuration. Routers operate at layer .
In diagram below we have network connected by switches.
Let's say if we add a router between Switch and Switch , the PCs will be split into two separate networks instead of being part of a single network.
Two networks are:
- Network :
- Network :
In both networks, the subnet mask indicates which part of the IP address is used for the network ID and which part is used for the host ID. Since each octet consists of bits, the first three octets () represent the network ID, while the last octet is used for the host ID.
IPv4 Address Classes
IPv4 addresses are bits long.
For example, in , each group (octet) consists of bits, and the at the end of the IP address indicates that the first bits are used for network addressing, while the last three octets are used for host addressing.
This notation is also called the prefix length, and based on it, IPv4 addresses are divided into five different classes, as shown below:
Class | First Octet | First Octet Numberic Range | Prefix Length | Number of Networks | Addresses Per Network |
---|---|---|---|---|---|
A | |||||
B | |||||
C | |||||
D | N/A | N/A | N/A | ||
E | N/A | N/A | N/A |
Addresses in Class D are reserved for multicast and are different from unicast and broadcast addresses. Class E addresses are reserved for experimental use.
In each network, the first address is reserved as the network address, and the last address is the broadcast address. Therefore, the number of usable host addresses per network is reduced by two.
On Juniper network devices, the prefix length is written using slash notation, as shown in the table above. However, Cisco devices still use the older method of specifying the prefix length with a subnet mask.
For example, the subnet masks for different classes are:
- Class A addresses:
- Class B addresses:
- Class C addresses:
Private IP Address Ranges
The Internet Assigned Numbers Authority (IANA) defines the following as:
- to (Class A).
- to (Class B).
- to (Class B).
Loopback Address
The end of the Class A range is usually considered to be because the range is reserved for loopback addresses. The addresses from to are designated for the network stack on the local device.
IPv4 Header
Below are the Protocol Data Units (PDUs) created at each level of the OSI model:
- The upper layers of the OSI model prepare data for transmission across the network.
- A Segment consists of Data + Layer 4 (L4) header.
- A Packet consists of Data + L4 header + Layer 3 (L3) header.
- A Frame consists of Layer 2 (L2) trailer + Data + L4 header + L3 header + L2 header.
Let's understand the IPv4 header, which is responsible for generating a packet.
-
Version field:
- It is bits in length.
- Identifies version of IP used.
-
IHL field
- It is bits in length.
- Indicates length of IPV header.
-
DSCP field
- It is bits in length.
- This field is used for Quality of Service. (For example prioritising delay sensitive data).
-
ECN field
- It is bits in length.
- Provides end to end notification of network congestion without dropping packets.
-
Total length field
- It is bits in length.
- Indicates the total length of the packet.
- Max length of IPv4 packet is .
-
Identification field
- It is bits in length.
- If packet is fragmented due to being too large, this field is used to identify which packet the fragment belongs to.
- All fragements of the same packet will have same value in this field.
- Packets are fragemented if it is larger than MTU.
- MTU is usually bytes long.
- Fragments are reassembled by the receiving host.
-
Flags
- It is bits in length.
- Used to control and identify fragments.
- Bit is reserved and always .
- Bit is don't fragment bit, used to indicate if packet should be fragmented.
- Bit is more fragment bit which is set to if there are more fragment in packet or else set to if it is last packet in the fragment.
-
Fragment Offset
- It is bits in length.
- Used to indicate position of fragment within the original packet.
-
TTL
- It is bits in length.
- Router will drop a packet with a TTL of .
- Used to prevent infinte loops.
-
Protocol
- It is bits in length.
- Indicate the protocol of encapsulated L PDU.
- Value of is TCP.
- Value of is UDP.
- Value of is ICMP(Ping).
- Value of is OSPF(Dynamic Rounting Protocol).
-
Header Checksum
- It is bits in length.
- A calculated checksum used to check for erros in IPV header.
-
Source IP Address
- It is bits in length.
- It is IPv4 address of sender.
-
Destination IP Address
- It is bits in length.
- It is IPv4 address of receiver.
-
Options
- It is optional field which can have any size between to bits.
- If IHL field is greater than , it means options are present.
Summary
PC has an IP address of
- Network address of PC is .
- Maximum number of hosts in the network is .
- Network broadcast address is .
- First usable address of network is .
- Last usable address of network is .