主机参考:VPS测评参考推荐/专注分享VPS服务器优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情! |
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作 |
TCP/IP网络协议栈分为应用层(Application)、传输层( Transport)、网络层(Network)和链路层(Link)四层。
1.数据链路层
实现了网卡接口的网络驱动程序。
协议:ARP协议和RARP协议
ARP协议:目标机器IP地址—(ARP协议)→
目标机器MAC地址→
目标机器
RARP协议:(无盘工作站)MAC地址—(RARP协议)→IP地址
2.网络层
实现数据包的选路和转发。负责点对点(point to point)的传输(“点”:主机或路由器)。网络层向上层协议隐藏了网络拓扑连接的细节,在传输层和应用层看来通信双方是直接相连的。
协议:IP协议,ICMP协议。
IP协议根据数据包的目的IP地址来决定如何投递它。如果数据包不能直接发给目的主机,那么IP协议就为它寻找合适的下一跳路由器,并将数据包交付给该路由器来转发。IP协议使用逐跳的方式确定通信路径。
ICMP协议是IP协议重要的补充,用于检测网络连接。
3.传输层
传输层为两台主机上的应用程序提供端到端(end to end)的通信。传输层只关心通信的起始端和目的端,而不在乎数据包的中转过程。
协议:TCP协议、UDP协议、SCTP协议
TCP协议
为应用层提供可靠的、面向连接和基于流(stream)的服务;
TCP协议使用超时重传、数据确定等方式确认数据报被正确地发送至目的端
使用TCP协议通信的双方必须先建立TCP连接,并在内核中为该连接维持一些必要的数据结构。通信结束时,双方必须关闭连接以释放这些内核数据。
TCP协议是基于流的,数据没有边界(长度)限制。发送端可以逐个字节地向数据流中写入数据,接收端也可以逐个字节将其读出
UDP协议
为应用层提供不可靠、无连接、基于数据报的服务。
UPD协议无法保证数据从发送端正确地传到目的端。使用UDP协议的应用程序通常要自己处理数据确认、超时重传等逻辑。
UDP协议是无连接的,因此应用程序每次发送数据都要明确指定接收端的地址(IP地址等信息)。
每个UPD数据报都有一个长度,接收端必须以该长度为最小单位将其所有内容一次性读出,否则数据将被截断。
TCP是一种面向连接的,开放的协议,有点像打电话,双方拿起电话互通身份后就建立了连接,然后说话就行了,这边说话那边保证听得到,并且是按说话的顺序听到的,说完话挂机断开连接。也就是说TCP传输的双方需要首先建立连接,之后由TCP协议保证数据收发的可靠性,丢失的数据包自动重发,上层应用程序收到的总是可靠的数据流,通讯之后关闭连接。
UDP协议不面向连接,也不保证可靠性,有点像寄信,写好信放进邮筒里,既不能保证信件在邮递过程中不会丢失, 也不能保证信件是按顺序寄到目的地的。使用UDP协议的应用程序需要自己完成丢包重发、消息排序等工作。
SCTP协议是为了在因特网上传输电话信号而设计的。
4.应用层
负责处理应用程序的逻辑
应用层协议(或程序)可能跳过传输层直接使用网络层提供的服务,比如ping程序和OSPF协议。
应用层协议(或程序)通常既可以使用TCP服务,又可以使用UDP服务,比如DNS协议。
TCP/IP数据包的封装
以太网帧使用6字节(48位)的目的物理地址和6字节(48位)的源物理地址(MAC地址)来表示通信的双方。
协议类型字段有三种值,分别对应IP、ARP、RAPP。
以太网帧的数据长度规定最小46字节,最大1500字节,ARP和RARP数据包的长度不够46字节,要在后面补充填位。最大值1500称为以太网最大传输单元(MTU),不同的网络类型有不同的MTU,如果一个数据包从以太网路由到拨号链路上,数据包的长度大于拨号链路的MTU,则需要对数据包进行分片(fragment)传输。
帧末尾的4字节CRC字段对帧的其他部分提供循环冗余校验。
帧才是最终在网络上传送的字节序列。
TCP/IP数据包跨路由器通讯过程
数据链路层(驱动程序)封装了物理网络的电气细节;
网络层封装了网络连接的细节;
传输层则为应用程序封装了一条端对端的逻辑通信链路,它负责数据的收发、链路的超时重连等。
分用
当帧到达目的主机时 ,将沿着协议栈自底向上依次传递。各层协议依次处理帧中本层负责的头部数据,以获取所需的信息,并将处理后的帧交给目的应用程序。这个过程称为分用( demultiplexing)。
分用是依靠头部信息中的类型字段实现的。
整理自《Linux高性能服务器编程》第1章,《Linux C一站式学习》第36章
TCP / IP network protocol stack is divided into application layer, transport layer, network layer and link layer.
1. Data link layer
The network driver of network card interface is implemented.
Protocol: ARP protocol and RARP protocol
ARP protocol: target machine IP address - (ARP Protocol) →
MAC address of target machine →
Target machine
RARP protocol: (diskless workstation) MAC address - (RARP protocol) → IP address
2. network layer
Realize packet routing and forwarding. Responsible for point-to-point transmission ("point": host or router). The network layer hides the details of the network topology connection from the upper layer protocol. In the view of the transmission layer and the application layer, the communication parties are directly connected.
Protocol: IP protocol, ICMP Protocol.
IP protocol determines how to deliver a packet according to its destination IP address. If the packet can not be sent directly to the destination host, the IP protocol will find a suitable next hop router for it, and deliver the packet to the router for forwarding. IP protocol uses hop by hop method to determine the communication path.
ICMP Protocol is an important supplement of IP protocol, which is used to detect network connection.
3. transport layer
The transport layer provides end-to-end communication for applications on both hosts. The transport layer only cares about the start and destination of communication, but not the transfer process of packets.
Protocol: TCP, UDP, SCTP
TCP protocol
Provide reliable, connection oriented and stream based services for the application layer;
TCP protocol uses time-out retransmission, data determination and other methods to confirm that the datagram is correctly sent to the destination
The two sides who use TCP protocol to communicate must first establish a TCP connection and maintain some necessary data structures for the connection in the kernel. At the end of the communication, both parties must close the connection to release the kernel data.
The TCP protocol is stream based, and the data has no boundary (length) limit. The sender can write data to the data stream byte by byte, and the receiver can read it out byte by byte
UDP protocol
Provide unreliable, connectionless, datagram based services for the application layer.
UPD protocol can not guarantee the data from the sender to the destination correctly. Applications using UDP protocol usually need to process data confirmation, timeout retransmission and other logic by themselves.
UDP protocol is connectionless, so every time the application sends data, it must specify the address of the receiver (IP address and other information).
Each UPD datagram has a length, and the receiver must read all its contents at one time in the minimum unit of the length, otherwise the data will be truncated.
TCP is a connection oriented and open protocol. It's a bit like making a phone call. After both parties pick up the phone to exchange identities, they establish a connection, and then talk. This way, you can hear it, and you can hear it in the order of speaking. When you finish speaking, hang up and disconnect. In other words, the two sides of TCP transmission need to establish a connection first, and then the TCP protocol ensures the reliability of data receiving and sending. The lost data packets are automatically retransmitted. The upper application receives always reliable data flow, and the connection is closed after communication.
UDP protocol is not connection oriented and does not guarantee reliability. It's a bit like sending a letter. Writing a letter and putting it in the mailbox can neither guarantee that the letter will not be lost in the process of mailing nor that the letter will be sent to the destination in order. Applications using UDP protocol need to complete packet loss retransmission, message sorting, etc.
SCTP is designed to transmit telephone signals over the Internet.
4. application layer
Responsible for handling the logic of the application
Application layer protocol (or program) may skip the transport layer and directly use the services provided by the network layer, such as ping program and OSPF protocol.
Application layer protocols (or programs) can usually use both TCP services and UDP services, such as DNS protocol.
Encapsulation of TCP / IP packets
Ethernet frames use a 6-byte (48 bit) destination physical address and a 6-byte (48 bit) source physical address (MAC address) to represent both sides of the communication.
There are three values in the protocol type field, corresponding to IP, ARP and Rapp respectively.
The data length of Ethernet frame specifies the minimum 46 bytes and the maximum 1500 bytes. The length of ARP and RARP packets is not enough 46 bytes, so it is necessary to fill in the following bits. The maximum value 1500 is called the Ethernet maximum transmission unit (MTU). Different network types have different MTUs. If a packet is routed from Ethernet to the dial-up link, and the length of the packet is larger than the MTU of the dial-up link, the packet needs to be transmitted in segments.
The 4-byte CRC field at the end of the frame provides cyclic redundancy checking for the rest of the frame.
Frame is the last byte sequence transmitted over the network.
Communication process of TCP / IP packets across routers
The data link layer (driver) encapsulates the electrical details of the physical network;
The network layer encapsulates the details of network connection;
The transport layer encapsulates an end-to-end logical communication link for the application program, which is responsible for data sending and receiving, link timeout reconnection, etc.
Separate use
When the frame reaches the destination host, it will pass from bottom to top along the protocol stack. Each layer protocol processes the header data in the frame in order to obtain the required information, and hands the processed frame to the target application program. This process is called de multiplexing.
The allocation is realized by the type field in the header information.
Organized from Chapter 1 of Linux high performance server programming, chapter 36 of Linux C one stop learning
--------------------------------------------------------------
主机参考,收集国内外VPS,VPS测评,主机测评,云服务器,虚拟主机,独立服务器,国内外服务器,高性价比建站主机相关优惠信息@zhujicankao.com
详细介绍和测评国外VPS主机,云服务器,国外服务器,国外主机的相关优惠信息,商家背景,网络带宽等等,也是目前国内最好的主机云服务器VPS参考测评资讯优惠信息分享平台
这几篇文章你可能也喜欢:
- 冲浪云怎么样? SurferCloud香港轻量级云VPS评测分享
- 冲浪云怎么样? SurferCloud 洛杉矶轻量级云 VPS 评论分享
- 冲浪云怎么样? 评测分享越南胡志明市SurferCloud轻量级云VPS,匿名云服务器,支持U支付
- lisahost台湾hinet动态IP VPS评测,台湾双ISP原生住宅,顶级IP!
- 六六云英国家庭宽带IP/双ISP/住宅IP VPS,英国原生IP,解锁奈飞YouTube抖音、chatgp等流媒体评测
本文由主机参考刊发,转载请注明:TCP/IP协议族 https://zhujicankao.com/12327.html
评论前必须登录!
注册