What does a WireGuard config generator do?
WireGuard is a small, fast VPN built into the Linux kernel. Its configuration is short, but it needs a lot of matching detail: every machine has a private key, every other machine needs the matching public key, each client needs its own tunnel address, and the server needs one [Peer] block per client. Writing this by hand with wg genkey and wg pubkey for ten devices is slow and easy to get wrong. This tool makes the whole set at once: one server file and as many client files as you ask for.
The keys are made inside this page, with your browser's random number generator, using the same X25519 math as the wg command. Nothing is uploaded and nothing is stored on a server. The private keys exist only in the page until you copy or download them. Each client file carries its own private key and the server's public key; the server file carries the server's private key and the clients' public keys. Send each client file only to its owner.
The tool also writes the details people forget: a different address for each client (10.8.0.2/32, 10.8.0.3/32 and so on), an optional preshared key per client, PersistentKeepalive for clients behind NAT, and optional PostUp and PostDown lines so the server forwards and masquerades the tunnel traffic. For a tunnel that sends only some traffic through the VPN, build the AllowedIPs value with the subnet exclusion calculator.
How to make a WireGuard server and client configs
- Set the server address and IPv4 network, for example
10.8.0.1/24. The prefix goes from/1to/30. You can also add an IPv6 network such asfd42:42:42::1/64; the IPv6 ULA generator makes a private prefix for it. - Choose the listen port (default 51820) and the number of clients (1 to 250).
- Fill the server public address, such as
vpn.example.comorvpn.example.com:443. If you leave it empty, the client files containYOUR_SERVER_IP:51820for you to replace. - Set the client DNS, the AllowedIPs written in the clients, the keepalive in seconds (0 turns it off) and the MTU (0 uses the default).
- To let clients reach the internet through the server, write the server's internet interface, such as
eth0, in the NAT field. - Keep or remove the preshared key option. It adds one extra shared secret per client.
- Open the server and each client in the list of files. Copy the text, download a single file, or use Download all (.zip). For a phone, open a client and scan its QR code with the WireGuard app.
- Changing an option rewrites the text but keeps the keys you already have. Use New keys to start over.
To repeat the same keys later, fill the phrase box. Every key is then derived from the phrase with PBKDF2-SHA256 and 600000 rounds, so the same phrase and settings give the same files again. Anyone who guesses the phrase gets every key, so use a long random phrase, or leave it empty for random keys. The token generator can make one.
Examples
Keys are random each time, so the examples show <key> where a key goes. Everything else is exactly what the tool writes.
The defaults with two clients and NAT
With server 10.8.0.1/24, endpoint vpn.example.com, NAT interface eth0 and two clients, the server file is:
[Interface]
PrivateKey = <key>
Address = 10.8.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
# client1
PublicKey = <key>
PresharedKey = <key>
AllowedIPs = 10.8.0.2/32
[Peer]
# client2
PublicKey = <key>
PresharedKey = <key>
AllowedIPs = 10.8.0.3/32The matching client file
The first client of the same set:
[Interface]
PrivateKey = <key>
Address = 10.8.0.2/32
DNS = 1.1.1.1, 2606:4700:4700::1111
[Peer]
PublicKey = <key>
PresharedKey = <key>
Endpoint = vpn.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25The PublicKey here is the server's. The PresharedKey is the same one written in the server's [Peer] block for this client.
Dual stack
Adding the IPv6 network fd42:42:42::1/64 makes the server Address = 10.8.0.1/24, fd42:42:42::1/64. Each client gets both addresses, and the server writes AllowedIPs = 10.8.0.2/32, fd42:42:42::2/128 for the first one. The NAT lines gain matching ip6tables rules.
A small network
A /29 has room for 5 clients. Asking for 6 shows the capacity error below, and a /30 holds only one.
Common errors and how to fix them
- The IPv4 network must be the server address with a prefix: write
10.8.0.1/24, not10.8.0.1. The prefix goes from/1to/30. - This network has room for N clients: lower the number of clients or use a shorter prefix, such as
/24. - The port must be a number from 1 to 65535, and the number of clients must be from 1 to 250.
- The server address must be a host name or IP address: no spaces or symbols; add
:portonly if it differs from the listen port. - DNS must be one or more IPv4 or IPv6 addresses separated by commas: names such as
dns.exampleare not accepted. - AllowedIPs must be addresses or blocks:
0.0.0.0/0, ::/0sends everything through the tunnel. - MTU must be 0 or a number from 576 to 9000. If you have no reason to change it, leave 0.
- The interface name has up to 15 letters, digits, dots, dashes or underscores: use
eth0, noteth 0.
Frequently asked questions
Is it safe to generate WireGuard keys in a web page?
The keys are made in your browser and never sent anywhere, so the page cannot see them after you leave. The risk is what you do next: do not paste the files into chats or tickets. Copy each client file only to its owner.
Do I need to run the server config as it is?
Save the server text as /etc/wireguard/wg0.conf and start it with wg-quick up wg0. If you use the NAT field, also turn on forwarding with sysctl -w net.ipv4.ip_forward=1 and open the listen port in your firewall.
What does the preshared key do?
It adds a second secret between each client and the server, as extra protection against future quantum attacks on the key exchange. It is optional.
Can I get the same keys again?
Yes, with the phrase option. Without it, every run makes new random keys.
How to run the result
Bash
sudo install -m 600 wg0.conf /etc/wireguard/wg0.conf
sudo wg-quick up wg0
sudo wg show
sudo systemctl enable wg-quick@wg0