第四章 TCP-IP协议.ppt
计算机网络、路由及交换技术第四章 TCP/IP协议常见的网络层协议nIPX/SPXnAppletalknNetBEUInTCP/IPnTransmission Control Protocol/Internet ProtocolTCP/IP模型nThe Process/Application layern定义用户接口,应用程序nThe Host-to-Host layern端到端传输服务nThe Internet layern逻辑寻址n路由nThe Network Access layern物理寻址n数据传输TCP/IP协议栈Process/Application Layern联合了OSI参考模型上三层的功能,定义了点到点的应用通信协议以及用户接口规范n常见应用-Telnet-FTP(File Transfer Protocol)-TFTP(Trivial File Transfer Protocol)-NFS(Network File System)-SMTP(Simple Mail Transfer Protocol)-DNS(Domain Name Service)-DHCP(Dynamic Host Configuration Protocol)-SNMP(Simple Network Management Protocol)Host-to-Host Layer Protocoln主要功能是隐藏上层应用,用来进行数据传输服务n提供可靠的端到端的通信n顺序处理包,保证包的完整性n主要包括两个协议:TCP和UDPn对应OSI参考模型的传输层端口号nTCP/UDP利用端口号同上层协议通讯,端口号用来保持网络中同时通讯的不同会话n源端口号被发送方主机动态分配,从1024开始n1023以下被预先定义nTCP和上层协议不使用IP和MAC地址区别发送主机,而使用端口号用于区别主机间的通讯,因此同一主机可以对另一主机有不同需求TCP功能nMultiplexnError Recovery(Reliability)nFlow Control using WindowingnConnection establishment and terminationnData TransferMultiplexError Recovery(Reliability)Flow Control using Windowingn利用SEQ和ACKnWindow字段,为接受方使用,用来告诉发送方发送多少数据而要求一个确认n可以要求发送多个TCP Segment而要求一个ACKnWindow大小可以依网络性能上下滑动nWindow是对称的Connection establishment and terminationn发生在任何其它TCP特性开始工作之前n连接建立主要用来初始化SEQ和ACK,以及portn连接存在于两个Socket之间nSYN和ACK Flagsn断开连接:FINData Transfern重新排序TCP格式TCP格式nSource/Destination Port:建立连接的源/目的端口号nSequence Number:数据传送的编号,按顺序传送nAcknowledgment Number:确认号,指明即将传输的下一个TCP段nHeader Length:TCP头长度nCode bits:功能控制位,被用来建立和终止会话nWindow:希望传送的window尺寸nChecknum:CRCnUrgent Pointer:指定紧急数据的末尾nOption:可选字段,设置TCP段的最大尺寸nData:上层数据TCP传输过程我刚刚发送完#10信息我刚刚接收完#10信息010231028确认号序号目的端口源端口11100102823确认号序号目的端口源端口10111231028确认号序号目的端口源端口UDPn可替代TCP的传输协议,Thin Protocol,不占用更多网络负载n不建立连接,也不用建立虚电路n不用按顺序传输数据n传输不可靠,假定数据传输的可靠性由上层处理,如:NFS、DNSn使用UDP具有更高效率,诸如:SNMPTCP和UDP的比较TCPUDPSequencedUnSequencedReliableUnReliableConnection-OrientedConnectionlessVirtual CircuitLow Overhead-Telephone-MailInternet Layer ProtocolnInternet Layer Protocol 功能:n路由n寻址nIP层的四个协议-Internet Protocol(IP)-Internet Control Message Protocol(ICMP)-Address Resolution Protocol(ARP)-Reverse Address Resolution Protocol(RARP)Internet Protocol(IP)nInternet层的主要协议,其他协议仅仅是为了支持它,每个网络设备都需要网络地址n每个包都是用IP地址,决定包被发往何处n网络地址和主机IP地址IP HeaderIP HeadernVersion:IP版本号nHLEN:IP Header 长度nPriority or ToS:服务类型,告诉数据报应该怎样被处理,前3bit为优先级nTotal Length:包括IP Header和数据总长度nIdentification:唯一的IP标识值nFlags:指定分段是否发生nFlags Offset:提供分段和重装配,如果包太大不能放在一个帧中nTTL:包存活时间nProtocol:上层协议,如:TCP=6,UDP=17nHeader Checksum:IP Header 校验和nSource IP/Destination IP:32bitnIP Option:被用来进行网络测试,Debug,安全等IP Header 实例nIP Header-Internet Protocol DatagramnVersion:4nHeader Length:5nPrecedence:0nType of Service:%000nUnused:%00nTotal Length:187nIdentifier:22486nFragmentation Flags:%010 Do Not FragmentnFragment Offset:0nTime To Live:60nIP Type:0 x06 TCPnHeader Checksum:0 xd031nSource IP Address:10.7.1.30nDest.IP Address:10.7.1.10nNo Internet Datagram OptionsICMP(Internet Control Message Protocol)n被用在网络层,为IP协议提供管理服务n消息传输使用IP协议nICMP消息-ICMP Echo Request and Reply-Time Exceeded-Destination Unreachablen应用-Ping(Packet Internet Groper):检查物理连接-Traceroute 检查包到目的路径ICMP头实例nIP Header-Internet Protocol DatagramnVersion:4nHeader Length:5nPrecedence:0nType of Service:%000nUnused:%00nTotal Length:60nIdentifier:56325nFragmentation Flags:%000nFragment Offset:0nTime To Live:32nIP Type:0 x01 ICMPnHeader Checksum:0 x2df0nSource IP Address:100.100.100.2nDest.IP Address:100.100.100.1nNo Internet Datagram OptionsARP(Address Resolution Protocol)n已知目的主机的IP地址,寻找硬件地址n过程:-发送方首先从Cache中查找,如没有则传输ARP广播-收到ARP需求的目的主机返回硬件地址RARP(Reverse Address Resolution Protocol)n已知主机MAC地址,查找IP地址n主要用于无盘工作站IP Addressingn网络设备的逻辑地址,用以分配给IP网络的每一个设备,又称为Host AddressnIP地址允许不同网络类型的计算机相互通讯n32bitnIP表示法-172.16.30.56-10101100.00010000.00011110.00111000-82 39 1E 38IP AddressingnIP地址分级方案-232个IP地址,但不能全部放到路由表中-分级方案:两级或三级方案,Network、Subnet、HostnNetwork Addressing-网络地址,独一标识每个网络,同一网段共享相同的IP地址网络部分nNode Addressing节点地址,唯一标识每个主机IP地址分类n为了更好的实施地址管理nA类:第1位为“0”,0-127之间nB类:第1、2位为“10”,128-191之间nC类:第1、2、3位为“110”,192-223之间nD类:前4位为“1110”,224-239之间,用于多播地址nE类:前4位为“1111”,240-254保留试验和研究使用A类地址n1-126,126个网络可用,0被用作缺省路由,127被用作Lookback测试n每个A类网络主机地址,224-2个可用,全0全1被保留n例:10.0.0.99/255.0.0.0-网络地址:10.0.0.0-广播地址:10.255.255.255B类地址n前2Byte表示网络地址,214个网络地址n每个B类网络主机地址:216-2=65534个节点地址n例:159.226.132.130/255.255.0.0-网络地址:159.226.0.0-广播地址:159.226.255.255C类地址n前3Byte表示网络地址,221个网络地址n每个C类网络主机地址:254个节点地址n例:210.72.132.2/255.255.255.0-网络地址:210.72.132.0-广播地址:210.72.132.255特殊的IP地址nNetwork 127.0.0.1:本地地址,用于Lookback测试nNode Address of all 0s:网络地址,如:210.72.131.128nNode Address of all 1s:指定网络所有节点,如:210.72.131.255nEntire IP address set to all 0s:缺省路由nEntire IP address set to all 1s:255.255.255.255,当前网络广播地址。子网掩码n每个主机必须知道,主机地址中的哪一个部分将被用作网络或子网地址n子网掩码是一个32bit的值,用来区别地址中网络地址和主机地址n掩码由1或0组成,1部分表示网络或子网地址,0部分表示主机地址nIP地址同掩码相与,如果得到相同值则认为在同一个子网获网络中nA、B、C类地址缺省掩码n子网掩码必须按序设置:前部分为1后部分为0n掩码表示法-192.168.100.0/255.255.255.0-192.168.100.0/24私有网络n用于企业内部IP地址分配n10.0.0.0/8:10.0.0.010.255.255.255172.16.0.0/12:172.16.0.0172.31.255.255192.168.0.0/16:192.168.0.0192.168.255.255Subnettingn用来将一个大的网络分成小的网络n定义了广播域n子网化的原因和好处-减少网络通讯量-优化了网络性能-简化管理,冗以隔离问题所在-有利于生成大型区域网络子网化步骤n定义所需的网络ID数目-每个子网-每个广域网连接接口n定义每个子网主机数目-每个TCP/IP主机-路由接口n建立子网-决定子网屏蔽字-独立的子网ID-对于每个子网的主机范围子网化C类网络n子网化定义掩码必须从左至右进行,中间不能跳位n七种可能,仅仅5种可能1000 0000=1281111 1000=2481100 0000=192 1111 1100=2521110 0000=2241111 1110=2541111 0000=240nRFC规定不允许1 bit的子网掩码n全0全1的子网不合法子网化C类网络-实例分析n192.168.100.X/255.255.255.192255.255.255.1100 0000n每子网合法主机数=2x-2(x为非掩码位)n子网数=2x-2(x为掩码位)n第一个可用子网号=256-掩码子网掩码位第一个可用主机最后可用主机子网广播192.168.100.000 000000192.168.100.6401 000000.65.126.127192.168.100.12810 000000.129.190.191192.168.100.19211 000000子网化B类网络-实例分析n14bit可用定义子网掩码n176.16.0.0/255.255.192.0255.255.1100 0000.0000 0000n每子网合法主机数=214-2=16382(14为非掩码位)n子网数=22-2=2(2为掩码位)n第一个可用子网号=256-192=64(192为掩码)子网掩码位第一个可用主机最后可用主机子网广播176.16.0.000 000000176.16.64.001 000000.64.1.127.254.127.255176.16.128.010 000000.128.1.191.254.191.255176.16.192.011 000000特殊掩码和超网n210.72.131.128/255.255.255.128#ip subnet-zeron超网192.168.0.X/255.255.0.0习题-1n1.Which protocol working at the Transport layer provides a connectionless service between hosts?A.IPB.ARPC.TCPD.UDPnAnswerD.习题-2n2.Which protocol works at the Transport layer and provides virtual circuits between hosts?A.IPB.ARPC.TCPD.UDPnAnswerC习题-3n3.Which protocol works at the Internet layer and provides a connection service between hosts?A.IPB.ARPC.TCPD.UDPnAnswerA习题-4n4.If a host broadcasts a frame that includes a source and destination hardware address,and its purpose is to assign IP addresses to itself,which protocol at the Network layer does the host use?A.RARPB.ARPAC.ICMPD.TCPE.IPXnAnswerA习题-5n5.If a router interface is congested,which protocol in the IP suite is used to tell neighbor routers?A.RARPB.ARPC.ICMPD.IPE.TCPnAnswerC习题-6n6.What is the valid host range the IP address 172.16.10.22 255.255.255.240 is a part of?A.172.16.10.20 through 172.16.10.22B.172.16.10.1 through 172.16.10.255C.172.16.10.16 through 172.16.10.23D.172.16.10.17 through 172.16.10.31E.172.16.10.17 through 172.16.10.30nAnswerE习题-7n7.What range of addresses can be used in the first octet of a Class B network address?A.1126B.1127C.128190D.128191E.129192F.192220nAnswerD习题-8n8.What range of addresses can be used in the first octet of a Class C address?A.1127B.129192C.203234D.192223nAnswerD习题-9n9.How many bytes is an Ethernet address?A.3B.4C.5D.6E.7F.8G.16nAnswerD习题-10n10.What protocol is used to find the hardware address of a local device?A.RARPB.ARPC.IPD.ICMPE.BootPnAnswerB习题-11n11.Which of the following is the broadcast address for a Class B network ID using the default subnet mask?A.172.16.10.255B.172.16.255.255C.172.255.255.255D.255.255.255.255nAnswerB习题-12nWhich class of IP address provides a maximum of only 254 host addresses per network ID?A.AB.BC.CD.DE.EnAnswerC习题-13n13.What is the broadcast address of the subnet address 10.254.255.19 255.255.255.248?A.10.254.255.23B.10.254.255.24C.10.254.255.255D.10.255.255.255nAnswerA习题-14n14.What is the broadcast address of the subnet address 172.16.99.99 255.255.192.0?A.172.16.99.255B.172.16.127.255C.172.16.255.255D.172.16.64.127nAnswerB习题-15n15.If you wanted to have 12 subnets with a Class C network ID,which subnet mask would you use?A.255.255.255.252B.255.255.255.248C.255.255.255.240D.255.255.255.255nAnswerC习题-16n16.What is the port number range that a transmitting host can use to set up a session with another host?A.11023B.1024 and aboveC.1256D.165534nAnswerB习题-17n17.Which of the following ranges are considered well-known port numbers?A.11023B.1024 and aboveC.1256D.165534nAnswerA习题-18n18.What is the broadcast address of the host subnet address 10.10.10.10 255.255.254.0?A.10.10.10.255B.10.10.11.255C.10.10.255.255D.10.255.255.255nAnswerB习题-19n19.What broadcast address will the host 192.168.210.5 255.255.255.252 use?A.192.168.210.255B.192.168.210.254C.192.168.210.7D.192.168.210.15nAnswerC习题-20n20.If you need to have a Class B network address subnetted into exactly 510 subnets,what subnet mask would you assign?A.255.255.255.252B.255.255.255.128C.255.255.0.0D.255.255.255.192nAnswerB