IPv4 Addressing

Over the years, we’ve all gotten comfortable with good old IP version 4. IPv4 is based on 32-bit host addresses. Addresses are first broken down into the classes A, B, and C, with D kept aside for multicast channels. The address class determines how many bits in the IP address apply to the network number and how many apply to the host number. All subnets made of these networks are of equal size and so on. Each new thing you learn about working with IP v4 lets you add more levels of complexity to your networking setups.

IPv4 Math Review

We’re not going to dwell on IP basics too much here. Most introductory network and Linux books cover that kind of information. In case it’s been a while since you really needed to deal with it, we’ll start with a quick overview of the easy stuff, and then we’ll dive into the math.

IP addresses are set in two different formats:

  • The computer readable (binary) version is xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx, where every x (bit) is either a 0 or a 1. Every address is composed of four octets or four 8-bit binary numbers.

  • The human readable (decimal) version is xxx.xxx.xxx.xxx, where xxx can range from 000 through 255. This is the decimal equivalent of each 8-bit binary number.

While the average user setting up his own box only needs to know the decimal IP values, sometimes it’s useful or even required to understand how to go between decimal and binary when planning and setting up complex networks. At first, let’s focus on reading just one of the 8-bit (byte) portions of a binary IP address. Each of the x’s has a specific decimal value depending on its binary value (1 or 0) and its placement within the octet. The value is always 0 decimal if the x is a 0-bit. However, if the x bit has a value of 1, it is worth its location decimal value.

The eight bits in each byte are numbered 0 through 7. The x farthest to the right is at position 0, and each bit has an individual value of two to the power of its location. So, from right to left the positions are worth:

2^0 = 1

2^1 = 2

2^2 = 4

2^3 = 8

2^4 = 16

2^5 = 32

2^6 = 64

2^7 = 128

Figure 4.1 maps these values to their actual position in the byte.

Figure 4.1. Each bit in a single IP byte corresponds to a particular power of 2, counted from right to left starting from position 0.


So, let’s take a look at an example.We’ll return to the fact that an IP address has four bytes, not just one. So say that we have the binary IP address 01001101.00011101.10111001.10110110.What is this address in decimal? Each byte is calculated individually, and it really doesn’t matter where we start. We’ll start from the left, since it feels more natural for some. The first byte, 01001101, breaks down to the following, which is shown in two different ways:

0x2^7 + 1x2^6 + 0x2^5 + 0x2^4 + 1x2^3 + 1x2^2 + 0x2^1 + 1x2^0 = 77

0x128 + 1x64 + 0x32 + 0x16 + 1x8 + 1x4 + 0x2 + 1x1 = 77

The second byte, 00011101, breaks down into:

0x128 + 0x64 + 0x32 + 1x16 + 1x8 + 1x4 + 0x2 + 1x1 = 29

The third byte, 10111001:

1x128 + 0x64 + 1x32 + 1x16 + 1x8 + 0x4 + 0x2 + 1x1 = 185

And, finally, the fourth byte, 10110110:

1x128 + 0x64 + 1x32 + 1x16 + 0x8 + 1x4 + 1x2 + 0x1 = 182

So the decimal version of this IP address is 77.29.185.182. Now that we’ve got the address itself, we want to know things like which are the network bits and which are the host bits. To do that, we have to look at the standard IP address class table, as shown in Table 4.1.

Table 4.1. IP Address Class Ranges, Without Special Addresses Removed and with Network Portions in Bold and Host Portions in Non-Bold
Class Start   End  
  BINARY DECIMAL BINARY DECIMAL
A 00000001.00000000. 1.0.0.0 01111111.00000000. 127.0.0.0
  00000000.00000000   00000000.00000000  
B 10000000.00000000. 128.0.0.0 10111111.11111111. 191.255.0.0
  00000000.00000000   00000000.00000000  
C 11000000.00000000. 192.0.0.0 11011111.11111111. 223.255.255.0
  00000000.00000000   11111111.00000000  
D 11100000.00000000. 224.0.0.0 11101111.11111111. 239.255.255.255
  00000000.00000000   11111111.11111111  

This isn’t the whole story, though. Not all of these addresses are actually available. Let’s weed out the network addresses first. For example, the entire network 127.0.0.0 is only used to loop back to the same machine you’re working in.You can’t use it to reach another machine. No one is assigned this network number. The very first network 0.0.0.0 isn’t even listed. It’s used to point to the default route.

We also can’t use the very first and last address in each class. All addresses where all of the variable bits are either 0s or 1s are reserved for special use. This means that the following addresses also are unavailable:

  • Class A. These have already been mentioned, but they are included here for easy reference. 0.0.0.0 and 127.0.0.0 are unavailable.

  • Class B. 128.0.0.0 and 191.255.0.0 are unavailable.

  • Class C. 192.0.0.0 and 223.255.255.0 are unavailable.

  • Class D. 224.0.0.0 and 239.255.255.255 are unavailable.You might notice that the multicast class has no host addresses. None are needed. Multicast entirely consists of channels that machines with their own addresses join and leave.

Another set of network addresses that must be removed is the combined private IP networks. These addresses are specifically set aside for internal use and never point to a machine out on the Internet. Table 4.2 outlines these address ranges. Note that the table shows entire networks that have been reserved.

Table 4.2. Reserved Private Networks, for Use in Intranets and Other Isolated Networks
Class Start End
A 10.0.0.0 10.0.0.0
B 172.16.0.0 172.31.0.0
C 192.168.0.0 192.168.255.0
D 239.0.0.0 239.255.255.255

It’s not just network addresses that get removed from the available-for-use pool. There are host addresses that cannot be used as well. While the host portions of the IP addresses were able to be left blank in the network discussions to isolate the network addresses, it’s a bit trickier to do this but use real network numbers for a host discussion. So we will use x’s for the network portion so we can refer only to the hosts, because what we’re saying about the hosts applies to all networks. Each of the unavailable host addresses has a special purpose:

  • The host address x.x.x.0 is reserved to refer to the network itself.

  • The host address x.x.x.255 is the broadcast address or the “host”TCP/IP sends data to when it wants to send something to all network members.

  • Believe it or not, that’s it. Sort of. When we get into subnetting in the section “Applying IP v4 Addressing Across Subnets” in just a moment, we begin losing even more host addresses.

Let’s not forget the issue of the network mask, or netmask, either. When you’re dealing with one piece, intact networks, the netmask does not change. It is always as you see in Table 4.3.

Table 4.3. Standard Netmasks for Each IP Address Class
Class Netmask
A 255.0.0.0
B 255.255.0.0
C 255.255.255.0
D 255.255.255.255

As you might notice, the netmask bits are set to all 1s in each byte that is used to determine the network number for the class. The 0 positions represent the positions that are available for hosts and subnets. As usual, you can see that multicast has no hosts, and you can’t subnet a single IP address.

Applying IPv4 Addressing Across Subnets

Sometimes one network is not enough.You might have a full class C address, but there is an administrative, security, geographic, or other reason that you need to break your network into a set of subnets. Doing so causes more work. For one thing, you’ll have to actually set up routing because you now have to tell each subnet how to send data to the other subnets and the outside world.You also have to calculate all of the IP bits and pieces, such as the new netmasks, new network addresses, new broadcast address, and so on.

You break an IP network into subnets by turning some of the host bits into network bits. No, this isn’t a magic trick.You do this with the assistance of also changing the netmask.A netmask that is not standard for the address class tells TCP/IP that it is dealing with a subnetted network. So, let’s take a look at how all of this is accomplished.

In the worlds of class A and B networking, subnetting is relatively simple. You can take a class A network such as 120.0.0.0—which has a netmask of 255.0.0.0—and divide it into subnets simply by using addresses 120.1.0.0 through 120.254.0.0 as network addresses and changing the netmask to 255.255.0.0. Look familiar? You’ve just turned your class A network into 254 class B network addresses or subnets. The same works for class B networks.Take 142.182.0.0, which falls in the class B range and so has the netmask 255.255.0.0. Give it a netmask of 255.255.255.0 and use 142.186.1.0 through 142.185.254.0 as network addresses, and you’ve just turned your class B network into 254 class C network addresses or subnets. However, how many of us really get our own class A or B to play with these days? Fat chance.

Things get more interesting when you want to subnet your class C network. You can’t just break it down into class D networks; those are individual IP addresses. However, we can do it by changing the netmask and then breaking up the available hosts so each go into a different network.You then usurp some of the host addresses for network numbers and other reserved values.

IP v4 has certain limits on the subnets you can create for a class C address. Each subnet must be the same size, and the number of nets you divide your network into is determined by binary math. Because the first three bytes of the netmask for a class C address are fixed as 255.255.255., let’s just look at the last byte. As usual, it is eight bits where x is either 0 or 1.Your first option for making subnets is to divide your network into two.Why? Because the first x can either be 0 or 1, you have only two options. So, suddenly your network bits (represented by n) are one bit larger, your host bits (represented by h) are one bit smaller, and your network bytes look like nnnnnnnn.nnnnnnnn.nnnnnnnn.nhhhhhhh.

The second chance for dividing your network is into four pieces because those first two x’s can be 00, 01, 10, or 11. So now your network bytes are nnnnnnnn.nnnnnnnn.nnnnnnnn.nnhhhhhh. Once again,TCP/IP keeps track of this through your netmask. The last byte of your netmask is equal to the position values of the n’s within it. So the netmask for a two-subnet network is 255.255.255.128. It follows that the netmask for four subnets is 255.255.255.192. Table 4.4 outlines the possible IP v4 subnets for a class C address and their pertinent values.

Table 4.4. Pertinent Facts About the Possible IP v4 class C Subnets, Where n Stands for Network Bit, h Stands for Host Bit, and x Stands for Network Byte
Number Network Bits Binary Netmask Decimal Netmask
2 nhhhhhhh .10000000 255.255.255.128
4 nnhhhhhh .11000000 255.255.255.192
8 nnnhhhhh .11100000 255.255.255.224
16 nnnnhhhh .11110000 255.255.255.240
32 nnnnnhhh .11111000 255.255.255.248
64 nnnnnnhh .11111100 255.255.255.252
128 nnnnnnnh .11111110 255.255.255.254

Now, some of these subnet sizes are pretty unrealistic. We’ll illustrate why by getting into the internals of the subnetwork addresses, host address ranges, and more. Let’s take the two-subnet case to start with.You can use the remaining host bits to help you determine the range of host numbers that goes toward each subnetwork. In the case of the two-subnet breakdown, the h’s (host bits) in nhhhhhhh add up to 127. So subnet 1 is from x.x.x.0 through x.x.x.127, and subnet 2 is from x.x.x.128 through x.x.x.255.

It’s not that simple though. The first and last host bits are always reserved, even in a subnetted network, so you really only get x.x.x.1 through x.x.x.127 and x.x.x.128 through x.x.x.254 for your subnets. Now we have to pull out the network addresses. For subnet 1 this is x.x.x.1 and for subnet 2 this is x.x.x.128—for the entire network it’s x.x.x.0, and that’s all the rest of the Internet sees. So your available host IP addresses are now x.x.x.2 through x.x.x.127 and x.x.x.129 through x.x.x.254. We now need the subnet broadcast addresses, as opposed to the x.x.x.255, which broadcasts to the entire network. Those would be the last address in each subnet, x.x.x.127 and x.x.x.254. Now our hosts can be x.x.x.2 through x.x.x.126 and x.x.x.129 through x.x.x.253. As you can see, for the convenience of turning our class C network into two subnetworks, we’ve given up the use of four host IP addresses.

Things of course get more complex as we create four subnets. The host bits in nnhhhhhh add up to 63, so we end up with the following four subnet ranges: x.x.x.0 through x.x.x.63, x.x.x.64 through x.x.x.127, x.x.x.128 through x.x.x.191, and x.x.x.192 through x.x.x.255. Once again, we lose x.x.x.0 and x.x.x.255 to the overall network address and broadcast address.We also lose x.x.x.1, x.x.x.64, x.x.x.128, and x.x.x.192 to network addresses; x.x.x.63, x.x.x.127, x.x.x.191, and x.x.x.254 to broadcast addresses. Table 4.5 lays out the address ranges for each subnetting possibility and the addresses lost as well.

Table 4.5. Host and Special Addresses Among IP v4 Class C Subnets Two Through Thirty-Two, Assuming That x.x.x.0 and x.x.x.255 Are Always Lost for Network and Broadcast Addresses
Number of Networks Network Numbers Broadcast Addresses Host Addresses
2 x.x.x.1, x.x.x.127, x.x.x.2 – x.x.x.126,
  x.x.x.128 x.x.x.254 x.x.x.129 – x.x.x.253
4 x.x.x.1, x.x.x.63, x.x.x.2 – x.x.x.62, x.x.x.65
  x.x.x.64, x.x.x.127, – x.x.x.126, x.x.x.129 –
  x.x.x.128, x.x.x.191, x.x.x.190, x.x.x.193 –
  x.x.x.192 x.x.x.254 x.x.x.253
8 x.x.x.1, x.x.x.31, x.x.x.2 – x.x.x.30, x.x.x.33
  x.x.x.32, x.x.x.63, – x.x.x.62, x.x.x.56 –
  x.x.x.64, x.x.x.95, x.x.x.94, x.x.x.97 –
  x.x.x.96, x.x.x.127, x.x.x.126, x.x.x.129 –
  x.x.x.128, x.x.x.159, x.x.x.158, x.x.x.161 –
  x.x.x.160, x.x.x.191, x.x.x.190, x.x.x.193 –
  x.x.x.192, x.x.x.223, x.x.x.222, x.x.x.225 –
  x.x.x.224 x.x.x.254 x.x.x.253
16 x.x.x.1, x.x.x.15, x.x.x.2 – x.x.x.14, x.x.x.17
  x.x.x.16, x.x.x.31, – x.x.x.30, x.x.x.33 –
  x.x.x.32, x.x.x.47, x.x.x.46, x.x.x.49 –
  x.x.x.48, x.x.x.64, x.x.x.63, x.x.x.65 –
  x.x.x.64, x.x.x.79, x.x.x.78, x.x.x.81 –
  x.x.x.80, x.x.x.95, x.x.x.94, x.x.x.97 –
  x.x.x.96, x.x.x.111, x.x.x.110, x.x.x.113 –
  x.x.x.112, x.x.x.127, x.x.x.126, x.x.x.129 –
  x.x.x.128, x.x.x.143, x.x.x.142, x.x.x.145 –
  x.x.x.144, x.x.x.159, x.x.x.158, x.x.x.161 –
  x.x.x.160, x.x.x.175, x.x.x.174, x.x.x.177 –
  x.x.x.176, x.x.x.191, x.x.x.190, x.x.x.193 –
  x.x.x.192, x.x.x.207, x.x.x.206, x.x.x.209 –
  x.x.x.208, x.x.x.223, x.x.x.222, x.x.x.225 –
  x.x.x.224, x.x.x.239, x.x.x.238, x.x.x.241 –
  x.x.x.240 x.x.x.254 x.x.x.253
32 x.x.x.1, x.x.x.7, x.x.x.2 – x.x.x.6,
  x.x.x.8, x.x.x.15, x.x.x.9 - x.x.x.14,
  x.x.x.16, x.x.x.23, x.x.x.17 – x.x.x.22,
  x.x.x.24, x.x.x.31, x.x.x.25 - x.x.x.30,
  x.x.x.32, x.x.x.39, x.x.x.33 – x.x.x.38,
  x.x.x.40, x.x.x.47, x.x.x.41 - x.x.x.46,
  x.x.x.48, x.x.x.55, x.x.x.49 – x.x.x.54,
  x.x.x.56, x.x.x.64, x.x.x.57 - x.x.x.63,
  x.x.x.64, x.x.x.71, x.x.x.65 – x.x.x.70,
  x.x.x.72, x.x.x.79, x.x.x.73 - x.x.x.78,
  x.x.x.80, x.x.x.87, x.x.x.81 – x.x.x.88,
  x.x.x.88, x.x.x.95, x.x.x.89 - x.x.x.94,
  x.x.x.96, x.x.x.103, x.x.x.97 – x.x.x.102,
  x.x.x.104, x.x.x.111, x.x.x.105 - x.x.x.110,
  x.x.x.112, x.x.x.119, x.x.x.113 - x.x.x.118,
  x.x.x.120, x.x.x.127, x.x.x.121 - x.x.x.126,
  x.x.x.128, x.x.x.135, x.x.x.129 – x.x.x.134,
  x.x.x.136, x.x.x.143, x.x.x.137 - x.x.x.142,
  x.x.x.144, x.x.x.151, x.x.x.145 – x.x.x.150,
  x.x.x.152, x.x.x.159, x.x.x.153 - x.x.x.158,
  x.x.x.160, x.x.x.167, x.x.x.161 – x.x.x.166,
  x.x.x.168, x.x.x.175, x.x.x.169 - x.x.x.174,
  x.x.x.176, x.x.x.183, x.x.x.177 – x.x.x.182,
  x.x.x.184, x.x.x.191, x.x.x.185 - x.x.x.190,
  x.x.x.192, x.x.x.199, x.x.x.193 – x.x.x.198,
  x.x.x.200, x.x.x.207, x.x.x.201 - x.x.x.206,
  x.x.x.208, x.x.x.215, x.x.x.209 – x.x.x.214,
  x.x.x.216, x.x.x.223, x.x.x.217 - x.x.x.222,
  x.x.x.224, x.x.x.231, x.x.x.225 – x.x.x.230,
  x.x.x.232, x.x.x.239, x.x.x.233 - x.x.x.238,
  x.x.x.240, x.x.x.247, x.x.x.241 – x.x.x.246,
  x.x.x.248 x.x.x.254 x.x.x.249 – x.x.x.253

Perhaps after taking time to look over this table you might see why we stopped at breaking up addressing space at thirty-two subnets. There are only five host addresses available for each subnet when we reach this point, so breaking it up further would just bring us down to even smaller networks with less and less useful numbers of hosts.

IPv4 Routing Issues

As we all know, when you have a large network, address space is paramount. Not only do you have to break your subnets into identical pieces with IP v4, but even worse, you cannot utilize the first and last subnets. Therefore, even though a two-part subnet was included in Table 4.5, you could not even use these subnets in IP v4. So your four-part subnet is really two. Your eight is really six. The sixteen is fourteen, and the thirty-two is thirty. In this case, you actually give up less bulk address space by creating more subnets; however, you lose so many host IP addresses to new network and broadcast subnet addresses that it’s not a useful trick.

The other thing to keep in mind is the information that an IP v4 router carries. All the external router knows is the network address and the netmask for that network. When the data reaches your internal routers, they then can send information appropriately to the correct subnet.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset