CLI tool for managing WireGuard VPN interfaces and clients
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wg_gen-0.2.1.tar.gz.
File metadata
- Download URL: wg_gen-0.2.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d34c03071b895cc4f8cf4b6eaf8565c51577e1f06692e3ec7d6ccb81be4622d
|
|
| MD5 |
8420c863778d9e32c35b3b9b58a4d83c
|
|
| BLAKE2b-256 |
1a61c3031805758fca2f4e8409a18b06a28c5a16148b37e9641ded238c566ef0
|
Provenance
The following attestation bundles were made for wg_gen-0.2.1.tar.gz:
Publisher:
publish.yml on mosquito/wg-gen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wg_gen-0.2.1.tar.gz -
Subject digest:
1d34c03071b895cc4f8cf4b6eaf8565c51577e1f06692e3ec7d6ccb81be4622d - Sigstore transparency entry: 946045008
- Sigstore integration time:
-
Permalink:
mosquito/wg-gen@754aae87ad078e1e32bf696f5424414dfd385b23 -
Branch / Tag:
refs/tags/0.2.1 - Owner: https://github.com/mosquito
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@754aae87ad078e1e32bf696f5424414dfd385b23 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wg_gen-0.2.1-py3-none-any.whl.
File metadata
- Download URL: wg_gen-0.2.1-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a0ecfe97aeb38353cee26282a75e4bf6df20080e85f92bcb30d6046e94035a8
|
|
| MD5 |
b665fe334afe5cf7f07e264dd7d9f6a9
|
|
| BLAKE2b-256 |
0e9f2cadb4e6701836f89b70540f89dc20c28b4f8ebcf3a9446361ef02a4d045
|
Provenance
The following attestation bundles were made for wg_gen-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on mosquito/wg-gen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wg_gen-0.2.1-py3-none-any.whl -
Subject digest:
7a0ecfe97aeb38353cee26282a75e4bf6df20080e85f92bcb30d6046e94035a8 - Sigstore transparency entry: 946045020
- Sigstore integration time:
-
Permalink:
mosquito/wg-gen@754aae87ad078e1e32bf696f5424414dfd385b23 -
Branch / Tag:
refs/tags/0.2.1 - Owner: https://github.com/mosquito
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@754aae87ad078e1e32bf696f5424414dfd385b23 -
Trigger Event:
release
-
Statement type: