TCPIP协议.ppt
第四章第四章 TCP/IP协议协议中国中国ITIT认证实验室认证实验室第四章第四章 TCP/IP协议协议nTCP/IP协议概述协议概述nTCP/IP协议模型协议模型n应用层协议应用层协议n传输层协议传输层协议n网间层协议网间层协议nIP地址地址n子网划分子网划分TCP/IPn一组通信协议(传输协议)nTransmission Control Protocol/Internet ProtocolnTCP/IP协议的产生nARPANETTCP/IP协议协议nRFC(Request For Comments)n关于Internet和ARPANET的技术文档n协议,概念的标准nWWW.IETF.ORGTCP/IP协议模型协议模型TCP/IP模型 OSI模型ApplicationTransportInternetHost to NetworkApplicationPresentationSessionTransportNetworkData linkPhysicalData FlowUDPTCPFTPHTTPIPICMP IGMPARPEthernetATMUDPTCPFTPHTTPIPICMP IGMPARPEthernetATMDataApplicationApplicationDataFTPHTTPTransportTransportDataUDPTCPFTPHTTPInternetInternetDataUDPTCPIPICMP IGMPARPPreamblePreambleDataCRCCRCIPICMP IGMPARPEthernetATMDataEthernetATMDataEthernetATMDataIPICMP IGMPARPEthernetATMDataUDPTCPIPICMP IGMPARPDataUDPTCPFTPHTTPPreamblePreambleInternetTransportApplicationDataCRCCRCFTPHTTPTCP/IP协议集TCP/IP体系结构体系结构ApplicationTransportInternetHost to NetworkTCP/IP 协议模型协议模型ApplicationTransportInternetHost to NetworkTCP/IP 应用层应用层HTTP/HTTPSFTPSMTPPOP3TelnetSNMPNNTPApplicationTransportInternetHost to NetworkTCP/IP 传输层传输层TCPTCPUDPUDPApplicationTransportInternetHost to NetworkTCPn面向连接的协议面向连接的协议Connection-Orientedn可以保证数据传输的正确性可以保证数据传输的正确性n数据传输过程数据传输过程建立连接建立连接发送数据和接收数据发送数据和接收数据释放连接释放连接nHTTP,FTP等等UDPn非面向连接的协议非面向连接的协议Connectionlessn不能保证数据传输的正确性,靠上层保证不能保证数据传输的正确性,靠上层保证n无需建立连接,减少了通讯的开销无需建立连接,减少了通讯的开销n可发送广播帧可发送广播帧nDNS寻址寻址,SNMP等等TCP帧结构帧结构 0 1 2 3 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+|Source Port|Destination Port|Source Port|Destination Port|+-+-+-+-+|Sequence Number|Sequence Number|+-+-+|Acknowledgment Number|Acknowledgment Number|+-+-+-+-+-+-+|Data|U|A|P|R|S|F|Data|U|A|P|R|S|F|Offset|Reserved|R|C|S|S|Y|I|Window|Offset|Reserved|R|C|S|S|Y|I|Window|G|K|H|T|N|N|G|K|H|T|N|N|+-+-+-+-+-+-+|Checksum|Urgent Pointer|Checksum|Urgent Pointer|+-+-+-+-+-+-+|Options|Padding|Options|Padding|+-+-+-+-+|data|data|+-+-+TCP帧结构帧结构 0 1 2 3 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+|Source Port|Destination Port|Source Port|Destination Port|+-+-+-+-+|Sequence Number|Sequence Number|+-+-+|Acknowledgment Number|Acknowledgment Number|+-+-+-+-+-+-+|Data|U|A|P|R|S|F|Data|U|A|P|R|S|F|Offset|Reserved|R|C|S|S|Y|I|Window|Offset|Reserved|R|C|S|S|Y|I|Window|G|K|H|T|N|N|G|K|H|T|N|N|+-+-+-+-+-+-+|Checksum|Urgent Pointer|Checksum|Urgent Pointer|+-+-+-+-+-+-+|Options|Padding|Options|Padding|+-+-+-+-+|data|data|+-+-+包丢失避免包丢失避免SenderReceiverSend1ACK 2Send2Send2ACK 2SYN 1SYN 2SYN 2ACK 3第二个包没收到建立连接建立连接n3-Way Handshake for Connection Synchronization n交换初始序列交换初始序列号号ISNA-B SYN my sequence number is 1A-B ACK your sequence number is 1AB ACK your sequence number is 130 用窗口进行流控制用窗口进行流控制Window size=1SenderSend1Send2Receiv1ACK2ReceiverReceiv1ACK3ACK4Window size=3Send1Send2Receive1Receive2Send3Receive3Receive4Send4SenderReceiver用窗口进行流控制用窗口进行流控制SenderSenderReceiverReceiverBuffer fullBuffer full ProgressProgress SegmentsSegmentsBuffer OKBuffer OKTransmitTransmitNot ReadyNot ReadyReadyReadyUDP帧结构帧结构 0 1 2 3 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+|Source Port|Destination Port|Source Port|Destination Port|+-+-+-+-+|Length|Checksum|Length|Checksum|+-+-+|data octets.|data octets.+-.+-.TCP/IP的传输层的传输层n端口号端口号Portn标识应用层某种具体的服务标识应用层某种具体的服务n16 bitn0-65535n0-1023保留保留TCP/IP的传输层的传输层n端口号端口号Portn标识某种具体的服务标识某种具体的服务n16 bitn0-1023保留保留n0-65535n套接套接字字 Socketn标识应用程序间的连接标识应用程序间的连接nTCP or UDP+IP+Port 常用的常用的TCP端口号端口号n端口号端口号n20 FTP server(data channel);n21 FTP server(control channel);n23 Telnet server;n25 SMTP server;n80 Web server(HTTP);n110 POP3 server;n139 NetBIOS session service常用的常用的UDP端口号端口号n端口号端口号n53 DNS name queries;n69 Trivial File Transfer Protocol(TFTP);n137 NetBIOS name service;n138 NetBIOS Datagram service;n161 Simple Network Management Protocol(SNMP);n520 Routing Information Protocol(RIP)TCP和和UDP的比较的比较n服务性质服务性质n传输可靠性传输可靠性n传输开销,速度传输开销,速度n传输类型传输类型n是否广播是否广播Internet层ApplicationTransportInternetHost to NetworkIPIP Internet ProtocolICMPICMP Internet Control Message ProtocolIGMPIGMP Internet Group Management ProtocolARPARP Address Resolution ProtocolRARPRARP Reverse ARPARPnAddress Resolution Protocoln地址解析协议ARPnIP-MAC解析解析n广播广播nARP CachenARP a n在路由器上在路由器上n察看察看ARP Cache的命令的命令n清除清除ARP CacheRARPnReverse Address Resolution Protocoln反地址解析协议nMAC-IP获得 n广播nRARP的应用场景的应用场景ICMPnInternet Control Messages Protocoln网间消息控制协议ICMPn作用作用n让发送者知道数据包传输过程中出现的问题让发送者知道数据包传输过程中出现的问题n必须被所有必须被所有TCP/IP的主机实现的主机实现 n是否用是否用IP协议传输?协议传输?n应用应用nPingEcho,Echo Replyn网络不可达网络不可达 Destination Unreachable IP协议协议nInternet ProtocolIP帧格式帧格式 0 1 2 3 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+|Version|IHL|Type of Service|Total Length|Version|IHL|Type of Service|Total Length|+-+-+-+-+-+-+-+-+-+-+|Identification|Flags|Fragment Offset|Identification|Flags|Fragment Offset|+-+-+-+-+-+-+-+-+|Time to Live|Protocol|Header Checksum|Time to Live|Protocol|Header Checksum|+-+-+-+-+|Source Address|Source Address|+-+-+|Destination Address|Destination Address|+-+-+-+-+|Options|Padding|Options|Padding|+-+-+-+-+IP帧格式帧格式 0 1 2 3 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+|Version|IHL|Type of Service|Total Length|Version|IHL|Type of Service|Total Length|+-+-+-+-+-+-+-+-+-+-+|Identification|Flags|Fragment Offset|Identification|Flags|Fragment Offset|+-+-+-+-+-+-+-+-+|Time to Live|Protocol|Header Checksum|Time to Live|Protocol|Header Checksum|+-+-+-+-+|Source Address|Source Address|+-+-+|Destination Address|Destination Address|+-+-+-+-+|Options|Padding|Options|Padding|+-+-+-+-+IP地址地址n逻辑地址,用于标识网络中的主机逻辑地址,用于标识网络中的主机IP地址地址n32位二进制数位二进制数n点分点分4组组,每组每组8位位n每每8位一个字节(位一个字节(byte)169.254.0.110101001.11111110.00000000.00000001Converting to Binary Format8 BitsDecimal Value 255111111111286432168421Binary Notation(Base 2)2726252423222120Example110110011*1281*640*321*161*80*40*21*11286432168421128640168001217IP 地址规定规定nNet ID 和和Host IDn二进制位不能全二进制位不能全0 全全1IP10.0.0.1Net ID 10.0.0.0本地广播本地广播 10.255.255.255子网广播子网广播 255.255.255.255IP Address ClasseswxyzClass ANetwork IDNetwork IDHost IDClass BNetwork IDNetwork IDHost IDClass CNetwork IDNetwork IDHost IDIP 分类 Class A 0 xxxxxxx.x.y.z 1 126.x.y.zClass B 10 xxxxxx.x.y.z128 191.x.y.zClass C 110 xxxxx.x.y.z 192 223.x.y.zClass D 1110 xxxx.x.y.z 224 239.x.y.zClass E 11110 xxx.x.y.z 240 Class A0 xxxxxxx.00000000.00000000.0000000000000000.00000000.0000000001111110.1.0.0.0 126.0.0.0网络号范围:网络号范围:00000001.xxxxxxxx.xxxxxxxx.xxxxxxxx00000001.00000001.主机范围主机范围:1.0.0.0 1.0.0.1 1.255.255.25400000001.00000000.00000000.0000000000000000.00000000.0000000111111111.11111111.11111110Class B10 xxxxxx.xxxxxxxx.00000000.00000000.00000000.0000000010111111.11111111128.0.0.0 191.255.0.0网络号范围:网络号范围:10000000.00000001.xxxxxxxx.xxxxxxxx10000000.00000000.10000000.00000000.主机范围主机范围:128.0.0.0 128.0.0.1 128.0.255.25410000000.00000000.00000000.0000000000000000.0000000111111111.11111110Class C110 xxxxx.xxxxxxxx.xxxxxxxx.00000000.0000000011011111.11111111.11111111192.0.0.0 223.255.255.0网络号范围:网络号范围:11000000.00000000.00000000.xxxxxxxx11000000.00000000.00000000.11000000.00000000.00000000.主机范围主机范围:192.0.0.0 192.0.0.1 192.0.0.25411000000.00000000.00000000.000000000000000111111110IP网络数网络数主机数主机数A类类27-2224 2B类类214 216 2C类类22128 2D类类组组播播E类类保留保留特殊特殊的的IP地址地址n0.0.0.0n255.255.255.255n127.0.0.1合法的主机合法的主机IP?n0.0.0.0n1.1.1.1n12.0.1.0n12.0.1.255n127.0.0.4n131.107.0.255n222.0.0.255n225.0.0.1Subnet Maskn子网掩码Subnet MasknIP:192.168.1.1nSubnet Mask:255.255.255.0nNet ID:192.168.1.0n11000000.10101000.00000001.00000001n11111111.11111111.11111111.00000000n11000000.10101000.00000001.00000000子网掩码的作用子网掩码的作用n区分区分Network ID和和Host IDn确定目标主机所在的网络确定目标主机所在的网络n“与与”运算运算 Subnet MasknDefault Subnet MasknClass A-255.0.0.0nClass B-255.255.0.0nClass C-255.255.255.0确定目标网络的过程确定目标网络的过程nTCP/IP初始化时初始化时n本机本机IP“与与”本机子网掩码本机子网掩码=本网络号本网络号n发送数据时发送数据时n目标目标IP“与与”本机子网掩码本机子网掩码=目标网络号目标网络号n目标网络号和本网络号比较目标网络号和本网络号比较n相同相同,说明在本网络说明在本网络n不相同不相同,数据包发往数据包发往 Gateway数据帧格式数据帧格式n相同n不相同源源IP目标目标IP源源mac目标目标macDATAFCS源源IP目标目标IP源源mac网关网关macDATAFCS子网掩码表示法子网掩码表示法n一种新的子网掩码的表示法一种新的子网掩码的表示法n192.168.0.1 255.255.255.0n192.168.0.1/24CIDR表示法表示法nClassless Inter-Domain Routing(CIDR)n不再遵从不再遵从A,B,C类地址的缺省子网掩码类地址的缺省子网掩码n10.0.0.0/16n128.64.1.0/24n192.168.1.64/26子网划分子网划分子网划分子网划分nSubnetting IP子网子网(Subnet)n不同访问技术的网络处于不同子不同访问技术的网络处于不同子网网n减少网络减少网络n拥塞拥塞n广播广播借位原则借位原则n从从Host ID高位起划分子网高位起划分子网n借位连续借位连续n最少要借最少要借2个二进制位个二进制位n子网子网ID不能全为不能全为0n子网子网ID不能全为不能全为1Subnet ID.xxxxxxxx.xxxxxxxx.00.01.10.11000000.00000000000000.00000000131.107.64.0131.107.128.011111111.11111111.11000000.0000000010000011.01101011.131.107Subnet Mask:255.255.192.0Subnet ID10000011.01101011.01000000.00000000000000.00000001111111.1111111010000011.01101011.0110000011.01101011.01主机范围:主机范围:131.107.64.1 131.107.127.254子网子网1:131.107.64.0 IP:11111111.11111111.11000000.00000000Mask:255.255.192.0Subnet ID10000011.01101011.10000000.00000000000000.00000001111111.1111111010000011.01101011.1010000011.01101011.10主机范围:主机范围:131.107.128.1 131.107.191.254子网子网2:131.107.128.0 IP:11111111.11111111.11000000.00000000Mask:255.255.192.0划分子网试题划分子网试题n128.0.0.0/16n划分5个子网 子网:主机范围:n192.168.1.0/24n划分3个子网 子网:主机范围:路由的过程路由的过程n连接两以太网的路由器的路由过程连接两以太网的路由器的路由过程1.1.1.1/8MAC21.1.1.2/8MAC13.3.3.2/8MAC63.3.3.1/8MAC5发送数据包的主机填写的包头发送数据包的主机填写的包头S IPD IPDMac SMac1.1.1.2 3.3.3.2Mac2Mac1DataIP包头包头Ethernet包包头头路由的过程路由的过程n连接两以太网的路由器的路由过程连接两以太网的路由器的路由过程1.1.1.1/8MAC21.1.1.2/8MAC13.3.3.2/8MAC63.3.3.1/8MAC5发送数据包的主机填写的包头发送数据包的主机填写的包头路由器修改后的包头路由器修改后的包头S IPD IPDMac SMacS IPD IPDMac SMac1.1.1.2 3.3.3.2Mac2Mac1Data1.1.1.2 3.3.3.2Mac6Mac5DataIP包头包头Ethernet包包头头IP包头包头Ethernet包包头头路由的过程路由的过程发送数据包的主机填写的包头发送数据包的主机填写的包头S IPD IPDMacSMac1.1.1.2 3.3.3.2Mac2 Mac1DataIP包头包头Ethernet包头包头3.3.3.2/8MAC61.1.1.1/8MAC21.1.1.2/8MAC13.3.3.1/8MAC52.2.2.1/82.2.2.2/8PPP路由的过程路由的过程1.1.1.2 3.3.3.2DataRTA修改后的包头修改后的包头IP包头包头PPP包头包头S IPD IP发送数据包的主机填写的包头发送数据包的主机填写的包头S IPD IPDMacSMac1.1.1.2 3.3.3.2Mac2 Mac1DataIP包头包头Ethernet包头包头3.3.3.2/8MAC61.1.1.1/8MAC21.1.1.2/8MAC13.3.3.1/8MAC52.2.2.1/82.2.2.2/8PPP路由的过程路由的过程1.1.1.2 3.3.3.2DataRTA修改后的包头修改后的包头IP包头包头PPP包头包头S IPD IP发送数据包的主机填写的包头发送数据包的主机填写的包头S IPD IPDMacSMac1.1.1.2 3.3.3.2Mac2 Mac1DataIP包头包头Ethernet包头包头RTB修改后的包头修改后的包头S IPD IPDMacSMac1.1.1.2 3.3.3.2Mac6 Mac5DataIP包头包头Ethernet包头包头3.3.3.2/8MAC61.1.1.1/8MAC21.1.1.2/8MAC13.3.3.1/8MAC52.2.2.1/82.2.2.2/8PPP私有私有IP地址地址nPublic IP和Private IPnInterNIC保留的Private IPn10.0.0.0255.0.0.0n172.16.0.0255.240.0.0n192.168.0.0 255.255.0.0地址耗尽问题地址耗尽问题IPV4IPIP地址耗尽地址耗尽路由表的增长路由表的增长Subneting 子网划分子网划分VLSM 变长子网掩码变长子网掩码CIDR 无类别域间路由无类别域间路由Private IP 私有私有IPIPV6 最终方案最终方案