wireguard-linux
Mirror only. Official repository is at https://git.zx2c4.com/wireguard-linux
Top Related Projects
An open source, self-hosted implementation of the Tailscale control server
Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks.
The easiest, most secure way to use WireGuard and 2FA.
Userspace WireGuard® Implementation in Rust
Set up a personal VPN in the cloud
Streisand sets up a new server running your choice of WireGuard, OpenConnect, OpenSSH, OpenVPN, Shadowsocks, sslh, Stunnel, or a Tor bridge. It also generates custom instructions for all of these services. At the end of the run you are given an HTML file with instructions that can be shared with friends, family members, and fellow activists.
Quick Overview
WireGuard-linux is the official Linux kernel implementation of WireGuard, a modern, fast, and secure VPN protocol. It provides a simple and efficient way to create secure point-to-point connections in routed or bridged configurations, offering high-speed performance and low attack surface.
Pros
- High performance and low latency compared to other VPN protocols
- Simple configuration and ease of use
- Strong, modern cryptography with a focus on security
- Lightweight codebase, making it easier to audit and maintain
Cons
- Relatively new compared to established VPN protocols like OpenVPN or IPsec
- Limited support for older Linux kernel versions
- Fewer advanced features compared to some other VPN solutions
- May require manual firewall configuration in some cases
Code Examples
As WireGuard-linux is a kernel module and not a typical code library, we'll provide configuration examples instead of code snippets.
- Basic WireGuard interface configuration:
[Interface]
PrivateKey = your_private_key_here
Address = 10.0.0.1/24
ListenPort = 51820
[Peer]
PublicKey = peer_public_key_here
AllowedIPs = 10.0.0.2/32
Endpoint = peer.example.com:51820
- Enabling IP forwarding for WireGuard:
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
- Firewall configuration example (using iptables):
sudo iptables -A INPUT -i wg0 -j ACCEPT
sudo iptables -A FORWARD -i wg0 -j ACCEPT
sudo iptables -A FORWARD -o wg0 -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Getting Started
To get started with WireGuard-linux:
-
Install WireGuard:
sudo apt update sudo apt install wireguard -
Generate private and public keys:
wg genkey | tee privatekey | wg pubkey > publickey -
Create a configuration file (e.g.,
/etc/wireguard/wg0.conf) using the example provided in the "Code Examples" section. -
Start the WireGuard interface:
sudo wg-quick up wg0 -
To enable the interface at boot:
sudo systemctl enable wg-quick@wg0
Remember to configure your firewall and IP forwarding as needed for your specific use case.
Competitor Comparisons
An open source, self-hosted implementation of the Tailscale control server
Pros of headscale
- Implements a control server for Tailscale, providing a self-hosted alternative
- Offers a user-friendly interface for managing network connections
- Supports multi-user environments and access control features
Cons of headscale
- Less mature and potentially less stable than WireGuard
- May have a steeper learning curve for users unfamiliar with Tailscale
- Limited to Tailscale-compatible clients, whereas WireGuard is more versatile
Code Comparison
headscale:
func (ns *Namespace) GetUsers() ([]*User, error) {
users := []*User{}
err := ns.db.Where("namespace = ?", ns.Name).Find(&users).Error
return users, err
}
wireguard-linux:
static int wg_peer_remove(struct wg_device *wg, struct wg_peer *peer)
{
if (peer->is_dead)
return 0;
peer->is_dead = true;
/* ... */
}
The headscale code snippet demonstrates user management within namespaces, while the wireguard-linux code focuses on low-level peer management. This reflects the different abstraction levels and purposes of the two projects.
Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks.
Pros of Netmaker
- Provides a user-friendly web interface for network management
- Offers automated peer discovery and configuration
- Supports multi-cloud and hybrid network setups
Cons of Netmaker
- Requires additional infrastructure for management
- May have a steeper learning curve for users new to network management
- Potentially higher resource overhead compared to bare WireGuard
Code Comparison
Netmaker (Go):
func (network *Network) GetNetworkNodes() ([]models.Node, error) {
var nodes []models.Node
collection := database.FetchRecords(database.NODES_TABLE_NAME)
err := collection.Find(bson.M{"network": network.NetID}).All(&nodes)
return nodes, err
}
WireGuard-linux (C):
static int wg_peer_create(struct wg_device *wg, struct wg_peer *peer)
{
int ret;
ret = noise_handshake_init(&peer->handshake, &wg->static_identity,
peer->public_key, peer);
if (ret)
return ret;
ret = cookie_checker_init(&peer->cookie_checker, peer->public_key);
return ret;
}
The code snippets demonstrate different approaches: Netmaker focuses on high-level network management in Go, while WireGuard-linux implements low-level networking protocols in C.
The easiest, most secure way to use WireGuard and 2FA.
Pros of Tailscale
- User-friendly and easier to set up for non-technical users
- Built-in features like access controls, DNS, and automatic key rotation
- Cross-platform support with clients for various operating systems
Cons of Tailscale
- Closed-source core components and reliance on centralized coordination servers
- Less flexibility for advanced networking configurations
- Potential privacy concerns due to the centralized nature of the service
Code Comparison
Tailscale (Go):
func (c *Conn) Close() error {
c.mu.Lock()
defer c.mu.Unlock()
if c.closed {
return nil
}
c.closed = true
return c.pconn.Close()
}
WireGuard (C):
static void wg_socket_reinit(struct wg_device *wg)
{
struct socket *new4, *new6;
struct udp_tunnel_sock_cfg cfg = {
.sk_user_data = wg,
.encap_type = UDP_ENCAP_XFRM,
.encap_rcv = wg_receive
};
}
The code snippets demonstrate different approaches: Tailscale uses Go and focuses on connection management, while WireGuard uses C and deals with low-level socket operations. This reflects their design philosophies, with Tailscale providing a higher-level abstraction and WireGuard offering more direct control over networking components.
Userspace WireGuard® Implementation in Rust
Pros of boringtun
- Written in Rust, offering memory safety and performance benefits
- Cross-platform compatibility, including Windows support
- User-space implementation, allowing easier deployment in various environments
Cons of boringtun
- May have slightly higher overhead compared to kernel-space implementation
- Potentially less integrated with the Linux kernel's networking stack
- Newer project with a smaller community and less extensive testing
Code Comparison
wireguard-linux (C):
static inline void chacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
const u8 *ad, const size_t ad_len,
const u64 nonce, const u8 key[CHACHA20POLY1305_KEY_SIZE])
{
chacha20_encrypt(dst, src, src_len, key, nonce);
poly1305_mac(dst + src_len, dst, src_len, ad, ad_len, key);
}
boringtun (Rust):
pub fn encrypt_packet_with_counter(
src: &[u8],
dst: &mut [u8],
nonce: u64,
key: &[u8; 32],
) -> Result<usize, WireGuardError> {
ChaCha20Poly1305::new(key.into())
.encrypt_in_place_detached(&nonce.to_le_bytes().into(), &[], dst)?;
Ok(src.len() + AEAD_TAG_SIZE)
}
Set up a personal VPN in the cloud
Pros of algo
- Easier to set up and manage for non-technical users
- Includes additional security features like DNS-based ad blocking
- Supports multiple cloud providers out of the box
Cons of algo
- Less flexible and customizable than wireguard-linux
- May have higher resource usage due to additional features
- Limited to specific deployment scenarios
Code comparison
algo:
def deploy(server, config, args):
algo_server = AlgoServer(server, config, args)
algo_server.install()
algo_server.config()
wireguard-linux:
static int wg_set_device(struct net_device *dev, struct nlattr *tb[])
{
struct wg_device *wg = netdev_priv(dev);
int ret;
ret = wg_set_device_keys(wg, tb);
if (ret)
return ret;
}
The algo project is written in Python and focuses on high-level deployment and configuration, while wireguard-linux is written in C and deals with low-level kernel interactions. This reflects their different purposes: algo aims for ease of use and quick deployment, while wireguard-linux provides the core VPN functionality with maximum performance and flexibility.
Streisand sets up a new server running your choice of WireGuard, OpenConnect, OpenSSH, OpenVPN, Shadowsocks, sslh, Stunnel, or a Tor bridge. It also generates custom instructions for all of these services. At the end of the run you are given an HTML file with instructions that can be shared with friends, family members, and fellow activists.
Pros of Streisand
- Offers a wider range of VPN protocols and services beyond just WireGuard
- Provides automated setup scripts for multiple cloud providers
- Includes additional privacy-enhancing tools like Tor and DNS encryption
Cons of Streisand
- More complex setup and maintenance due to multiple services
- Potentially higher resource usage and overhead
- Less focused on performance optimization compared to WireGuard
Code Comparison
Streisand (setup script excerpt):
#!/bin/bash
set -e
if [ ! -e ~/.ssh/id_rsa.pub ]; then
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa
fi
WireGuard (kernel module initialization):
static int __init mod_init(void)
{
int ret;
ret = device_init();
if (ret < 0)
return ret;
return 0;
}
While Streisand focuses on automating the deployment of various VPN services, WireGuard is a dedicated, high-performance VPN protocol implementation. Streisand offers more versatility and ease of setup across different platforms, but WireGuard provides a more streamlined and efficient VPN solution with a focus on simplicity and performance.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Linux kernel
The Linux kernel is the core of any Linux operating system. It manages hardware, system resources, and provides the fundamental services for all other software.
Quick Start
- Report a bug: See Documentation/admin-guide/reporting-issues.rst
- Get the latest kernel: https://kernel.org
- Build the kernel: See Documentation/admin-guide/quickly-build-trimmed-linux.rst
- Join the community: https://lore.kernel.org/
Essential Documentation
All users should be familiar with:
- Building requirements: Documentation/process/changes.rst
- Code of Conduct: Documentation/process/code-of-conduct.rst
- License: See COPYING
Documentation can be built with make htmldocs or viewed online at: https://www.kernel.org/doc/html/latest/
Who Are You?
Find your role below:
- New Kernel Developer - Getting started with kernel development
- Academic Researcher - Studying kernel internals and architecture
- Security Expert - Hardening and vulnerability analysis
- Backport/Maintenance Engineer - Maintaining stable kernels
- System Administrator - Configuring and troubleshooting
- Maintainer - Leading subsystems and reviewing patches
- Hardware Vendor - Writing drivers for new hardware
- Distribution Maintainer - Packaging kernels for distros
- AI Coding Assistant - LLMs and AI-powered development tools
For Specific Users
New Kernel Developer
Welcome! Start your kernel development journey here:
- Getting Started: Documentation/process/development-process.rst
- Your First Patch: Documentation/process/submitting-patches.rst
- Coding Style: Documentation/process/coding-style.rst
- Build System: Documentation/kbuild/index.rst
- Development Tools: Documentation/dev-tools/index.rst
- Kernel Hacking Guide: Documentation/kernel-hacking/hacking.rst
- Core APIs: Documentation/core-api/index.rst
Academic Researcher
Explore the kernel's architecture and internals:
- Researcher Guidelines: Documentation/process/researcher-guidelines.rst
- Memory Management: Documentation/mm/index.rst
- Scheduler: Documentation/scheduler/index.rst
- Networking Stack: Documentation/networking/index.rst
- Filesystems: Documentation/filesystems/index.rst
- RCU (Read-Copy Update): Documentation/RCU/index.rst
- Locking Primitives: Documentation/locking/index.rst
- Power Management: Documentation/power/index.rst
Security Expert
Security documentation and hardening guides:
- Security Documentation: Documentation/security/index.rst
- LSM Development: Documentation/security/lsm-development.rst
- Self Protection: Documentation/security/self-protection.rst
- Reporting Vulnerabilities: Documentation/process/security-bugs.rst
- CVE Procedures: Documentation/process/cve.rst
- Embargoed Hardware Issues: Documentation/process/embargoed-hardware-issues.rst
- Security Features: Documentation/userspace-api/seccomp_filter.rst
Backport/Maintenance Engineer
Maintain and stabilize kernel versions:
- Stable Kernel Rules: Documentation/process/stable-kernel-rules.rst
- Backporting Guide: Documentation/process/backporting.rst
- Applying Patches: Documentation/process/applying-patches.rst
- Subsystem Profile: Documentation/maintainer/maintainer-entry-profile.rst
- Git for Maintainers: Documentation/maintainer/configure-git.rst
System Administrator
Configure, tune, and troubleshoot Linux systems:
- Admin Guide: Documentation/admin-guide/index.rst
- Kernel Parameters: Documentation/admin-guide/kernel-parameters.rst
- Sysctl Tuning: Documentation/admin-guide/sysctl/index.rst
- Tracing/Debugging: Documentation/trace/index.rst
- Performance Security: Documentation/admin-guide/perf-security.rst
- Hardware Monitoring: Documentation/hwmon/index.rst
Maintainer
Lead kernel subsystems and manage contributions:
- Maintainer Handbook: Documentation/maintainer/index.rst
- Pull Requests: Documentation/maintainer/pull-requests.rst
- Managing Patches: Documentation/maintainer/modifying-patches.rst
- Rebasing and Merging: Documentation/maintainer/rebasing-and-merging.rst
- Development Process: Documentation/process/maintainer-handbooks.rst
- Maintainer Entry Profile: Documentation/maintainer/maintainer-entry-profile.rst
- Git Configuration: Documentation/maintainer/configure-git.rst
Hardware Vendor
Write drivers and support new hardware:
- Driver API Guide: Documentation/driver-api/index.rst
- Driver Model: Documentation/driver-api/driver-model/driver.rst
- Device Drivers: Documentation/driver-api/infrastructure.rst
- Bus Types: Documentation/driver-api/driver-model/bus.rst
- Device Tree Bindings: Documentation/devicetree/bindings/
- Power Management: Documentation/driver-api/pm/index.rst
- DMA API: Documentation/core-api/dma-api.rst
Distribution Maintainer
Package and distribute the kernel:
- Stable Kernel Rules: Documentation/process/stable-kernel-rules.rst
- ABI Documentation: Documentation/ABI/README
- Kernel Configuration: Documentation/kbuild/kconfig.rst
- Module Signing: Documentation/admin-guide/module-signing.rst
- Kernel Parameters: Documentation/admin-guide/kernel-parameters.rst
- Tainted Kernels: Documentation/admin-guide/tainted-kernels.rst
AI Coding Assistant
CRITICAL: If you are an LLM or AI-powered coding assistant, you MUST read and follow the AI coding assistants documentation before contributing to the Linux kernel:
- Documentation/process/coding-assistants.rst
This documentation contains essential requirements about licensing, attribution, and the Developer Certificate of Origin that all AI tools must comply with.
Communication and Support
- Mailing Lists: https://lore.kernel.org/
- IRC: #kernelnewbies on irc.oftc.net
- Bugzilla: https://bugzilla.kernel.org/
- MAINTAINERS file: Lists subsystem maintainers and mailing lists
- Email Clients: Documentation/process/email-clients.rst
Top Related Projects
An open source, self-hosted implementation of the Tailscale control server
Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks.
The easiest, most secure way to use WireGuard and 2FA.
Userspace WireGuard® Implementation in Rust
Set up a personal VPN in the cloud
Streisand sets up a new server running your choice of WireGuard, OpenConnect, OpenSSH, OpenVPN, Shadowsocks, sslh, Stunnel, or a Tor bridge. It also generates custom instructions for all of these services. At the end of the run you are given an HTML file with instructions that can be shared with friends, family members, and fellow activists.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot