# 磁力链接 URI 方案

磁力链接（magnet URI）是通过密码学哈希——通常是比特洪流的 infohash——而非服务器上文件的位置来标识内容的链接。客户端打开磁力链接后，可以加入相应的对等网络群（swarm），从其他对等节点获取文件的元数据和数据，全程无需先下载 .torrent 文件。<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 携带内容 | 内容哈希（比特洪流 infohash），外加可选的显示名称、追踪器 URL、对等节点地址和网页种子 URL；`xt` 是唯一必填参数<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup> |
| v1 哈希 | SHA-1 infohash，20 字节，写作 40 个十六进制字符或 32 个 base32 字符<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup><sup> • </sup><sup>[2](https://docs.rs/rbit/latest/rbit/metainfo/struct.MagnetLink.html)</sup> |
| v2 哈希 | SHA-256 infohash，32 字节，写作 64 个十六进制字符，带多重哈希前缀 `urn:btmh:1220`<sup>[2](https://docs.rs/rbit/latest/rbit/metainfo/struct.MagnetLink.html)</sup> |
| 解析路径 | 通过 DHT 查找对等节点，再进行 BEP 9 元数据交换<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup><sup> • </sup><sup>[3](https://stackoverflow.com/questions/3844502/how-do-bittorrent-magnet-links-work)</sup> |
| DHT 规模 | 在剑桥大学一项长期测量中，Mainline DHT 每日维持 1500 万至 2700 万个节点<sup>[4](https://www.cl.cam.ac.uk/~lw525/MLDHT/)</sup> |
| 标准化 | 2002 年的社区提案，后由比特洪流增强提案第 5、9、19 号正式规定<sup>[5](http://gojomo.blogspot.com/2002/06/magnet-uri-proposal.html)</sup><sup> • </sup><sup>[6](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)</sup> |
| 主要安全警示 | 磁力链接本身不具备任何完整性、真实性或保密性机制；连接对等节点会暴露你的 IP 地址<sup>[6](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)</sup><sup> • </sup><sup>[7](https://www.neatnettricks.com/what-are-magnet-links-how-to-use-them-complete-guide/)</sup> |

## 结构与参数

磁力链接是一个 `magnet:` 方案的 URI，查询字符串由参数构成。v1 的规范形式为 `magnet:?xt=urn:btih:<info-hash>&dn=<name>&tr=<tracker-url>&x.pe=<peer-address>`；v2 形式则将 `urn:btih:` 替换为 `urn:btmh:<tagged-info-hash>`。<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup> 各参数如下：

- **xt**（exact topic，精确主题）：内容哈希，唯一必填参数。对于 v1 种子，它是 `urn:btih:` 后接 SHA-1 infohash，以十六进制编码为 40 个字符；为兼容已在流通的链接，客户端也应接受 32 字符的 base32 编码。<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup> 对于 v2 种子，它是 `urn:btmh:` 后接 64 个十六进制字符的 SHA-256 摘要，并带两字节多重哈希前缀 `1220`，用以标识算法（SHA-256）和摘要长度（32 字节）。<sup>[2](https://docs.rs/rbit/latest/rbit/metainfo/struct.MagnetLink.html)</sup>
- **dn**（display name，显示名称）：经 URL 编码的名称，客户端可在等待元数据期间显示。<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup>
- **tr**（tracker，追踪器）：追踪器 URL，多追踪器种子可重复此参数。<sup>[2](https://docs.rs/rbit/latest/rbit/metainfo/struct.MagnetLink.html)</sup>
- **xl**（exact length，精确长度）：总大小（字节）；例如 qBittorrent 在创建磁力链接时会添加此参数。<sup>[8](https://www.qbittorrent.org/news)</sup>
- **as**、**xs**、**ws**（alternative sources，替代源）：由 BEP 9 的网页种子扩展添加，指向元数据或数据本身的替代来源，例如网页种子 URL。<sup>[6](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)</sup>
- **x.pe**（peer，对等节点）：直接的对等节点地址，可重复，能够在两个客户端之间发起直接的元数据传输，同时减少对外部对等节点来源的依赖。<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup>

该约定还允许通过在参数名后追加 `.1`、`.2` 等来携带多个同类型参数。<sup>[9](https://superuser.com/questions/199970/whats-the-difference-between-a-torrent-file-and-a-magnet-link)</sup> 各实现在细节上有所不同：某个 Rust 库按 xt（v1）、xt（v2）、dn、xl、tr 的顺序输出参数，并根据标志位将 v1 哈希编码为 base32 或十六进制，而 v2 哈希始终为十六进制。<sup>[10](https://docs.rs/bitors/latest/bitors/magnet/struct.MagnetLink.html)</sup> 网页种子参数是比特洪流特有的，并非协议无关，通用磁力链接草案可能永远不会正式支持它们。<sup>[6](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)</sup>

## 解析工作原理

仅含 infohash 的磁力链接不描述任何服务器和文件路径，因此客户端必须自行找到群。主要机制是比特洪流 DHT——一种基于 Kademlia、在 UDP 上实现的“分布式松散哈希表”，其中每个对等节点都为无追踪器种子充当追踪器。<sup>[11](https://bittorrent.org/beps/bep_0005.html)</sup> 节点 ID 取自与比特洪流 infohash 相同的 160 位空间，距离用 XOR 度量，与 Kademlia 的原始设计一致；后者为每个节点和对象从 160 位键空间分配标识符，并定义了 PING、STORE、FIND_NODE 和 FIND_VALUE 操作。<sup>[11](https://bittorrent.org/beps/bep_0005.html)</sup><sup> • </sup><sup>[12](https://www.cs.cornell.edu/people/egs/714-spring05/kademlia.pdf)</sup>

**查找过程。** 客户端迭代查询 ID 最接近目标 infohash 的节点，直到找不到更近的节点为止。<sup>[3](https://stackoverflow.com/questions/3844502/how-do-bittorrent-magnet-links-work)</sup><sup> • </sup><sup>[11](https://bittorrent.org/beps/bep_0005.html)</sup> 在 Mainline DHT 中，Kademlia 的对象 ID 即种子 infohash，存储的值是各种子群中对等节点的列表。<sup>[13](https://www.diva-portal.org/smash/get/diva2:398948/FULLTEXT01.pdf)</sup> Azureus 利用其 DHT 在集中式协调器不可用时提供对等节点备份来源，DHT 也使得无需指定任何中央协调器即可分发。<sup>[14](https://conferences.sigcomm.org/imc/2007/papers/imc150.pdf)</sup>

**元数据交换。** 客户端一旦找到对等节点，BEP 9 便允许从它们处下载种子的元数据，即 info 字典，因此无需 .torrent 文件；每个对等节点必须验证其发送的任何元数据分片能通过 info-hash 校验。<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup> Transmission 的开发追踪器描述了同样的流程：先通过 DHT 定位对等节点，再用 BEP 9 下载 info 字典。<sup>[15](https://trac.transmissionbt.com/ticket/2096)</sup>

实测转化率显示了实际限制。在一次为期 10 天的爬取中，从 57,065,499 个唯一对等节点收集了 10,149,649 条磁力链接和超过 264,846,482 次 get_peers 请求，磁力链接转种子的成功率通过种子存储服务为 46.9%，通过扩展协议为 22.7%。<sup>[16](https://doi.org/10.1109/dsc.2016.106)</sup> NAT 和防火墙是失败的主要原因，影响了 32.5% 的对等节点。<sup>[16](https://doi.org/10.1109/dsc.2016.106)</sup> 比特洪流 v2 降低了启动开销：v2 的 info 字典更小，因此在实际传输开始前需下载的字节更少。<sup>[17](https://blog.libtorrent.org/2020/09/bittorrent-v2/)</sup>

## 哈希与比特洪流版本

v1 infohash 是种子 info 字典的 SHA-1 哈希，20 字节，写作 40 个十六进制或 32 个 base32 字符。<sup>[3](https://stackoverflow.com/questions/3844502/how-do-bittorrent-magnet-links-work)</sup><sup> • </sup><sup>[2](https://docs.rs/rbit/latest/rbit/metainfo/struct.MagnetLink.html)</sup> 比特洪流 v2 将分片哈希函数改为 SHA-256，使分片哈希为 32 字节而非 20 字节；v2 种子中的每个文件构成一棵[默克尔树](https://www.edgepedia.org/zh/merkle-tree)，其分片哈希是该分片中 16 KiB 块的 SHA-256 默克尔根。<sup>[17](https://blog.libtorrent.org/2020/09/bittorrent-v2/)</sup><sup> • </sup><sup>[18](https://www.libtorrent.org/upgrade_to_2.0-ref.html)</sup>

**混合种子。** 由于 v1 和 v2 客户端本来无法共享群，混合格式携带两个 info-hash——一个 SHA-1、一个 SHA-256——并同时参与 v1 和 v2 两个群。<sup>[17](https://blog.libtorrent.org/2020/09/bittorrent-v2/)</sup> 混合种子同时包含 v1 和 v2 的 info 字典；v1 客户端将其视为普通 v1 种子，而 v2 客户端则使用 v2 特性。<sup>[19](https://naoshiquan.com/en/blog/bittorrent-v1-vs-v2)</sup> 如果 `btih` 和 `btmh` 精确主题描述的是同一个混合种子，单条磁力链接可以同时携带二者。<sup>[1](https://bittorrent.org/beps/bep_0009.html)</sup> 为兼容起见，针对 v2 种子的 DHT 与追踪器通告和查找使用截断至 20 字节的 SHA-256 info-hash，混合种子按每个 info-hash 各通告一次，追踪器结果按比特洪流版本分别报告。<sup>[17](https://blog.libtorrent.org/2020/09/bittorrent-v2/)</sup><sup> • </sup><sup>[18](https://www.libtorrent.org/upgrade_to_2.0-ref.html)</sup>

## 数据一览

- infohash 大小：v1 为 160 位（SHA-1，40 个十六进制或 32 个 base32 字符）；v2 为 256 位（SHA-256，64 个十六进制字符外加 `1220` 多重哈希前缀）。<sup>[2](https://docs.rs/rbit/latest/rbit/metainfo/struct.MagnetLink.html)</sup>
- DHT 标识符空间：160 位，由节点 ID 和 infohash 共用。<sup>[11](https://bittorrent.org/beps/bep_0005.html)</sup>
- Mainline DHT 规模：剑桥测量中每日 1500 万至 2700 万个节点，且有明显的每日更替规律。<sup>[4](https://www.cl.cam.ac.uk/~lw525/MLDHT/)</sup>
- 爬取规模：10 天内 10,149,649 条磁力链接和 57,065,499 个唯一对等节点。<sup>[16](https://doi.org/10.1109/dsc.2016.106)</sup>
- 转化率：通过种子存储服务为 46.9%，通过扩展协议为 22.7%；32.5% 的对等节点位于 NAT 或防火墙之后。<sup>[16](https://doi.org/10.1109/dsc.2016.106)</sup>

## 与 .torrent 文件及其他链接方案的比较

传统 .torrent 文件是一种数据结构，含标识追踪器的 `announce` 键和包含文件名与分片哈希的 `info` 键；infohash 即编码后 info 数据的哈希。<sup>[3](https://stackoverflow.com/questions/3844502/how-do-bittorrent-magnet-links-work)</sup> 磁力链接仅携带 infohash 及可选提示，因此客户端必须从群中重建其余元数据。两种情况下完整性都依托 infohash：比特洪流将内容完整性保证置于此处，验证下载内容与创建哈希时所用的原始数据集一致。<sup>[20](https://blog.mauve.moe/posts/protocol-comparisons)</sup> 若通过替代来源获取的 .torrent 文件与磁力链接中的 infohash 不符，必须静默丢弃。<sup>[6](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)</sup>

磁力链接还可推广到比特洪流之外：同一方案可以携带 `xt=urn:ed2k:` 哈希。ED2K 链接属于 eDonkey/eMule 生态，通过文件名、字节大小和 ED2K 哈希描述文件；两种形式不可互换。<sup>[21](https://www.ed2ktool.com/en/guide/ed2k-vs-magnet)</sup>

## 采用情况、标准化状态与近期工具

该方案始于 2002 年 6 月戈登·莫尔（Gordon Mohr）的提案，定位为对当时激增的 P2P 专用 URI 方案（如 `ed2k`、`freenet`、`mnet` 和 `sig2dat`）的项目与厂商中立式推广。<sup>[5](http://gojomo.blogspot.com/2002/06/magnet-uri-proposal.html)</sup> 其比特洪流特有行为由社区比特洪流增强提案定义：BEP 5 针对 DHT，BEP 9 针对元数据交换，网页种子扩展则针对 `as`、`xs` 和 `ws` 参数。<sup>[11](https://bittorrent.org/beps/bep_0005.html)</sup><sup> • </sup><sup>[6](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)</sup>

客户端对 v2 和混合种子的支持如今已很广泛：qBittorrent 4.4 及以后、Transmission 3.0 及以后、Deluge 2.1 及以后均支持。<sup>[19](https://naoshiquan.com/en/blog/bittorrent-v1-vs-v2)</sup> qBittorrent 随 libtorrent 2.0.x 添加了 v2 支持，在创建磁力链接时添加精确长度（`xl`）参数，并在其 WebUI 中分列 Info Hash v1 和 v2。<sup>[8](https://www.qbittorrent.org/news)</sup> 在底层库中，libtorrent 2.0.13 使 `parse_magnet_uri()` 更严格，<sup>[22](https://github.com/arvidn/libtorrent/releases/tag/v2.0.13)</sup> libtorrent 2.1.0 添加了可选的 [WebTorrent](https://www.edgepedia.org/zh/webtorrent) 支持。<sup>[23](https://github.com/arvidn/libtorrent/releases/tag/v2.1.0)</sup>

## 安全、隐私与实际使用

磁力链接不验证发布者身份，也不提供保密性；获取的元数据可通过其 infohash 校验完整性。规范建议使用满足提供方和接收方双方安全要求的通道。<sup>[6](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)</sup> 看起来正确的链接可能指向与预期不同的内容；防御手段正是 infohash 校验本身，因为任何未通过 info-hash 校验的已获取元数据都会被丢弃。<sup>[6](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)</sup>

**暴露与扫描。** 连接对等节点会将你的 IP 地址暴露给该节点，无论链接来自 .torrent 文件还是磁力链接。<sup>[7](https://www.neatnettricks.com/what-are-magnet-links-how-to-use-them-complete-guide/)</sup> DHT 扫描机器人可以发现 infohash、下载元数据和内容并建立索引，使已发布的种子数据实际上成为公开信息；USENIX WOOT 2010 的一篇论文表明，爬虫只需一个 .torrent 文件或其 infohash（作为磁力链接）即可从对等节点获取元数据。<sup>[20](https://blog.mauve.moe/posts/protocol-comparisons)</sup><sup> • </sup><sup>[24](https://static.usenix.org/events/woot10/tech/full_papers/Wolchok.pdf)</sup> 协议的 PE/MSE 扩展会加密两个对等节点之间的对等流。<sup>[20](https://blog.mauve.moe/posts/protocol-comparisons)</sup> 客户端的攻击面同样重要：libtorrent 2.1.0 的发布说明指出，可选的 WebTorrent 支持显著扩大了该库的攻击面，建议在不用时将其禁用。<sup>[23](https://github.com/arvidn/libtorrent/releases/tag/v2.1.0)</sup>

## References

1. [BEP 9: Extension for Peers to Send Metadata Files, BitTorrent Enhancement Proposals](https://bittorrent.org/beps/bep_0009.html)
2. [MagnetLink in rbit::metainfo, docs.rs](https://docs.rs/rbit/latest/rbit/metainfo/struct.MagnetLink.html)
3. [How do BitTorrent magnet links work?, Stack Overflow](https://stackoverflow.com/questions/3844502/how-do-bittorrent-magnet-links-work)
4. [BitTorrent Mainline DHT Measurement, University of Cambridge](https://www.cl.cam.ac.uk/~lw525/MLDHT/)
5. [Gojomo: MAGNET-URI Proposal (June 2002), Gordon Mohr](http://gojomo.blogspot.com/2002/06/magnet-uri-proposal.html)
6. [BitTorrent Magnet-URI Webseeding (BEP 19 extension), TheoryOrg wiki](https://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding)
7. [What Are Magnet Links & How to Use Them (Complete Guide), Neat Net Tricks](https://www.neatnettricks.com/what-are-magnet-links-how-to-use-them-complete-guide/)
8. [qBittorrent Official Website, News](https://www.qbittorrent.org/news)
9. [What's the difference between a torrent file and a Magnet link?, Super User](https://superuser.com/questions/199970/whats-the-difference-between-a-torrent-file-and-a-magnet-link)
10. [MagnetLink in bitors::magnet, docs.rs](https://docs.rs/bitors/latest/bitors/magnet/struct.MagnetLink.html)
11. [BEP 5: DHT Protocol, BitTorrent Enhancement Proposals](https://bittorrent.org/beps/bep_0005.html)
12. [Kademlia: A Peer-to-peer Information System Based on the XOR Metric, Maymounkov & Mazières](https://www.cs.cornell.edu/people/egs/714-spring05/kademlia.pdf)
13. [Connectivity Properties of Mainline BitTorrent DHT Nodes, DiVA thesis](https://www.diva-portal.org/smash/get/diva2:398948/FULLTEXT01.pdf)
14. [Profiling a Million User DHT, IMC 2007](https://conferences.sigcomm.org/imc/2007/papers/imc150.pdf)
15. [Transmission ticket #2096: Magnet links, BEP 9](https://trac.transmissionbt.com/ticket/2096)
16. [A Measurement Study on Mainline DHT and Magnet Link](https://doi.org/10.1109/dsc.2016.106)
17. [BitTorrent v2, libtorrent blog (Arvid Norberg)](https://blog.libtorrent.org/2020/09/bittorrent-v2/)
18. [Upgrade to libtorrent 2.0, libtorrent reference documentation](https://www.libtorrent.org/upgrade_to_2.0-ref.html)
19. [BitTorrent v1 vs v2: What Changed?, NSQ](https://naoshiquan.com/en/blog/bittorrent-v1-vs-v2)
20. [Comparing Peer to Peer Protocols, Mauve blog](https://blog.mauve.moe/posts/protocol-comparisons)
21. [ED2K vs Magnet Links: What Is the Difference?, ed2ktool.com](https://www.ed2ktool.com/en/guide/ed2k-vs-magnet)
22. [libtorrent v2.0.13 release notes, GitHub](https://github.com/arvidn/libtorrent/releases/tag/v2.0.13)
23. [libtorrent v2.1.0 release notes, GitHub](https://github.com/arvidn/libtorrent/releases/tag/v2.1.0)
24. [Crawling BitTorrent DHTs for Fun and Profit, USENIX WOOT 2010](https://static.usenix.org/events/woot10/tech/full_papers/Wolchok.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; 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/magnet-uri-scheme

English original: https://www.edgepedia.org/magnet-uri-scheme
