Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Cisco Press CCNA ICND 2004 - Cisco Press.pdf
Скачиваний:
120
Добавлен:
24.05.2014
Размер:
13.19 Mб
Скачать

116 Chapter 4: IP Addressing and Subnetting

Step 5 Declare the number of subnets, which is 2number-of-subnet-bits – 2.

Step 6 Declare the number of hosts per subnet, which is 2number-of-host-bits – 2.

What Is the Subnet Number, and What Are the IP Addresses in the Subnet?

One of the most common situations you face is after you know an IP address and subnet mask and you must answer questions about them. The question might be straightforward, like “What is the subnet number?”, or it might be more subtle, like “Which of the following IP addresses are in the same subnet as the stated address?”. In either case, if you can dissect an IP address as described in this chapter, you can answer any variation on this type of question.

In the next several sections, you will learn how to derive the subnet number and the subnet broadcast address. After deriving these two values, you can easily find the range of valid IP addresses in the subnet.

Finding the Subnet Number

Earlier, you learned that computers perform a Boolean AND of the address and mask to find the subnet number. Tables 4-10 through 4-14 show the Boolean AND process for the five examples used in the preceding section.

Table 4-10 Boolean AND Calculation for the Subnet with Address 8.1.4.5, Mask 255.255.0.0

Address

8.1.4.5

0000 1000 0000 0001 0000 0100 0000 0101

 

 

 

Mask

255.255.0.0

1111 1111 1111 1111 0000 0000 0000 0000

 

 

 

AND Result

8.1.0.0

0000 1000 0000 0001 0000 0000 0000 0000

 

 

 

Table 4-11 Boolean AND Calculation for the Subnet with Address 130.4.102.1, Mask 255.255.255.0

Address

130.4.102.1

1000 0010 0000 0100 0110 0110 0000 0001

 

 

 

Mask

255.255.255.0

1111 1111 1111 1111 1111 1111 0000 0000

 

 

 

AND Result

130.4.102.0

1000 0010 0000 0100 0110 0110 0000 0000

 

 

 

Table 4-12 Boolean AND Calculation for the Subnet with Address 199.1.1.100, Mask 255.255.255.0

Address

199.1.1.100

1100 0111 0000 0001 0000 0001 0110 0100

 

 

 

Mask

255.255.255.0

1111 1111 1111 1111 1111 1111 0000 0000

 

 

 

AND Result

199.1.1.0

1100 0111 0000 0001 0000 0001 0000 0000

 

 

 

Analyzing and Interpreting IP Addresses and Subnets 117

Table 4-13 Boolean AND Calculation for the Subnet with Address 130.4.102.1, Mask 255.255.252.0

Address

130.4.102.1

1000 0010 0000 0100 0110 0110 0000 0001

 

 

 

Mask

255.255.252.0

1111 1111 1111 1111 1111 1100 0000 0000

 

 

 

AND Result

130.4.100.0

1000 0010 0000 0100 0110 0100 0000 0000

 

 

 

Table 4-14 Boolean AND Calculation for the Subnet with Address 199.1.1.100, Mask 255.255.255.224

Address

199.1.1.100

1100 0111 0000 0001 0000 0001 0110 0100

 

 

 

Mask

255.255.255.224

1111 1111 1111 1111 1111 1111 1110 0000

 

 

 

AND Result

199.1.1.96

1100 0111 0000 0001 0000 0001 0110 0000

 

 

 

Although these tables show the answers, they do not show the process. The steps taken to complete the tables are as follows:

Step 1 You start with the decimal address and mask stated in the question.

Step 2 You convert the two numbers to binary, as shown in all five examples.

Step 3 Each bit is ANDed with the bit in the same position in the other number (in other words, a bitwise Boolean AND), giving the result of the Boolean AND.

Step 4 You convert the Boolean AND result back to decimal.

The last step in this process, converting the binary number back to decimal, is the step that causes most of the problems for people new to subnetting. In some cases, the conversion is simple. For instance, in the first example, the subnet mask is 255.255.0.0. Because the mask has only 255s, or 0s in decimal, the boundary between the subnet and host fields is on a byte boundary as well—between the second and third bytes in this case. So the conversion from binary back to decimal for the result of the Boolean AND—0000 1000 0000 0001 0000

0000 0000 0000—typically does not pose a problem.

The confusion typically arises when the boundary between the subnet and host part of the address is in the middle of a byte, which occurs when the subnet mask has a value besides 0 or 255 decimal. For example, with 130.4.102.1, mask 255.255.252.0, the first 6 bits of the third octet comprise the subnet field, and the last 2 bits of the third octet, plus the entire fourth octet, comprise the host field. The problem that some people experience is that they try to convert the 6-bit subnet part from binary to decimal and the 10-bit host part to decimal. However, when converting binary to decimal, to find the dotted decimal IP address you always convert the entire octet—even if part of the octet is in the subnet part of the address and part is in the host part of the address.

118 Chapter 4: IP Addressing and Subnetting

So, in this example, the subnet number (130.4.100.0) in binary is 1000 0010 0000 0100 0110 0100 0000 0000. The entire third octet is shown in bold, which converts to 100 in decimal. When you convert the whole number, each set of 8 bits is converted to decimal, giving you 130.4.100.0.

Finding the Subnet Broadcast Address

The subnet broadcast address, sometimes called the directed broadcast address, can be used to send a packet to every device in a single subnet. However, few tools and protocols use the subnet broadcast address anymore. However, by calculating the subnet broadcast address, you can easily calculate the largest valid IP address in the subnet, which is an important part of answering subnetting questions.

There is a binary math operation to calculate the subnet broadcast address. However, there is a much easier process, especially if you already have the subnet number in binary:

Change all the host bit values in the subnet number to binary 1s.

You can examine the simple math behind calculating the subnet broadcast address in Tables 4-15 through 4-19. The host parts of the addresses, masks, subnet numbers, and broadcast addresses are in bold.

Table 4-15 Calculating the Broadcast Address: Address 8.1.4.5, Mask 255.255.0.0

Address

8.1.4.5

0000 1000 0000 0001 0000 0100 0000 0101

 

 

 

Mask

255.255.0.0

1111 1111 1111 1111 0000 0000 0000 0000

 

 

 

AND Result

8.1.0.0

0000 1000 0000 0001 0000 0000 0000 0000

 

 

 

Broadcast

8.1.255.255

0000 1000 0000 0001 1111 1111 1111 1111

 

 

 

Table 4-16 Calculating the Broadcast Address: Address 130.4.102.1, Mask 255.255.255.0

Address

130.4.102.1

1000 0010 0000 0100 0110 0110 0000 0001

 

 

 

Mask

255.255.255.0

1111 1111 1111 1111 1111 1111 0000 0000

 

 

 

AND Result

130.4.102.0

1000 0010 0000 0100 0110 0110 0000 0000

 

 

 

Broadcast

130.4.102.255

1000 0010 0000 0100 0110 0110 1111 1111

 

 

 

Table 4-17 Calculating the Broadcast Address: Address 199.1.1.100, Mask 255.255.255.0

Address

199.1.1.100

1100 0111 0000 0001 0000 0001 0110 0100

 

 

 

Mask

255.255.255.0

1111 1111 1111 1111 1111 1111 0000 0000

 

 

 

AND Result

199.1.1.0

1100 0111 0000 0001 0000 0001 0000 0000

 

 

 

Broadcast

199.1.1.255

1100 0111 0000 0001 0000 0001 1111 1111

 

 

 

Analyzing and Interpreting IP Addresses and Subnets 119

Table 4-18 Calculating the Broadcast Address: Address 130.4.102.1, Mask 255.255.252.0

Address

130.4.102.1

1000 0010 0000 0100 0110 0110 0000 0001

 

 

 

Mask

255.255.252.0

1111 1111 1111 1111 1111 1100 0000 0000

 

 

 

AND Result

130.4.100.0

1000 0010 0000 0100 0110 0100 0000 0000

 

 

 

Broadcast

130.4.103.255

1000 0010 0000 0100 0110 0111 1111 1111

 

 

 

Table 4-19 Calculating the Broadcast Address: Address 199.1.1.100, Mask 255.255.255.224

Address

199.1.1.100

1100 0111 0000 0001 0000 0001 0110 0100

 

 

 

Mask

255.255.255.224

1111 1111 1111 1111 1111 1111 1110 0000

 

 

 

AND Result

199.1.1.96

1100 0111 0000 0001 0000 0001 0110 0000

 

 

 

Broadcast

199.1.1.127

1100 0111 0000 0001 0000 0001 0111 1111

 

 

 

By examining the subnet broadcast addresses in binary, you can see that they are identical to the subnet numbers, except that all host bits have a value of binary 1 instead of binary 0. (Look for the bold digits in the examples.)

NOTE In case you want to know, to derive the broadcast address using Boolean math, start with the subnet number and mask in binary. Invert the mask (change all the 1s to 0s and all the 0s to 1s), and then do a bitwise Boolean OR between the two 32-bit numbers. (An OR yields a 0 when both bits are 0 and yields a 1 in any other case.) The result is the subnet broadcast address.

Finding the Range of Valid IP Addresses in a Subnet

You also need to be able to figure out which IP addresses are in a particular subnet and which are not. You already know how to do the hard part of finding that answer! You know that in any subnet, two numbers are reserved. The two reserved numbers are the subnet number itself and the subnet broadcast address. The subnet number is the numerically smallest number in the subnet, and the broadcast address is the numerically largest number. So the range of valid IP addresses starts with 1 more than the subnet number and ends with the address that is 1 less than the broadcast address. It’s that simple!

Here’s a formal definition of the “algorithm” to find the first and last IP addresses in a subnet when you know the subnet number and broadcast addresses:

For the first valid IP address, copy the subnet number, but add 1 to the fourth octet.

For the last valid IP address, copy the subnet broadcast address, but subtract 1 from the fourth octet.

120 Chapter 4: IP Addressing and Subnetting

The range of valid IP addresses starts with the first number and ends with the last. Tables 4-20 through 4-24 summarize the answers for the five examples used in this section.

Table 4-20 Subnet Chart: 8.1.4.5/255.255.0.0

 

 

 

 

 

 

 

 

 

 

 

 

Octet

 

1

2

3

4

 

 

 

 

 

 

 

 

Address

 

8

1

4

5

 

 

 

 

 

 

 

 

Mask

 

255

255

0

0

 

 

 

 

 

 

 

 

Subnet Number

 

8

1

0

0

 

 

 

 

 

 

 

 

First Address

 

8

1

0

1

 

 

 

 

 

 

 

 

Broadcast

 

8

1

255

255

 

 

 

 

 

 

 

 

Last Address

 

8

1

255

254

 

 

 

 

 

 

 

Table 4-21 Subnet Chart: 130.4.102.1/255.255.255.0

Octet

1

2

3

4

 

 

 

 

 

Address

130

4

102

1

 

 

 

 

 

Mask

255

255

255

0

 

 

 

 

 

Subnet Number

130

4

102

0

 

 

 

 

 

First Address

130

4

102

1

 

 

 

 

 

Broadcast

130

4

102

255

 

 

 

 

 

Last Address

130

4

102

254

 

 

 

 

 

Table 4-22 Subnet Chart: 199.1.1.100/255.255.255.0

Octet

1

2

3

4

 

 

 

 

 

Address

199

1

1

100

 

 

 

 

 

Mask

255

255

255

0

 

 

 

 

 

Subnet Number

199

1

1

0

 

 

 

 

 

First Address

199

1

1

1

 

 

 

 

 

Broadcast

199

1

1

255

 

 

 

 

 

Last Address

199

1

1

254