← Back to All Blog Posts
October 4, 2026 • By Syed
Category:VPN SETUP GUIDES
Tags:ENCRYPTION HOME IP WIREGUARD

How to Generate WireGuard Config Files the Right Way

Your Internet IP is: ISP:

VPN SETUP GUIDES

How to Generate WireGuard Config Files the Right Way

WireGuard's simplicity is its superpower, but that simplicity means there's no hand-holding when you need to generate WireGuard config files…

✓The Moving Parts, Explained✓Generating Keys Properly✓Server Config Template Walkthrough

Quick Answer

Generate WireGuard configs with a unique key pair per device (wg genkey), a distinct tunnel IP per peer, client AllowedIPs at 0.0.0.0/0, and no reused private keys. Test each with wg-quick up and a leak check: the checklist HomeIPVPN runs on client configs.

  • The fields: PrivateKey/PublicKey identity, tunnel Address, ListenPort 51820, Endpoint as a DDNS hostname, AllowedIPs routing, PersistentKeepalive 25.
  • Key hygiene: One key pair per device, configs at 0600, private keys never emailed or pasted in chat.
  • Server template: Each peer block: client public key and tunnel IP (/32), plus PostUp/PostDown rules for forwarding and NAT.
  • Before you rely on it: Malformed configs fail silently or connect unprotected: verify with wg-quick up and a leak check.

How to Generate WireGuard Config Files the Right Way

WireGuard's simplicity is its superpower, but that simplicity means there's no hand-holding when you need to generate WireGuard config files correctly. A malformed config fails silently or, worse, connects without actually protecting you. This guide explains the moving parts (keys, addresses, AllowedIPs), walks through clean server and client templates, and covers the key-hygiene rules that keep your tunnel secure.

The Moving Parts, Explained

A WireGuard config has a small number of fields, and each one matters:

  • PrivateKey: Your device's secret identity. Generated with wg genkey. Never shared, never transmitted.
  • PublicKey: Derived from the private key (echo <private> | wg pubkey). This is what you give to the other side, it's safe to share.
  • PresharedKey (optional): An extra symmetric key shared between two peers for post-quantum resistance. Nice to have, not required.
  • Address: The device's IP inside the tunnel (e.g., 10.0.0.1/24 on the server, 10.0.0.2/32 on a client). These are private addresses you choose, they don't need to relate to your real network.
  • ListenPort: The UDP port the server listens on (conventionally 51820).
  • Endpoint: Where the client connects: your server's public address, ideally a DDNS hostname, plus port (e.g., myhome.example.com:51820).
  • AllowedIPs: The heart of WireGuard's security model ("cryptokey routing"). It defines which IPs may arrive from / be sent to a peer.
  • On the client: 0.0.0.0/0 means "send everything through the tunnel" (full tunnel). A narrower range means split tunneling.
  • On the server: each peer's entry lists that peer's tunnel IP (e.g., 10.0.0.2/32), the server will only accept packets from that peer claiming that source.
  • PersistentKeepalive: How often (seconds) the client pings the server to keep NAT mappings alive. 25 is the standard value for clients behind NAT.

Generating Keys Properly

On any machine with WireGuard tools installed:

# Server keys
wg genkey | tee server_private.key | wg pubkey > server_public.key

# Client keys (repeat per client - never reuse)
wg genkey | tee client1_private.key | wg pubkey > client1_public.key

Rules that matter:

  1. One key pair per device. Two devices sharing a private key will fight over the tunnel IP and cause intermittent, maddening failures.
  2. Private keys live in the config file with 0600 permissions (chmod 600 wg0.conf).
  3. Private keys are never emailed in plaintext, pasted into chat, or stored in unencrypted notes.

Server Config Template Walkthrough

/etc/wireguard/wg0.conf on the server:

[Interface]
PrivateKey = <server private key>
Address = 10.0.0.1/24
ListenPort = 51820

# Enable forwarding + NAT so clients reach the internet
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

[Peer]
# Laptop
PublicKey = <client1 public key>
AllowedIPs = 10.0.0.2/32

[Peer]
# Phone
PublicKey = <client2 public key>
AllowedIPs = 10.0.0.3/32

Notes: adjust eth0 to your server's actual outbound interface. Each [Peer] section gets exactly one client's public key and that client's tunnel IP with /32. The server's Address uses /24 so it owns the whole tunnel subnet.

Client Config Template Walkthrough

On the client (laptop, phone, or travel router, the fields are identical):

[Interface]
PrivateKey = <client1 private key>
Address = 10.0.0.2/32
DNS = 10.0.0.1

[Peer]
PublicKey = <server public key>
Endpoint = myhome.example.com:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

Notes: DNS = 10.0.0.1 routes DNS through the tunnel to the server (preventing DNS leaks). AllowedIPs = 0.0.0.0/0 is the full-tunnel setting, everything goes through home. PersistentKeepalive = 25 keeps the connection alive through hotel and mobile NAT.

Key Hygiene: What to Never Share or Reuse

DoDon't
Generate a fresh key pair per deviceReuse one private key across devices
Store private keys with 0600 permissionsLeave keys world-readable
Rotate keys if a device is lost or soldKeep using a compromised key "for now"
Share only public keys and configs' non-secret partsEmail private keys in plaintext
Delete configs from decommissioned devicesLeave stale peers in the server config

When a device is lost, stolen, or sold: remove its [Peer] block from the server config and restart the interface. That single action fully revokes its access, no password changes needed anywhere else.

Testing Before You Trust It

  1. Bring the tunnel up: sudo wg-quick up wg0 (or import the config in your app/router).
  2. Check the handshake: sudo wg show should show a recent handshake and transfer counters moving.
  3. IP test: Your public IP should be your home/server IP.
  4. DNS leak test: All resolvers shown should be your tunnel DNS, never the local network's.
  5. Kill test: Stop the server side briefly, with a proper kill switch (or AllowedIPs full-tunnel on a router with firewall rules), traffic should stop, not leak.

Frequently Asked Questions

Can I use the same config file on two devices? +
No. Each device needs its own private key and tunnel IP. Sharing one config causes conflicts and intermittent drops as both devices fight over the same tunnel address.
What does AllowedIPs = 0.0.0.0/0 actually do? +
It tells WireGuard to route all IPv4 traffic through that peer, the full-tunnel behavior you want for a home IP VPN. (Add ::/0 too if you use IPv6.)
Do I need a PresharedKey? +
Not strictly, WireGuard's standard cryptography is considered secure. A preshared key adds a layer of post-quantum resistance. It's cheap to add if your tooling supports it, but don't let its absence stop you.
Where should the Endpoint point, IP or hostname? +
A DDNS hostname, always, for a home server, your home IP changes, and a hostname follows it automatically. A raw IP in the config will silently break after the next ISP IP rotation.
How do I revoke a lost device's access? +
Delete its [Peer] section from the server config and restart the WireGuard interface. Its keys become useless instantly.
Why does my tunnel connect but pass no traffic? +
The classic causes: missing NAT/masquerade rules on the server (the PostUp lines), a firewall blocking forwarding, or AllowedIPs misconfigured so return traffic has no route. Check wg show for handshake first, no handshake means a connectivity/key problem; handshake with no traffic means a routing/NAT problem.

Need help setting this up?

Config files are unforgiving, and one wrong key means a tunnel that silently fails. If you'd rather skip the trial and error, our team will build and test the whole thing for you: https://homeipvpn.com.

Share this post

Facebook WhatsApp X LinkedIn Pinterest Reddit Email

Looking to Travel And Need Home Internet IP?

Book a 1-on-1 remote setup session with our network engineers and have your personal Home IP VPN configured and ready to use within a few hours.

Book Home IP VPN Setup Appointment
No monthly subscriptions • One-time setup fee • Zero technical skills required
Syed
Syed VPN & Network Infrastructure Specialist
Syed is a network infrastructure engineer specializing in residential VPN deployments and travel router systems for digital nomad and remote workers, working from abroad.
More Articles →

Related Articles & Guides

October 17, 2026

Working from Brazil While Keeping Your Home IP

Work from Brazil home IP VPN setup: which services misbehave on Brazilian…

Read Article →
October 16, 2026

Can Websites Tell You’re Using a VPN? Detection Methods Explained

Can websites detect VPN use? The real detection signals ranked, which ones…

Read Article →
October 16, 2026

OpSec Basics for Remote Workers Traveling Abroad

OpSec remote workers traveling guide: the five signal layers beyond your VPN…

Read Article →