# 协议栈

协议栈是一组分层的通信协议，每一层为上一层提供服务，并使用下一层提供的服务，从而通过组合简单、独立规定的部分来构建完整的网络会话。最著名的例子是互联网协议族，通常以其两个奠基性协议命名为 TCP/IP，其中主机至少实现每一层的一个协议。<sup>[1](https://www.rfc-editor.org/rfc/inline-errata/rfc1122.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 互联网协议族分层 | 应用层、传输层、互联网层和链路层；RFC 1122 涵盖链路层、IP 层和传输层，其配套的 RFC 1123 涵盖应用层<sup>[1](https://www.rfc-editor.org/rfc/inline-errata/rfc1122.html)</sup> |
| OSI 对应模型 | OSI 参考模型有七层；ISO 于 1983 年 5 月批准了国际标准 7498，CCITT 批准了 X.200 建议书<sup>[2](https://www.itu.int/ITU-T/recommendations/rec.aspx?id=2820)</sup> |
| 传输层选择 | TCP 在 IP 数据报中提供可靠的、按序的字节流；UDP 以最少的协议机制提供数据报模式<sup>[3](https://www.rfc-editor.org/info/rfc9293/)</sup><sup> • </sup><sup>[4](https://www.rfc-editor.org/info/rfc768/)</sup> |
| 封装 | 每一层按降序在来自上一层的数据前面添加首部；当数据包在接收端协议栈中向上传递时，首部按相反顺序被移除<sup>[5](https://www.cisco.com/c/en/us/td/docs/ios/12_4/interface/configuration/guide/inb_tun.html)</sup> |
| 起源 | 1974 年 Cerf/Kahn 的原始设计描述了一个单一协议 TCP；后来拆分为负责寻址和转发的 IP 与负责流量控制和丢失恢复的 TCP，并增加了 UDP 以直接访问 IP<sup>[6](https://www.internetsociety.org/internet/history-internet/brief-history-internet/)</sup> |
| 部署里程碑 | ARPANET 于 1983 年 1 月 1 日从网络控制程序切换至 TCP/IP<sup>[7](https://www.tomshardware.com/networking/arpanet-standardized-tcp-ip-on-this-day-in-1983-43-year-old-standard-set-the-foundations-for-todays-internet)</sup> |
| 已知成本 | 在一个商用 TCP/IP 协议栈中，小数据包处理时间近四分之一用于内存管理，其中仅 mbuf 管理就占总处理时间的 15%<sup>[8](https://www.usenix.org/legacy/publications/library/proceedings/ana97/full_papers/rodrigues/rodrigues_html/node2.html)</sup> |

## 互联网协议族的分层

互联网体系结构定义了四个协议层。应用层是顶层，综合了 OSI 模型中表示层和应用层的功能；它分为直接为用户服务的用户协议（如 Telnet、FTP 和 SMTP）以及用于常见系统功能的支撑协议（如 SNMP、BOOTP、RARP 和[域名系统](https://www.edgepedia.org/zh/domain-name-system)）。<sup>[1](https://www.rfc-editor.org/rfc/inline-errata/rfc1122.html)</sup> 传输层为应用提供端到端通信服务；其两个主要协议是 TCP——一种面向连接的可靠服务，具有端到端可靠性、重排序和流量控制——以及 UDP——一种无连接数据报服务。<sup>[1](https://www.rfc-editor.org/rfc/inline-errata/rfc1122.html)</sup> 互联网层以 IP 为核心，提供统一的网络抽象，使得新的链路技术可以通过定义其如何承载 IP 来引入。其下的链路层处理单个网段上的传输。<sup>[1](https://www.rfc-editor.org/rfc/inline-errata/rfc1122.html)</sup>

层级的分配在协议首部本身中即可看到。TCP 提供可靠的、按序的字节流服务；应用字节流在 TCP 段中传送，每个段作为 IP 数据报发送，可靠性来自通过序列号检测丢失、通过每段校验和检测错误，并通过重传进行纠正。TCP 使用端口号来标识应用服务并在主机之间多路复用不同的流。<sup>[3](https://www.rfc-editor.org/info/rfc9293/)</sup> 相比之下，UDP 的定义是为应用程序提供一种数据报模式的分组交换通信，具有最少的协议机制，假定以 IP 为底层协议。<sup>[4](https://www.rfc-editor.org/info/rfc768/)</sup>

在互联网层，IPv6 首部包含 4 位版本号、8 位流量类别字段、20 位流标签、16 位有效载荷长度、8 位下一首部选择符、8 位跳数限制（每个转发节点递减），以及 128 位源地址和目的地址。<sup>[9](https://www.rfc-editor.org/info/rfc8200/)</sup> 下一首部字段是协议栈机制的缩影：它标识后面跟随的内容，无论是扩展首部还是上层首部（如 TCP、UDP 或 ICMPv6），接收方严格按照首部出现的顺序处理整个链。<sup>[9](https://www.rfc-editor.org/info/rfc8200/)</sup>

## 封装

**数据如何沿协议栈向下传递。** 当主机发送数据时，每一层将来自上一层的数据视为自己的有效载荷，并附加自己的首部。TCP 段被封装在 IP 数据包内，IP 数据包被封装在链路层帧（如以太网或 Wi-Fi）内；这种包裹就是协议封装，它使每一层能够独立运作，同时组合成一个完整的系统。<sup>[10](https://people.cs.rutgers.edu/~pxk/classes/417/notes/networking.html)</sup> 思科的实现指南用 OSI 术语描述了同样的过程：每一层按降序在数据前面添加首部，每个首部包含一个字段，指示紧邻上一层所封装的数据类型，从而使接收端协议栈能够按相反顺序移除首部。<sup>[5](https://www.cisco.com/c/en/us/td/docs/ios/12_4/interface/configuration/guide/inb_tun.html)</sup>

封装还产生了熟悉的单元名称：传输层数据以段为单位传输，网络层数据以数据包为单位传输，链路层数据以帧为单位传输，每一层的首部携带其对等层所需的信息，例如有效载荷是 TCP 还是 UDP，以及用于检测损坏的校验和。<sup>[11](https://w3.cs.jmu.edu/kirkpams/OpenCSF/Books/csf/html/FiveLayer.html)</sup>

## 起源与 TCP/IP 的拆分

协议栈源于 DARPA 1973 年的网络互连研究项目，该项目寻求使联网计算机能够跨多个互联分组网络透明通信的协议；由此产生的协议系统被称为 TCP/IP 协议族。<sup>[12](https://www.internetsociety.org/internet/history-internet/brief-history-internet-related-networks/)</sup> Cerf/Kahn 的原始论文描述了一个协议，称为 TCP，提供所有传输和转发服务。最初的实现仅支持虚电路，这对文件传输和远程登录有效，但分组语音的早期工作表明，某些应用应自行处理数据包丢失。这导致了重组为两个协议：简单的 IP，仅提供单个数据包的寻址和转发；以及独立的 TCP，负责流量控制和丢失数据包的恢复。UDP 是为那些不希望使用 TCP 服务、希望直接访问 IP 基本服务的应用而增加的。<sup>[6](https://www.internetsociety.org/internet/history-internet/brief-history-internet/)</sup>

这一拆分正是协议栈拥有独立的传输层和互联网层的原因。ARPANET 从 1983 年 1 月 1 日开始，从仅限 ARPANET 使用、不具备网络互连能力的网络控制程序切换至 TCP/IP，到 1984 年，美国和欧洲已有 100 多所大学和研究机构与之连接。<sup>[7](https://www.tomshardware.com/networking/arpanet-standardized-tcp-ip-on-this-day-in-1983-43-year-old-standard-set-the-foundations-for-todays-internet)</sup> TCP/IP 的主要竞争对手 OSI 协议族由委员会自上而下开发，以印刷标准的形式出售，而互联网标准则是自下而上开发的，并免费在线分发；到 1983 年 IPv4 正式采用时，TCP/IP 已有生产使用，而到 1988 年，CERN 已得出结论认为 ISO/OSI 已经出局。<sup>[13](https://www.pcgamer.com/hardware/networking/the-internet-as-we-know-it-emerged-out-of-the-protocol-wars-which-is-as-nerdy-as-it-sounds-but-also-somehow-involved-the-pentagon/)</sup> OSI 模型作为描述性词汇存续下来：其七层仍被用来讨论问题或功能所处的位置，尽管实际部署的协议栈是 TCP/IP。<sup>[13](https://www.pcgamer.com/hardware/networking/the-internet-as-we-know-it-emerged-out-of-the-protocol-wars-which-is-as-nerdy-as-it-sounds-but-also-somehow-involved-the-pentagon/)</sup>

## 实践中的分层：成本与例外

**严格分层是一个不完美的模型。** RFC 1122 直接指出了这一点：不同层中的协议以复杂的方式交互，特定功能往往涉及多个层，而实现中经常涉及对严格分层的创造性打破。<sup>[1](https://www.rfc-editor.org/rfc/inline-errata/rfc1122.html)</sup> 成本是可测量的。层间转换需要在每个边界进行数据变换，因为各层可能对数据存储使用不同的抽象，而分层限制了层间的信息传递。<sup>[8](https://www.usenix.org/legacy/publications/library/proceedings/ana97/full_papers/rodrigues/rodrigues_html/node2.html)</sup> 在上述经过测量的商用协议栈中，首部添加和移除的内存管理消耗了小数据包处理时间的近四分之一。<sup>[8](https://www.usenix.org/legacy/publications/library/proceedings/ana97/full_papers/rodrigues/rodrigues_html/node2.html)</sup> RFC 3439 得出架构性结论：增加分层往往会增加复杂性和运营成本，并引用 Tennenhouse 的论文《分层多路复用被认为有害》作为早期警示。<sup>[14](https://www.rfc-editor.org/info/rfc3439/)</sup> 在高速互连上，传统 TCP/IP 和 UDP/IP 协议栈因固有的协议开销而无法使用全部带宽；一项跨传输层到物理层的集成优化研究将 UDP/IP 提升至基于 Myrinet 的实验系统最大吞吐量的 95% 以上。<sup>[15](https://doi.org/10.1007/S11227-007-0101-0)</sup>

**QUIC 重新划定了层边界。** 经典协议栈最明显的近期例外是 QUIC，标准化于 RFC 9000，其数据包承载在 UDP 数据报中，在一个协议中同时提供机密性和完整性保护、受流量控制的流以及低延迟连接建立。<sup>[16](https://www.rfc-editor.org/info/rfc9000/)</sup> HTTP/3 随后将 HTTP 语义映射到 QUIC 之上，将流生命周期和流量控制委托给传输层，同时在每个流上使用类似 HTTP/2 的二进制帧。<sup>[17](https://www.rfc-editor.org/rfc/rfc9114.html)</sup> 因此，QUIC 将传统上分属传输层的功能（如可靠性和流量控制）以及通常置于其上的功能（如加密和会话管理）全部组合在一个 UDP 有效载荷之内。

**扩展首部在 IP 内部展现了同样的张力。** IPv6 的可选互联网层信息位于 IPv6 首部和上层首部之间的扩展首部中，接收方必须严格按顺序处理它们，而不能扫描特定类型。<sup>[9](https://www.rfc-editor.org/info/rfc8200/)</sup> 运营分析指出，节点确定上层协议类型的唯一方法是按顺序解析和处理整个首部链，这限制了中间盒对流量分类的速度，也是扩展首部在传输中受到有限处理的原因之一。<sup>[18](https://www.rfc-editor.org/rfc/rfc9098.html)</sup>

## References

1. [Braden, R., Ed. (October 1989). Requirements for Internet Hosts -- Communication Layers, RFC 1122. RFC Editor.](https://www.rfc-editor.org/rfc/inline-errata/rfc1122.html)
2. [ITU-T Recommendation X.200 (OSI Basic Reference Model), ITU-T.](https://www.itu.int/ITU-T/recommendations/rec.aspx?id=2820)
3. [Eddy, W. M., Ed. (August 2022). Transmission Control Protocol (TCP), RFC 9293. RFC Editor.](https://www.rfc-editor.org/info/rfc9293/)
4. [Postel, J. (August 1980). User Datagram Protocol, RFC 768. RFC Editor.](https://www.rfc-editor.org/info/rfc768/)
5. [Implementing Tunnels, Cisco IOS Interface Configuration Guide, Release 12.4. Cisco.](https://www.cisco.com/c/en/us/td/docs/ios/12_4/interface/configuration/guide/inb_tun.html)
6. [Leiner, B., Cerf, V., et al. A Brief History of the Internet. Internet Society.](https://www.internetsociety.org/internet/history-internet/brief-history-internet/)
7. [ARPANET standardized TCP/IP on this day in 1983. Tom's Hardware.](https://www.tomshardware.com/networking/arpanet-standardized-tcp-ip-on-this-day-in-1983-43-year-old-standard-set-the-foundations-for-todays-internet)
8. [Rodrigues et al. 2 Problems with TCP/IP. USENIX ANA '97.](https://www.usenix.org/legacy/publications/library/proceedings/ana97/full_papers/rodrigues/rodrigues_html/node2.html)
9. [Deering, S. and Hinden, R. (July 2017). Internet Protocol, Version 6 (IPv6) Specification, RFC 8200. RFC Editor.](https://www.rfc-editor.org/info/rfc8200/)
10. [Communication and Networking in Distributed Systems, Rutgers University course notes.](https://people.cs.rutgers.edu/~pxk/classes/417/notes/networking.html)
11. [The TCP/IP Internet Model, Computer Systems Fundamentals, James Madison University.](https://w3.cs.jmu.edu/kirkpams/OpenCSF/Books/csf/html/FiveLayer.html)
12. [Cerf, V. A Brief History of the Internet & Related Networks. Internet Society.](https://www.internetsociety.org/internet/history-internet/brief-history-internet-related-networks/)
13. [The internet as we know it emerged out of the Protocol Wars. PC Gamer.](https://www.pcgamer.com/hardware/networking/the-internet-as-we-know-it-emerged-out-of-the-protocol-wars-which-is-as-nerdy-as-it-sounds-but-also-somehow-involved-the-pentagon/)
14. [Bush, R. and Meyer, D. (December 2002). Some Internet Architectural Guidelines and Philosophy, RFC 3439. RFC Editor.](https://www.rfc-editor.org/info/rfc3439/)
15. [Impact of protocol overheads on network throughput over high-speed interconnects. The Journal of Supercomputing.](https://doi.org/10.1007/S11227-007-0101-0)
16. [Iyengar, J., Ed. and Thomson, M., Ed. (May 2021). QUIC: A UDP-Based Multiplexed and Secure Transport, RFC 9000. RFC Editor.](https://www.rfc-editor.org/info/rfc9000/)
17. [Bishop, M., Ed. (June 2022). HTTP/3, RFC 9114. RFC Editor.](https://www.rfc-editor.org/rfc/rfc9114.html)
18. [Ding, X. et al. (2021). Operational Implications of IPv6 Packets with Extension Headers, RFC 9098. RFC Editor.](https://www.rfc-editor.org/rfc/rfc9098.html)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Networking fundamentals and architecture › Internet protocol suite

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/protocol-stack

English original: https://www.edgepedia.org/protocol-stack
