IPv4 addressing
IPv4 address structure
An IPv4 address is a 32-bit hierarchical address that is made up of a network portion and a host portion. When determining the network portion vs. the host portion, you must look at the 32-bit stream.
- The bits within the network portion of the address must be identical for all devices that reside in the same network.
- The bits within the host portion of the address must be unique to identify a specific host within a network
If 2 hosts have the same bit-pattern in the specified network portion of the 32-bit stream, those 2 hosts will reside in the same network.
The IPv4 subnet mask is used to differentiate the network portion from the host portion of an IPv4 address. When an IPv4 address is assigned to a device, the subnet mask is used to determine the network address of the device. The network address represents all the devices on the same network.
The subnet mask is a consecutive sequence of 1 bits followed by a consecutive sequence of 0 bits. To identify the network and host portions of an IPv4 address, the subnet mask is compared to the IPv4 address bit for bit, from left to right. The subnet mask does not actually contain the network or host portion of an IPv4 address, it just tells the computer where to look for the part of the IPv4 address that is the network portion and which part is the host portion. The actual process used to identify the network portion and host portion is called ANDing:
A logical AND is a Boolean operation.
- 1 AND 1 = 1
- 0 AND 1 = 0
- 1 AND 0 = 0
- 0 AND 0 = 0
To identify the network address of an IPv4 host, the IPv4 address is logically ANDed, bit by bit, with the subnet mask. ANDing between the address and the subnet mask yields the network address.
The prefix length is the number of bits set to 1 in the subnet mask. It is written in “slash notation”, which is noted by a forward slash (/) followed by the number of bits set to 1. Therefore, count the number of bits in the subnet mask and prepend it with a slash.
A network address is also referred to as a prefix or network prefix. Therefore, the prefix length is the number of 1 bits in the subnet mask.
Within each network are 3 types of IP addresses:
Network address
Represents a specific network. The network address has all 0 bits in the host portion, as determined by the subnet mask. A device belongs to a certain network if it meets 3 criteria:
- It has the same subnet mask as the network address.
- It has the same network bits as the network address, as indicated by the subnet mask.
- It is located on the same broadcast domain as other hosts with the same network address.
Host addresses
Host addresses are addresses that can be assigned to a device such as a host computer, laptop, smart phone, web camera, printer, router, etc. The host portion of the address is the bits indicated by 0 bits in the subnet mask. Host addresses can have any combination of bits in the host portion except for all 0 bits (this would be a network address) or all 1 bits (this would be a broadcast address). All devices within the same network, must have the same subnet mask and the same network bits. Only the host bits will differ and must be unique.
Broadcast address
A broadcast address is an address that is used when it is required to reach all devices on the IPv4 network. As shown in the table, the network broadcast address has all 1 bits in the host portion, as determined by the subnet mask. In this example, the network address is 192.168.10.255/24. A broadcast address cannot be assigned to a device.
About unicast, multicast and broadcast addresses
ADDRESS TYPE | ADDRESS RANGE |
Unicast | 1.0.0.1 - 223.255.255.255 |
Multicast | 224.0.0.0 - 239.255.255.255 |
Broadcast | 255.255.255.255 (limited broadcast) |
Unicast addresses
Unicast transmission refers to one device sending a message to one other device in one-to-one communications. A unicast packet has a destination IP address that is a unicast address which goes to a single recipient. A source IP address can only be a unicast address, because the packet can only originate from a single source. This is regardless of whether the destination IP address is a unicast, broadcast or multicast.
Multicast addresses
Multicast transmission reduces traffic by allowing a host to send a single packet to a selected set of hosts that subscribe to a multicast group. A multicast packet is a packet with a destination IP address that is a multicast address. Hosts that receive particular multicast packets are called multicast clients. The multicast clients use services requested by a client program to subscribe to the multicast group. Each multicast group is represented by a single IPv4 multicast destination address. When an IPv4 host subscribes to a multicast group, the host processes packets addressed to this multicast address, and packets addressed to its uniquely allocated unicast address. Example: OSPF routing.
Broadcast addresses
Hay dos tipos de broadcast: limited y directed:
-
Limited broadcasts: to reach all hosts in the same network.
-
Directed broadcasts: a host in one network sends the message to all host in another network.
Es decir si yo tengo un host 192.168.1.10 y quiero mandar un mensaje desde ahi a todos los host de la 192.168.2.0/24, mando un mensaje a la 192.168.2.255. Si lo mando a 255.255.255.255, solo llega a los hosts en la 192.168.1.10 (mi propia red, de ahi que sea un broadcast limitado, y el otro dirigido -> lo dirijo a todos los host de otra red.).
OJO: para que un broadcast desde una red pueda llegar a otra red, tiene que estar habilitado el comando ip directed-broadcasts (por razones obvias, desde IOS 12.0 está deshabilitado por defecto).
A directed broadcast is sent to all hosts on a specific network. For example, a host on the 172.16.4.0/24 network sends a packet to 10.74.255.255. A limited broadcast is sent to 255.255.255.255. By default, routers do not forward broadcasts.
Limited broadcasts
A limited broadcast packet has a destination IP address with all ones (1s) in the host portion, or 32 one (1) bits (255.255.255.255). A limited broadcast packet must be processed by all devices in the same broadcast domain. A broadcast domain identifies all hosts on the same network segment. Because routers separate broadcast domains, subdividing networks can improve network performance by eliminating excessive broadcast traffic.
Directed broadcasts
There is a broadcast IPv4 address for each network. This address allows communication to all the hosts in that network. To send data to all the hosts in a network, a host can send a single packet that is addressed to the broadcast address of that network. A device that is not directly connected to the destination network forwards an IP directed broadcast in the same way it would forward unicast IP packets destined to a host on that network. When a directed broadcast packet reaches a router that is directly connected to the destination network, that packet is broadcast on the destination network.
Types of IPv4 addresses
In 1981, IPv4 addresses were assigned using classful addressing. Customers were allocated a network address based on one of three classes, A, B or C. The RFC divided the unicast range into specific classes as follows:
CLASS | RANGE |
A | 0.0.0.0/8 - 127.0.0.0/8 |
B | 128.0.0.0/16 - 191.255.0.0/16 |
C | 192.0.0.0/24 - 223.255.255.0/24 |
D | 224.0.0.0/4 - 239.255.255.254/4 |
E (reserved for future use/experimental) | 240.0.0.0/4 - 255.255.255.254/4 |
In the mid-1990s, with the introduction of the World Wide Web (WWW), classful addressing was deprecated to more efficiently allocate the limited IPv4 address space. Classful address allocation was replaced with classless addressing, which is used today. Classless addressing ignores the rules of classes (A, B, C). Public IPv4 network addresses (network addresses and subnet masks) are allocated based on the number of addresses that can be justified.
Public IPv4 addresses are addresses which are globally routed between internet service provider (ISP) routers. However, not all available IPv4 addresses can be used on the internet. There are blocks of addresses called private addresses that are used by most organizations to assign IPv4 addresses to internal hosts. In the mid-1990s, with the introduction of the World Wide Web (WWW), private IPv4 addresses were introduced because of the depletion of IPv4 address space. Private IPv4 addresses are not unique and can be used internally within any network.
PREFIX AND PREFIX LENGTH | RFC 1918 PRIVATE ADDRESS RANGE |
10.0.0.0/8 | 10.0.0.0 - 10.255.255.255 |
172.16.0.0/12 | 172.16.0.0 - 172.31.255.255 |
192.168.0.0/16 | 192.168.0.0 - 192.168.255.255 |
Packets with a private address must be filtered (discarded) or translated to a public address before forwarding the packet to an ISP (NAT). Organizations that have resources available to the internet, such as a web server, will also have devices that have public IPv4 addresses. This part of the network is known as the DMZ (demilitarized zone).
SPECIAL USE IPv4 ADDRESSES | RANGE |
Loopback | 127.0.0.0/8 -------> 127.0.0.1 - 127.255.255.254 |
Link-local addresses | 169.254.0.0/16 ---> 169.254.0.1 - 169.254.255.254 |
TEST-NET-1 (para documentación, labs, ejemplos, practicas, etc.) | 192.0.2.0/24 ------> 192.0.2.0 - 192.0.2.255 |
TEST-NET-2 (para documentación, labs, ejemplos, practicas, etc.) | 198.51.100.0/24 --> 198.51.100.0 - 198.51.100.255 |
TEST-NET-3 (para documentación, labs, ejemplos, practicas, etc.) | 203.0.113.0/24 ---> 203.0.113.0 - 203.0.113.255 |
Public IPv4 addresses are addresses which are globally routed over the internet. Public IPv4 addresses must be unique. Both IPv4 and IPv6 addresses are managed by the Internet Assigned Numbers Authority (IANA). The IANA manages and allocates blocks of IP addresses to the Regional Internet Registries (RIRs). RIRs are responsible for allocating IP addresses to ISPs who provide IPv4 address blocks to organizations and smaller ISPs. Organizations can also get their addresses directly from an RIR (subject to the policies of that RIR).
- AfriNIC (African Network Information Centre) -- Africa region
- APNIC (Asia Pacific Network Information Centre) -- Asia/Pacific Region
- ARIN (American Registry for Internet Numbers) -- North America Region
- LACNIC (Regional Latin-American and Caribbean IP Address Registry) -- Latin America and some Caribbean Islands
- RIPE NCC (Réseaux IP Européens Network Coordination Centre) -- Europe, Middle East, and Central Asia