第四章 IP地址 子网划分 VLSM CIDR Purpose: This chapter reviews the physical layer and describes how to cable various network devices. Timing: This chapter takes approximately 1 hour to present. Note: This section has a cabling laboratory exercise at the end. Contents: Objectives—This section explains what the student will be able to do at the end of this chapter. TCP/IP Overview—This section describes the TCP/IP protocol stack. TCP/IP Application Layer Overview—This section describes the application protocols. TCP/IP Transport Layer Overview—This section describes TCP and UDP. TCP/IP Internet Layer Overview—This section describes IP and other Internet layer protocols. TCP/IP Address Overview—This section describes IP addressing. Configuring IP Addresses—This section describes how to address an IOS device with IP Interconnecting Networks—This section describes how to interconnect separate VLANs and WANs With TCP/IP. Written Exercise—This section has students work with IP addresses in binary format.
本章目标 通过本章学习,您应该掌握以下内容: 掌握IP地址分类,子网掩码的作用,识别网络标识号、主机标识号,子网的数目、主机的数目, 掌握VLSM和CIDR的概念 Purpose: This figure states the chapter objectives. Emphasize: Read or state each objective so each student has a clear understanding of the chapter objectives.
十进制和二进制的转换 128 64 32 16 8 4 2 1 1 0 0 0 0 0 0 0 = 128 1 1 0 0 0 0 0 0 = 192 1 1 1 0 0 0 0 0 = 224 1 1 1 1 0 0 0 0 = 240 1 1 1 1 1 0 0 0 = 248 1 1 1 1 1 1 0 0 = 252 1 1 1 1 1 1 1 0 = 254 1 1 1 1 1 1 1 1 = 255 Purpose: This figure explains how subnet masks are converted to decimal addresses. Emphasize: Review binary-to-decimal conversion, bit weighting, and conversion. Explain logical AND. One possible explanation of logical AND follows: We will need to be able to perform a logical AND on the binary numbers. Just take two binary numbers and place one above the other. The ones in the bottom are like a pipe—the number above it just drops through. The zeros are like a clogged pipe, so nothing comes out in the answer. Presenting a truth table will help some students understand. You might need to give more than one explanation. Note: You might want to hand out a binary-to-decimal conversion sheet if you have not already done so. We have not included one in the lab section. It is more useful to have one that is on a separate page from the labs.
255 255 255 IP 地 址 255 32 bits Dotted Decimal Network Host Maximum Layer 1 of 3: Purpose: This figure show the general format of an IP address. In layer 1, the address is 32 bits with a network and host portion.
IP 地 址 32 bits Dotted Decimal Network Host 255 255 255 255 Maximum 1 8 9 16 17 24 25 32 11111111 11111111 11111111 11111111 Layer 3 of 3: In layer 2, one can convert the address to binary. Binary 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1
IP 地 址 32 bits Dotted Decimal Network Host 255 255 255 255 Maximum 1 8 9 16 17 24 25 32 11111111 11111111 11111111 11111111 Layer 3 of 3: In layer 3, an example of dotted-decimal format and binary are displayed. Emphasize: IP address format is dotted-decimal. Dotted-decimal makes it easy to work with IP addresses. However, in this course we will work with the addresses on the bit level, so we will convert these addresses into binary, make changes to them, and convert them back. The central authority for addresses is the Internet Assigned Numbers Authority. Note: This most common form of addressing reflects the widely used IP version 4. Faced with the problem of depleting available addresses, Internet Engineering Task Force (IETF) work is under way for a backward-compatible next generation of IP (IPng, also called IP 6). IP 6 will offer expanded routing and addressing capabilities with 128-bit addresses rather than the 32-bit addressing shown on the graphic. Addresses from both IP versions will coexist. Initial occurrences will probably be at locations with address translator software and firewalls. Binary 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1 172 16 122 204 Example Decimal 10101100 00010000 01111010 11001100 Example Binary
IP 地址分类 Class A: Class B: Class C: Class D: 多播地址 Class E: 科研用 8 bits Network Host Network Host Network Host Purpose: This graphic describes the three most common classes of IP address. Emphasize: Discuss classes of addresses. Each address contains information about the network number and the host number of the device. Class A addresses are for very large organizations. Class B addresses are for smaller organizations, and Class C addresses for even smaller ones. As the number of networks grows, classes may eventually be replaced by another addressing mechanism, such as classless interdomain routing (CIDR). RFC 1467, Status of CIDR Deployment in the Internet, presents information about CIDR. RFC 1817, CIDR and Classful Routing, also presents CIDR information.
IP 地址分类 Class A: Class B: Class C: Class D: 1 8 9 16 17 24 25 32 Bits: 0NNNNNNN Host Host Host Class A: 范围 (1-126) 1 8 9 16 17 24 25 32 Bits: 10NNNNNN Network Host Host Class B: Emphasize: Highlight the fixed values that start each class address. The first octet rule states that when an address falls into a specified range, it belongs to a certain class. Students should soon be able to recognize the address class of any IP address on sight. Note: If time or interest permits, you can use the initial bit patterns in the first octet and show how a class of IP network derives the range of network numbers for that IP address class. 范围 (128-191) 1 8 9 16 17 24 25 32 Bits: 110NNNNN Network Network Host Class C: 范围 (192-223) 1 8 9 16 17 24 25 32 Bits: 1110MMMM Multicast Group Multicast Group Multicast Group Class D: 范围 (224-239)
特殊IP地址 一些特殊的IP 地址: 1.IP 地址127.0.0.1:本地回环(loopback)测试地址 2.广播地址:255.255.255.255 3.IP 地址0.0.0.0:代表任何网络 4.节点号全为1:代表该网段的所有主机 广播地址TCP/IP 协议规定,主机号部分各位全为1 的IP 地址用于广播.所谓广播地址指同时 向网上所有的主机发送报文,也就是说,不管物理网络特性如何,Internet 网支持广播传输.如136.78.255.255 就是B 类地址中的一个广播地址,你将信息送到此地址,就是将信息送给网络号为136.78 的所有主机.
私有IP地址 私有IP地址: 1.A 类地址中:10.0.0.0 到10.255.255.255 2.B 类地址中:172.16.0.0 到172.31.255.255 3.C 类地址中:192.168.0.0 到192.168.255.255
计算可用的主机地址 网络 主机 172 16 0 0 N 10101100 00010000 00000000 00000000 1 16 15 14 13 12 11 10 9 00000000 8 7 6 5 4 3 2 1 00000001 2 00000000 00000011 3 ... ... ... Purpose: This figure explains how to calculate the number of available hosts in a network. Emphasize: 2N-2 is the calculation to determine available hosts. N is the number of binary digits in the host field. Subtract 2 because a host cannot be all 0s or 1s. The same principal applies when determining the number of available networks. 11111111 11111101 65534 11111111 11111110 65535 11111111 11111111 65536 - 2 2N-2 = 216-2 = 65534 65534
IP地址分类练习 地址 类别 网络 主机 10.2.1.1 128.63.2.100 Layer 1 of 2: Purpose: This exercise verifies that the students understand IP address classes, network numbers, and host numbers. Give the students time to list the address class, network, and host number for each IP address in the table. Review the correct answers interactively. The answers are given in the following figure. 201.222.5.64 192.6.141.2 130.113.64.16 256.241.201.10
IP地址分类练习 (答案) 地址 类别 网络 主机 10.2.1.1 A 10.0.0.0 0.2.1.1 128.63.2.100 B 128.63.0.0 0.0.2.100 Layer 2 of 2: Purpose: This answers to the exercise are given in the figure. Note: Students can also find the answers to this exercise in the “Answers” appendix. 201.222.5.64 C 201.222.5.0 0.0.0.64 192.6.141.2 C 192.6.141.0 0.0.0.2 130.113.64.16 B 130.113.0.0 0.0.64.16 256.241.201.10 Nonexistent
子网划分的好处 1.缩减网络流量 2.优化网络性能 3.简化管理 4.更为灵活地形成打覆盖范围的网络
不设子网的地址 172.16.0.1 172.16.0.2 172.16.0.3 172.16.255.253 172.16.255.254 Purpose: This figure explains what networks look like without subnets. Without subnets, use of network addressing space is inefficient. The Class B network is like a highway with no exits—there is no place to exit, so all of the traffic is in one line. …... 172.16.0.0 网络 172.16.0.0
设置子网的地址 172.16.3.0 172.16.4.0 Purpose: This figure describes network structure when subnets are used. Emphasize: The host bits of an IP address can be subdivided into a subnetwork section and a host section. The subnetwork section in this example is the full third octet. Point out the difference in the addressing between the previous slide and this slide. A subnetted address space is like a highway with exits. A network device uses a subnet mask to determine what part of the IP address is used for the network, the subnet, and the device ID. A subnet mask is a 32-bit value containing a number of one bits for the network and subnet ID and a number of zero bits for the host ID. Given its own IP address and subnet mask, a device can determine if an IP packet is destined for 1) a device on its own subnet, 2) a device on a different subnet on its own network, or 3) a device on a different network. A device can determine what class of address the device has been assigned from its own IP address. The subnet mask then tells the device where the boundary is between the subnet ID and the host ID. 172.16.1.0 172.16.2.0 网络 172.16.0.0
缺省情况下的子网掩码 缺省情况下子网未划分 网络 主机 网络号 172.16.2.160 10101100 00010000 00000010 10100000 255.255.0.0 11111111 11111111 00000000 00000000 00000000 00000000 Purpose: This graphic explains how routers use addresses that have no subnet mask. Emphasize: Explain how masking works at the bit level. Zero bits mask host information. Note: This is an easy place to lose students. At this point, they need to learn several abstract mathematical concepts before we can show them how to lay out an IP-addressed network. To the novice these techniques may seem unrelated, making the presentation confusing. To a more experienced audience, these techniques will be familiar. 10101100 00010000 网络号 172 16 缺省情况下子网未划分
子网地址 172.16.2.200 172.16.3.5 172.16.3.1 E1 172.16.2.2 E0 172.16.3.100 172.16.2.1 172.16.2.160 172.16.3.150 Layer 1 of 2: Purpose: This figure shows what would happen if there were no subnetting. Emphasize: If networks could not be broken down into more granular, subnetworks few networks could exist, each with a capacity for many hosts. 新路由表 172.16 . 2 . 160 网络 端口 网络 主机 172.16.0.0 E0 E1
子网地址 172.16.2.200 172.16.3.5 172.16.3.1 E1 172.16.2.2 E0 172.16.3.100 172.16.2.1 172.16.2.160 172.16.3.150 Layer 1 of 2: Emphasize: By turning on more bits in the mask, we reserve some bits as network information and can use these bits to describe subnetworks. Describe how the router makes use of this technique. Point out that there is more information in the routing table now. Note: As you enter the discussion about subnet masks, a question might arise about whether it is legal to define a discontiguous subnet mask. A discontiguous subnet mask consists of intervening zeros, as in 101111011000, rather than all ones followed by zeros, as in 1111111100000000. The question has two answers. According to RFC 950 that describes IP, a discontiguous subnet mask is legal. However, the hardware expense to produce an interface that supports discontiguous masking is cost-prohibitive. Thus in practice it is not supported on most vendors’ equipment, including Cisco. Also, discontiguous masking has no benefit, and it is much more difficult to maintain a network based on this design. Later RFCs make noncontiguous subnet masks illegal because they are incompatible with future addressing schemes such as CIDR. 新路由表 172.16 . 2 . 160 网络 端口 网络 子网 主机 172.16.2.0 172.16.3.0 E0 E1
子网掩码 172 16 255 255 255 Network Host IP Address Network Host IP Address Network Host Default Subnet Mask 255 255 11111111 11111111 00000000 00000000 A:/8 10.0.0.0 255.0.0.0>10.0.0.0/8 172.16.0.0 255.255.0.0>172.16.0.0/16 “/16” 表示子网掩码有16位. Network Subnet Host 8-bit Subnet Mask 255 “/24”表示子网掩码有24位.
利用子网掩码划分子网 扩展了8位地址的网络 网络 子网 主机 网络号 172.16.2.160 10101100 00010000 00000010 10100000 255.255.255.0 11111111 11111111 11111111 00000000 Purpose: This figure shows how the router determines an address when subnetting is used. Emphasize: This example makes a Class B address space look like a collection of Class C address spaces. Now the logical AND allows us to extract the subnet number as well as the assigned network number. An exercise follows that tests the students’ understanding of subnet masks. 10101100 00010000 00000010 00000000 128 192 224 240 248 252 254 255 网络号 172 16 2 扩展了8位地址的网络
利用子网掩码划分子网 扩展了10位地址的网络 网络 子网 主机 网络号 172.16.2.160 10101100 00010000 00000010 10100000 255.255.255.192 11111111 11111111 11111111 11000000 Purpose: This figure shows how the router determines an address when subnetting is used. Emphasize: This example is different from the previous example in that the the subnet and host are divided within an octet. Transition: An exercise follows that tests the students’ understanding of subnet masks. 10101100 00010000 00000010 10000000 128 192 224 240 248 252 254 255 128 192 224 240 248 252 254 255 网络号 172 16 2 128 扩展了10位地址的网络
子网划分的核心思想 “借用”主机位来“制造”新的“网络”
划分子网方法 划分子网方法: 1.你所选择的子网掩码将会产生多少个子网?:2 的x 次方(x 代表掩码位数) 2.每个子网能有多少主机?: 2 的y 次方-2(y 代表主机位数) 3.有效子网是?:有效子网号=256-10 进制的子网掩码(结果叫做block size 或base number) 4.每个子网的广播地址是?:广播地址=下个子网号-1 5.每个子网的有效主机分别是?:忽略子网内全为0 和全为1 的地址剩下的就是有效主机地址. 最后有效1 个主机地址=下个子网号-2(即广播地址-1)
C类地址子网划分例子 网络地址192.168.10.0;子网掩码255.255.255.192(/26) 1.子网数=2*2=4 2.主机数=2 的6 次方-2=62 3. 有效子网?:block size=256-192=64; 所以第一个子网为192.168.10.0, 第二个为192.168.10.64,最后一个为192.168.10.192 4.广播地址:下个子网-1.所以第一个子网的广播地址是192.168.10.63,第二个是192.168.10.127,最后一个是192.168.10.255 5.有效主机范围是:第一个子网的主机地址是192.168.10.1 到192.168.10.62;第二个是192.168.10.65 到192.168.10.126;最后一个是192.168.10.193到192.168.10.254
B类地址子网划分例子1 例子1:网络地址:172.16.0.0;子网掩码255.255.192.0(/18) 1.子网数=2*2=4 2.主机数=2 的14 次方-2=16382 3.有效子网?:block size=256-192=64;所以第一个子网为172.16.0.0,第二个为172.16.64.0,最后1 个为172.16.192.0 4.广播地址:下个子网-1.所以第一个子网的广播地址是172.16.63.0,第二个为172.16.127.0,最后一个为172.16.255.0 5.有效主机范围是:第一个子网的主机地址是172.16.0.1 到172.16.62.254;第二个是172.16.64.1 到172.16.126.254;最后一个是172.16.192.1到172.16.254.254
B类地址子网划分例子2 B 类地址例子2:网络地址:172.16.0.0;子网掩码255.255.255.224(/27) 2.主机数=2 的5 次方-2=30 3. 有效子网?:block size=256-224=32; 所以第一个子网为172.16.0.0, 第二个为172.16.0.32,最后一 个为172.16.255.224 4.广播地址:下个子网-1.所以第一个子网的广播地址是172.16.0.31,第二个为172.16.0.63,最后一个为172.16.255.255 5.有效主机范围是:第一个子网的主机地址是172.16.0.1到172.16.0.30;第二个是172.16.0.33到172.16.0.62最后1 个是172.16.255.225 到172.16.255.254
变长子网掩码(VLSM) 变长子网掩码(Variable-Length Subnet Masks,VLSM)的出现是打破传统的以类(class)为标准的地址划分方法,是为了缓解IP 地址紧缺而产生的 作用:节约IP 地址空间;减少路由表大小. 注意事项:使用VLSM 时,所采用的路 由协议必须能够支持它,这些路由协议包括RIPv2,OSPF,EIGRP 和BGP.
VLSM预备知识-前缀 地址范围: 192.168.1.64 - 192.168.1.79 前缀长度为/28 192.168.1.64/28 第四个8位位组 64 01000000 65 01000001 66 01000010 67 01000011 68 01000100 69 01000101 70 01000110 71 01000111 72 01001000 73 01001001 74 01001010 75 01001011 76 01001100 77 01001101 78 01001110 79 01001111
VLSM的实现(1)
需求 1.D 需要2 个VLAN,然后每个VLAN 容纳200 个用户. 2.A,B 和C 连接3 个以太网,分别用1 个24 口的交换机相连 D—S0—172.16.1.0/24 D—S0—172.16.2.0/24 255.255.255.11100000 A—E0—172.16.0.0/27 B—E0—172.16.0.32/27 C—E0—172.16.0.64/27
VLSM的实现(2)
VLSM的实现(3)
VLSM的实现(4)
VLSM的实现(5)
VLSM的实现(6)
无类域间路由 (CIDR) CIDR的概念:忽略A、B、C类网络的规则,定义前缀相同的一组网络为一个块,即一条路由条目。(如:199.0.0.0/8)
CIDR的优点 减少了网络数目,缩小了路由选择表 从网络流量、CPU和内存方面说,开销更低 对网络进行编址时,灵活性更大
CIDR例子
CIDR计算方法
本章总结 通过本章学习,您应该掌握以下内容: 掌握IP地址分类,子网掩码的作用,识别网络标识号、主机标识号,子网的数目、主机的数目, 掌握VLSM和CIDR的概念 Purpose: This figure states the chapter objectives. Emphasize: Read or state each objective so each student has a clear understanding of the chapter objectives.