Understanding IPv4 addressing
The most important thing IPv4 gives you is the IPv4 address. It’s the existence of IPv4 addresses that enables information to be routed from point A to point B over a network. An IPv4 address is a 32-bit logical address that has two components: a network address and a node address. Typically, IPv4 addresses are divided into four 8-bit values called octets and are written as four separate decimal values delimited by a period (referred to as a dot). The binary values are converted to decimal equivalents by adding the numbers represented by the bit positions that are set to 1. The general way to write this value is in the form w.x.y.z, where each letter represents one of the four octets.
IPv4 addresses can be used in three ways:
- Unicast. Unicast IPv4 addresses are assigned to individual network interfaces that are attached to an IPv4 network and are used in one-to-one communications.
- Multicast. Multicast IPv4 addresses are addresses for which one or multiple IPv4 nodes can listen on the same or different network segments and are used in one-to-many communications.
- Broadcast. Broadcast IPv4 addresses are designed to be used by every IPv4 node on a particular network segment and are used in one-to-everyone communications.
Each of these IPv4 addressing techniques is discussed in the sections that follow.
Unicast IPv4 addresses
Unicast IPv4 addresses are the ones you’ll work with the most. These are the IPv4 addresses that are assigned to individual network interfaces. In fact, each network interface that uses TCP/IPv4 must have a unique unicast IPv4 address. A unicast IPv4 address consists of two components:
- A network ID. The network ID or address identifies a specific logical network and must be unique within its boundaries. Typically, IPv4 routers set the boundaries for a logical network and this boundary is the same as the physical network defined by the routers. All nodes that are on the same logical network must share the same network ID. If they don’t, routing or delivery problems occur.
- A host ID. The host ID or address identifies a specific node on a network, such as a router interface or server. As with a network ID, it must be unique within a particular network segment.
Address classes are used to create subdivisions of the IPv4 address space. With unicast IPv4 addresses, the classes A, B, and C can be applied. Each describes a different way of dividing a subset of the 32-bit IPv4 address space into network addresses and host addresses.
Class A networks
Class A networks are designed for when you need a large number of hosts but only a few network segments, and they have addresses that begin with a number between 1 and 127 for the first octet. As shown in Figure 2-3, the first octet (the first 8 bits of the address) defines the network ID, and the last three octets (the last 24 bits of the address) define the host ID. As you’ll learn shortly, the Class A address 127 has a special meaning and isn’t available for your use. This means that there are 126 possible Class A networks and each network can have 16,277,214 nodes. For example, a Class A network with the network address 100 contains all IPv4 addresses from 126.96.36.199 to 188.8.131.52.
Figure 2-3 IPv4 addressing on Class A networks.
Class B networks
Class B networks are designed for when you need a moderate number of networks and hosts, and they have addresses that begin with a number between 128 and 191 for the first octet. As shown in Figure 2-4, the first two octets (the first 16 bits of the address) define the network ID, and the last two octets (the last 16 bits of the address) define the host ID. This means that there are 16,384 Class B networks and each network can have 65,534 nodes.
Figure 2-4 IPv4 addressing on Class B networks.
Class C networks
Class C networks are designed for when you need a large number of networks and relatively few hosts, and they have addresses that begin with a number between 192 and 223 for the first octet. As shown in Figure 2-5, the first three octets (the first 24 bits of the address) define the network ID and the last octet (the last 8 bits of the address) defines the host ID. This means that there are 2,097,152 Class C networks and each network can have 254 nodes.
Figure 2-5 IPv4 addressing on Class C networks.
Loopback, public, and private addresses
When using any of the IPv4 address classifications, you need to follow certain rules. The network ID can’t begin with 127 as the first octet. All IPv4 addresses that begin with 127 are reserved as loopback addresses. Any packets sent to an IPv4 address beginning with 127 are handled as if they’ve already been routed and have reached their destination, which is the local network interface. This means that any packets addressed to an IPv4 address of 127.0.0.0 to 127.255.255.255 are addressed to and received by the local network interface.
In addition, some addresses in the ranges are defined as public and others are defined as private. Public IPv4 addresses are assigned by Internet service providers (ISPs). ISPs obtain allocations of IPv4 addresses from a local Internet registry (LIR), from a national Internet registry (NIR), or from their appropriate regional Internet registry (RIR). Private addresses are addresses reserved for organizations to use on internal networks. Because they are nonroutable, which means they are not reachable on the Internet, they do not affect the public Internet and do not have to be assigned by an addressing authority.
The private IPv4 addresses defined are as follows:
- Class A private IPv4 addresses. 10.0.0.0 through 10.255.255.255
- Class B private IPv4 addresses. 172.16.0.0 through 172.31.255.255
- Class C private IPv4 addresses. 192.168.0.0 through 192.168.255.255
Because you shouldn’t connect hosts on an organization’s private network directly to the Internet, you should indirectly connect them using the Network Address Translation (NAT) protocol or a gateway program such as a proxy. When NAT is configured on the organization’s network, a device, such as a router, is responsible for translating private addresses to public addresses, allowing the nodes on the internal network to communicate with the nodes on the public Internet. When proxies are configured on the organization’s network, the proxy acts as the go-between. It receives requests from nodes on the internal network and sends the requests to the public Internet. When the response is returned, the proxy sends the response to the node that made the original request. In both cases the device providing NAT or proxy services has a private IP address on its internal network interface and a public address on its Internet interface.
Multicast IPv4 addresses
Multicast IPv4 addresses are used only as destination IPv4 addresses and allow multiple nodes to listen for packets sent by a single originating node. In this way, a single packet can be delivered to and received by many hosts. Here’s how it works: a sending node addresses a packet using a multicast IPv4 address. If the packet is addressed to the sending node’s network, nodes on the network that are listening for multicast traffic receive and process the packet. If the packet is addressed to another network, a router on the sending node’s network forwards the packet as it would any other packet. When it’s received on the destination network, any nodes on the network that are listening for multicast traffic receive and process the packet.
The nodes listening for multicast packets on a particular IPv4 address are referred to as the host group. Members of the host group can be located anywhere—as long as the organization’s routers know where members of the host group are located so that the routers can forward packets as appropriate.
One address class is reserved for multicast: Class D. Class D addresses begin with a number between 224 and 239 for the first octet.
Multicast IPv4 addresses in the range of 184.108.40.206 through 220.127.116.11 are reserved for local subnet traffic. For example, the address 18.104.22.168 is an all-hosts multicast address and is designed for multicasting to all hosts on a subnet. The address 22.214.171.124 is an all-routers multicast address and is designed for multicasting to all routers on a subnet. Other addresses in this range are used as specified by the Internet Assigned Numbers Authority (IANA), which is a function of the Internet Corporation for Assigned Names and Numbers (ICANN). For details, see the IANA website at http://www.iana.org/assignments/multicast-addresses/multicast-addresses.xml.
Broadcast IPv4 addresses
Broadcast IPv4 addresses are used only as destination IPv4 addresses, and they allow a single node to direct packets to every node on the local network segment. When a sending node addresses a packet using a broadcast IPv4 address, every node on that network segment receives and processes the packet.
To understand how broadcasts are used, you must understand the difference between classful networks and nonclassful networks. A classful network is a network that follows the class rules as defined, meaning a Class A, B, or C network is configured with network addresses and host addresses as described previously. A nonclassful network is a network that doesn’t strictly follow the class rules. Nonclassful networks might have subnets that don’t follow the normal rules for network and host IDs. You’ll learn more about subnets later in this chapter in the section entitled “Using subnets and subnet masks.”
All nodes listen for and process broadcasts. Because IPv4 routers usually do not forward broadcast packets, broadcasts are generally limited by router boundaries. The broadcast address is obtained by setting all the host bits in the IPv4 address to 1 as appropriate for the broadcast type. Three types of broadcasts are used:
- Network broadcasts. Network broadcasts are used to send packets to all nodes on a classful network. For network broadcasts, the host ID bits are set to 1. For a nonclassful network, there is no network broadcast address, only a subnet broadcast address.
- Subnet broadcasts. Subnet broadcasts are used to send packets to all nodes on a nonclassful network. For subnet broadcasts, the host ID bits are set to 1. For a classful network, there is no subnet broadcast address, only a network broadcast address.
- Limited broadcasts. Limited broadcasts are used to send packets to all nodes when the network ID is unknown. For a limited broadcast, all network ID and host ID bits are set to 1.