WireGuard Configuration Generator
A command-line tool for managing WireGuard VPN interfaces and clients. It helps you set up and maintain a WireGuard VPN server, generate client configurations, and render system configuration files for both systemd-networkd and wg-quick.
Motivation
Managing WireGuard configurations by hand gets tedious fast - generating key pairs, tracking IP assignments,
keeping server and client configs in sync. This tool was born out of a need to manage a home network VPN
where family members and devices come and go. Instead of editing config files and juggling keys manually,
wg-gen keeps everything in a local SQLite database and generates correct, ready-to-use configurations
with a single command.
Features
- Create and manage WireGuard interfaces
- Add and remove VPN clients
- Generate configuration files for WireGuard clients
- Export client configuration as QR codes
- Generate systemd-networkd configuration
- Generate wg-quick configuration
- Manage client IP addressing automatically
- Support for both IPv4 and IPv6
- SQLite-based persistent storage
Installation
Prerequisites
- Python 3.10+
- uv package manager
Step 1: Install uv
pip install uv
On Ubuntu/Debian, where system-managed Python may block pip install, add --break-system-packages:
pip install uv --break-system-packages
Step 2: Install wg-gen
uv tool install wg-gen
This installs wg-gen into an isolated environment and makes the wg-gen command available globally.
Step 3: Verify
wg-gen --help
Upgrading
uv tool upgrade wg-gen
Install from source
uv tool install git+https://github.com/mosquito/wg-gen.git
Usage
Basic Commands
# List available commands
wg-gen --help
# Create a new WireGuard interface
wg-gen interface add wg0 --ipv4 10.0.0.1/24 --ipv6 fd00::1/64 --endpoint vpn.example.com:51820 --listen-port 51820
# List all interfaces
wg-gen interface list
# Add a new client to an interface
wg-gen client add wg0 laptop
# Generate client configuration with QR code
wg-gen client add wg0 phone --qr
# List all clients
wg-gen client list
# Remove a client
wg-gen client remove wg0 phone
# Generate systemd-networkd configuration by default to /etc/systemd/network
wg-gen render systemd
# If you want specific output directory
wg-gen render systemd --output ~/test/networkd
# Generate wg-quick configuration by default to /etc/wireguard
wg-gen render wgquick
# If you want specific output directory
wg-gen render wgquick --output ~/wg-quick
Configuration Options
Interface Configuration
When adding a new interface, the following options are available:
wg-gen interface add <interface_name> [OPTIONS]
| Option | Description | Default |
|---|---|---|
--ipv4 |
IPv4 interface for server with subnet (e.g., 10.0.0.1/24) | None |
--ipv6 |
IPv6 interface for server with subnet (e.g., fd00::1/64) | None |
--mtu |
MTU to use for the interface | 1420 |
--listen-port |
Server listen port | Random (1024-65000) |
--endpoint |
Server endpoint host:port for clients | Required |
--dns |
DNS servers for clients | 1.1.1.1, 8.8.8.8 |
--allowed-ips |
Allowed IPs for peers (non-local for all non-local nets) |
0.0.0.0/0, 2000::/3 |
--persistent-keepalive |
Persistent keepalive seconds | 15 |
Client Configuration
When adding a new client, the following options are available:
wg-gen client add <interface_name> <client_alias> [OPTIONS]
| Option | Description | Default |
|---|---|---|
--preshared-key |
Use a preshared key for additional security | False |
--force |
Overwrite existing client with the same alias on same interface | False |
--qr |
Display client configuration as a QR code | False |
How It Works
- The tool maintains a SQLite database of interfaces and clients
- When adding an interface, it generates WireGuard keys and stores the configuration
- When adding a client, it assigns the next available IP addresses from the interface's subnet
- Client configurations include private keys, server endpoint, and allowed IPs
- The render commands output configuration files for various init systems
Example Setup
Create a WireGuard Server
# Create interface with IPv4 and IPv6 subnets
wg-gen interface add wg0 \
--ipv4 10.7.0.1/24 \
--ipv6 fd00:7::1/64 \
--endpoint vpn.example.com:51820 \
--dns 1.1.1.1 9.9.9.9
# Generate systemd-networkd configuration
wg-gen render systemd
# Activate the interface
systemctl restart systemd-networkd
Add Clients
# Add a client named 'laptop'
wg-gen client add wg0 laptop
# Add a client 'phone' with QR code for mobile app
wg-gen client add wg0 phone --qr
Directory Structure
wg_gen/: Main packagecli/: Command-line interface modulesdb.py: Database interfacekeygen.py: Key generation utilitiestable.py: Table formatting for output__main__.py: Entry point
Database Location
By default, the SQLite database is stored at ~/.local/share/wg-gen/database.sqlite3.
You can specify a different location with the --db-path option.
Configuration Files
The tool reads configuration from ~/.local/share/wg-gen/config.ini by default or from the path specified in the
WG_GEN_CONFIG environment variable.
Example
[DEFAULT]
# Default configuration for wg-gen will be written to ~/.local/share/wg-gen/config.ini
# when database is created
db_path = ~/.local/share/wg-gen/database.sqlite3
log_level = info
# Default output format for list subcommands, can be 'table', 'json', 'csv', 'tsv'
output_format = table
Metadata
Release files for wg-gen 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wg_gen-0.2.2.tar.gz | 11.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wg_gen-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.6 kB
Release files / wg_gen-0.2.2.tar.gz
| Download URL | wg_gen-0.2.2.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
616aa2e18e856253edae01f38fd955bfcf78ab310c01c4642256b6fa74ccfbe0
|
|
BLAKE2b-256 checksum How to use checksums |
959bfac20e07dc30e6576858004759ee11c3e335816dd37266bc78909ac17359
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 13, 2026.
Transparency logRelease files / wg_gen-0.2.2-py3-none-any.whl
| Download URL | wg_gen-0.2.2-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df38f30202be22bdcadc743eecd4461ce79c48407ab811181beb217217894230
|
|
BLAKE2b-256 checksum How to use checksums |
c00cd5fcd2fef65b0f5cb9f2563589bf4795b8c6b5f03fcac2ede2b25ef2d636
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 13, 2026.
Transparency log