IP地址分配第三章完成本章的学习后,您可以完成下面的任务:•分配IP地址,区分地址级别,网络部分和主机部分•给定IP地址和子网掩码,计算相应的子网•根据给定的网络地址和子网掩码配置IP地址•把主机名和一个IP地址做一个映射•利用网络工具发现网络中路由器的IP地址目标TCP/IP地址概述•唯一的地址分配机制保证通讯的可靠性•根据所处的位置选择路径•用地址代表网络设备所处的位置TCP/IP地址入门UNIX主机UNIX主机公司A公司B地址分配32BitsNetworkHost8Bits172.16.122.2048Bits8Bits8BitsIP地址分配目前的IP地址(IPv4:IP第4版本)由32个二进制位表示,每8位二进制数为一个整数,中间由小数点间隔,如159.226.41.98,整个IP地址空间有4组8位二进制数,由表示主机所在的网络的地址(类似部队的编号)以及主机在该网络中的标识如同士兵在该部队的编号)共同组成IP地址分配为了便于寻址和层次化的构造网络,IP地址被分为A、B、C、D、E五类,商业应用中只用到A、B、C三类。IP地址分配•A类地址:A类地址的网络标识由第一组8位二进制数表示,网络中的主机标识占3组8位二进制数,A类地址的特点是网络标识的第一位二进制数取值必须为“0”。不难算出,A类地址允许有126个网段,每个网络大约允许有1670万台主机,通常分配给拥有大量主机的网络(如主干网)。A类网络的IP地址范围为1.0.0.1-126.255.255.254IP地址分配•B类地址:B类地址的网络标识由前两组8位二进制数表示,网络中的主机标识占两组8位二进制数,B类地址的特点是网络标识的前两位二进制数取值必须为“10”。B类地址允许有16384个网段,每个网络允许有65533台主机,适用于结点比较多的网络(如区域网)。B类网络的IP地址范围为:128.1.0.1-191.255.255.254IP地址分配•C类地址:C类地址的网络标识由前3组8位二进制数表示,网络中主机标识占1组8位二进制数,C类地址的特点是网络标识的前3位二进制数取值必须为“110”。具有C类地址的网络允许有254台主机,适用于结点比较少的网络(如校园网)。C类网络的IP地址范围为:192.0.1.1-223.255.255.254IP地址分配•ClassA:•ClassB:•ClassC:•ClassD:用于组拨(multicast)•ClassE:用于研究N=网络号H=主机号IP地址分配NHHHNNHHNNNH不同IP地址Bit位的区别1724ClassA:#Bits114161ClassB:#Bits121811ClassC:#Bits0network#host#1network#host#01network#host#10识别IP地址的类别HighOrderBitsOctetinDecimalAddressClass0101101-126128-191192-223ABC练习:IP地址的级别AddressClassNetworkHost10.2.1.1128.63.2.100201.222.5.64192.6.141.2130.113.64.16256.241.201.10练习答案:IP地址的级别AddressClassNetworkHost10.2.1.1128.63.2.100201.222.5.64192.6.141.2130.113.64.16256.241.201.10ABCCBNonexistent10.0.0.0128.63.0.0201.222.5.0192.6.141.0130.113.0.00.2.1.10.0.2.1000.0.0.640.0.0.20.0.64.16配置IP地址主机地址172.16.2.1172.16.3.10172.16.12.12IP:172.16.2.110.1.1.110.250.8.1110.180.30.118IP:10.6.24.2E0E1172.161212NetworkHost..NetworkInterface172.16.0.010.0.0.0E0E1RoutingTable•Network172.16.0.0172.16.0.0无子网时的地址分配•Network172.16.0.0有子网时的地址分配172.16.1.0172.16.2.0172.16.3.0172.16.4.0子网地址172.16.2.200172.16.2.2172.16.2.160IP:172.16.2.1172.16.3.5172.16.3.100172.16.3.150IP:172.16.3.1E0E1172.162160NetworkHost..NetworkInterface172.16.2.0172.16.3.0E0E1NewRoutingTableSubnet子网掩码1721600255255002552552550IPAddressDefaultSubnetMask8-bitSubnetMaskNetworkHostUsehostbits,startingatthehighorderbitpositionNetworkHostNetworkSubnetHost子网掩码IP地址的二进制和十进制表示法的对应关系10000000=12811000000=19211100000=22411110000=24011111000=24811111100=25211111110=25411111111=2551286432168421练习:子网掩码AddressSubnetMaskClassSubnet172.16.2.1010.6.24.2010.30.36.12255.255.255.0255.255.0.0255.255.255.0练习(答案):子网掩码AddressSubnetMaskClassSubnet172.16.2.1010.6.24.2010.30.36.12255.255.255.0255.255.0.0255.255.255.0BAA172.16.2.010.6.0.010.30.36.0规划IP子网Othersubnets20subnets5hostspersubnetClassCaddress:201.222.5.0201.222.5.16201.222.5.32201.222.5.48IPHostAddress:172.16.2.120SubnetMask:255.255.255.0•SubnetAddress=172.16.2.0•HostAddresses=172.16.2.1-72.16.2.254•BroadcastAddress=172.16.2.255•EightbitsofsubnettingNetworkSubnetHost1721620172.16.2.120:255.255.255.0:1010110011111111Subnet:10101100000100000001000011111111000000100000001011111111011110010000000000000000B类子网规划举例IPHostAddress:201.222.5.121SubnetMask:255.255.255.248NetworkSubnetHost2012225120201.222.5.121:1100100111111111Subnet:11001001110111101101111011111111000001010000010111111111011110011111100001111000255.255.255.248:C类子网规划举例•SubnetAddress=201.222.5.120•HostAddresses=201.222.5.121-01.222.5.126•BroadcastAddress=201.222.5.127•FiveBitsofSubnetting广播地址172.16.1.0172.16.2.0172.16.3.0172.16.4.0172.16.3.255(Directedbroadcast)255.255.255.255(Localnetworkbroadcast)X练习:广播地址AddressClassSubnetBroadcast201.222.10.60255.255.255.248SubnetMask15.16.193.6255.255.248.0128.16.32.13255.255.255.252153.50.6.27255.255.255.128练习(答案):广播地址AddressClassSubnetBroadcast201.222.10.60255.255.255.248C201.222.10.63201.222.10.56SubnetMask15.16.193.6255.255.248.0A15.16.199.25515.16.192.0128.16.32.13255.255.255.252B128.16.32.15128.16.32.12153.50.6.27255.255.255.128B153.50.6.127153.50.6.0地址子网化的例子CiscoACiscoBE0S0E0S0To0CiscoAE0:172.16.2.1S0:172.16.1.1S0:172.16.1.2E0:144.254.4.1To0:144.254.16.1CiscoBMask255.255.255.0Subnet172.16.2.0172.16.1.0172.16.1.0144.254.16.0144.254.4.0MaskSubnet255.255.255.0255.255.255.0255.255.252.0255.255.252.0TokenRing配置IP地址Router(config-if)#•分配一个IP地址和子网掩码•在端口上运行IP进程ipaddressip-addresssubnet-maskRouter(config-line)#ipnetmask-format{bitcount|decimal|hexadecimal}•在端口配置模式下配置网络地址的表示格式Router#termipnetmask-format{bitcount|decimal|hexadecimal}•配置网络地址的表示格式Router(config)#•给主机名静态的指定一个IP地址•可以有多个IP地址与主机名对应主机名iphostname[tcp-port-number]address[address]iphostP1R11.0.0.52.0.0.8iphostP1R21.0.0.4•指定一个或多个主机提供从主机名到逻辑地址的映射服务Router(config)#配置名字服务器ipname-serverserver-address1[[server-address2]...server-address6]•路由器缺省启用DNS服务•关闭名字服务Router(config)#Router(config)#名字系统ipdomain-lookupnoipdomain-lookup显示主机名Router#showhostsDefaultdomainisnotsetName/addresslookupusesstaticmappingsHostFlagsAgeTypeAddress(es)P1R1(perm,OK)5IP144.253.100.200133.3.13.2133.3.5.1P2R1(perm,OK)5IP144.253.100.201153.50.3.2153.50.5.6P2R2(perm,OK)**IP128.45.17.4153.50.3.200153.50.34.17P2R3(perm,OK)**IP172.26.40.11153.50.5.7153.50.34.1--More--检验配置的地址Ap