API reference guide for WireGuard including Setup, Configuration, and Usage, with examples.
<i>All credit goes to the WireGuard project, zx2c4 and the open source contributors for the original software,<br/> this is my solo unofficial attempt at providing more comprehensive documentation, API references, and examples.</i>
<small>Source for these docs, example code, and issue tracker: https://github.com/pirate/wireguard-docs Nicer HTML page version: https://docs.sweeting.me/s/wireguard
</small> </div>WireGuard is an open-source VPN solution written in C by Jason Donenfeld and others, aiming to fix many of the problems that have plagued other modern server-to-server VPN offerings like IPSec/IKEv2, OpenVPN, or L2TP. It shares some similarities with other modern VPN offerings like Tinc and MeshBird, namely good cipher suites and minimal config. As of 2020-01 it's been merged into the 5.6 version of the Linux kernel, meaning it will ship with most Linux systems out-of-the-box.
Official Links
wg
, wg-quick
WireGuard Goals
See https://github.com/pirate/wireguard-docs for example code and documentation source.
<ul> <li><a href="#Table-of-Contents">Table of Contents</a></li> <li><a href="#Intro">Intro</a> <ul> <li><a href="#My-Personal-Requirements-for-a-VPN-Solution">My Personal Requirements for a VPN Solution</a></li> <li><a href="#List-of-Possible-VPN-Solutions">List of Possible VPN Solutions</a></li> </ul> </li> <li><a href="#WireGuard-Documentation">WireGuard Documentation</a> <ul> <li><a href="#Glossary">Glossary</a> <ul> <li><a href="#PeerNodeDevice">Peer/Node/Device</a></li> <li><a href="#Bounce-Server">Bounce Server</a></li> <li><a href="#Subnet">Subnet</a></li> <li><a href="#CIDR-Notation">CIDR Notation</a></li> <li><a href="#NAT">NAT</a></li> <li><a href="#Public-Endpoint">Public Endpoint</a></li> <li><a href="#Private-key">Private key</a></li> <li><a href="#Public-key">Public key</a></li> <li><a href="#DNS">DNS</a></li> <li><a href="#Example-Strings">Example Strings</a></li> </ul> </li> <li><a href="#How-WireGuard-Works">How WireGuard Works</a> <ul> <li><a href="#How-Public-Relay-Servers-Work">How Public Relay Servers Work</a></li> <li><a href="#How-WireGuard-Routes-Packets">How WireGuard Routes Packets</a></li> <li><a href="#What-WireGuard-Traffic-Looks-Like">What WireGuard Traffic Looks Like</a></li> <li><a href="#WireGuard-Performance">WireGuard Performance</a></li> <li><a href="#WireGuard-Security-Model">WireGuard Security Model</a></li> <li><a href="#How-WireGuard-Manages-Keys">How WireGuard Manages Keys</a></li> </ul> </li> <li><a href="#Usage">Usage</a> <ul> <li><a href="#QuickStart">QuickStart</a></li> <li><a href="#Setup">Setup</a></li> <li><a href="#Config-Creation">Config Creation</a></li> <li><a href="#Key-Generation">Key Generation</a></li> <li><a href="#Start--Stop">Start / Stop</a></li> <li><a href="#Inspect">Inspect</a></li> <li><a href="#Testing">Testing</a></li> </ul> </li> <li><a href="#Config-Reference">Config Reference</a> <ul> <li><a href="#Interface">[Interface]</a></li> <li><a href="#Peer">[Peer]</a></li> </ul> </li> <li><a href="#Advanced-Topics">Advanced Topics</a> <ul> <li><a href="#IPv6">IPv6</a></li> <li><a href="#Forwarding-All-Traffic">Forwarding All Traffic</a></li> <li><a href="#NAT-to-NAT-Connections">NAT-to-NAT Connections</a></li> <li><a href="#Dynamic-IP-Allocation">Dynamic IP Allocation</a></li> <li><a href="#Other-WireGuard-Implementations">Other WireGuard Implementations</a></li> <li><a href="#WireGuard-Setup-tools">WireGuard Setup Tools</a></li> <li><a href="#Config-Shortcuts">Config Shortcuts</a></li> <li><a href="#Containerization">Containerization</a></li> </ul> </li> </ul> </li> <li><a href="#Further-Reading">Further Reading</a> <ul> <li><a href="#Reference-Docs">Reference Docs</a></li> <li><a href="#Tutorials">Tutorials</a></li> <li><a href="#Papers-Articles-and-Talks">Papers, Articles, and Talks</a></li> <li><a href="#Related-Projects">Related Projects</a></li> <li><a href="#Docker">Docker</a></li> <li><a href="#Other">Other</a></li> <li><a href="#Discussions">Discussions</a></li> </ul> </li> </ul>Whether living behind the Great Wall of China or just trying to form a network between your servers, WireGuard is a great option and serves as a "lego block" for building networks (much in the same way that ZFS is a lego block for building filesystems).
Things WireGuard does not do:
But you can write your own solutions for these problems using WireGuard under the hood (like Tailscale or AltheaNet).
These are demo hostnames, domain names, IP addresses, and ranges used in the documentation and example configs. Replace them with your preferred values when doing your own setup.
example-vpn.dev
can be replaced with any publicly accessible domain you controlpublic-server1
, public-server2
, home-server
, laptop
, phone
can be changed to your device hostnames192.0.2.1/24
, 192.0.2.3
, 192.0.2.3/32
, 2001:DB8::/64
can be replaced with your preferred subnets and addresses (e.g. 192.168.5.1/24
)Wherever you see these strings below, they're just being used as placeholder values to illustrate an example and have no special meaning.
Make sure to change the IP addresses in your configs! The blocks used in these docs are reserved for example purposes by the IETF and should never be used in real network setups.
You can use any private range you want for your own setups, e.g. 10.0.44.0/24
, just make sure
they don't conflict with any of the LAN subnet ranges your peers are on.
A host that connects to the VPN and registers a VPN subnet address such as 192.0.2.3
for itself. It can also optionally route traffic for more than its own address(es) by specifying subnet ranges in comma-separated CIDR notation.
A publicly reachable peer/node that serves as a fallback to relay traffic for other VPN peers behind NATs. A bounce server is not a special type of server, it's a normal peer just like all the others, the only difference is that it has a public IP and has kernel-level IP forwarding turned on which allows it to bounce traffic back down the VPN to other clients.
See more: https://tailscale.com/blog/how-nat-traversal-works/ (Tailscale uses Wireguard under the hood)
A group of IPs separate from the public internet, e.g. 192.0.2.1-255 or 192.168.1.1/24. Generally behind a NAT provided by a router, e.g. in office internet LAN or a home Wi-Fi network.
A way of defining a subnet and its size with a "mask", a smaller mask = more address bits usable by the subnet & more IPs in the range. Most common ones:
192.0.2.1/32
(a single IP address, 192.0.2.1
) netmask = 255.255.255.255
192.0.2.1/24
(255 IPs from 192.0.2.0
-192.0.2.255
) netmask = 255.255.255.0
192.0.2.1/16
(65,536 IPs from 192.0.0.0
- 192.0.255.255
) netmask = 255.255.0.0
192.0.2.1/8
(16,777,216 IPs from 192.0.0.0
- 192.255.255.255
) netmask = 255.0.0.0
0.0.0.1/0
(4,294,967,296 IPs from 0.0.0.0
- 255.255.255.255
) netmask = 0.0.0.0
2001:DB8::/64
https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
To people just getting started 192.0.2.1/32
may seem like a weird and confusing way to refer to a single IP. This design is nice though because it allows peers to expose multiple IPs if needed without needing multiple notations. Just know that anywhere you see something like 192.0.2.3/32
, it really just means 192.0.2.3
.
A subnet with private IPs provided by a router standing in front of them doing Network Address Translation, individual nodes are not publicly accessible from the internet, instead the router keeps track of outgoing connections and forwards responses to the correct internal IP (e.g. standard office networks, home Wi-Fi networks, free public Wi-Fi networks, etc)
The publicly accessible address:port for a node, e.g. 123.124.125.126:1234
or some.domain.tld:1234
(must be accessible via the public internet, generally can't be a private IP like 192.0.2.1
or 192.168.1.1
unless it's directly accessible using that address by other peers on the same subnet).
A WireGuard private key for a single node, generated with:
wg genkey > example.key
(never leaves the node it's generated on)
A WireGuard public key for a single node, generated with:
wg pubkey < example.key > example.key.pub
(shared with other peers)
Domain Name Server, used to resolve hostnames to IPs for VPN clients, instead of allowing DNS requests to leak outside the VPN and reveal traffic. Leaks are testable with
字节跳动发布的AI编程神器IDE
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到 语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。
专业的AI公文写作平台,公文写作神器
AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。
openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号