{"id":2265,"date":"2026-07-24T00:08:53","date_gmt":"2026-07-23T17:08:53","guid":{"rendered":"https:\/\/sumberlaba.com\/index.php\/2026\/07\/24\/how-to-set-up-a-wireguard-vpn-on-a-raspberry-pi\/"},"modified":"2026-07-24T00:08:53","modified_gmt":"2026-07-23T17:08:53","slug":"how-to-set-up-a-wireguard-vpn-on-a-raspberry-pi","status":"publish","type":"post","link":"https:\/\/sumberlaba.com\/index.php\/2026\/07\/24\/how-to-set-up-a-wireguard-vpn-on-a-raspberry-pi\/","title":{"rendered":"How to Set Up a WireGuard VPN on a Raspberry Pi"},"content":{"rendered":"<h1>How to Set Up a WireGuard VPN on a Raspberry Pi<\/h1>\n<p>Turning your Raspberry Pi into a VPN server is a cost-effective way to secure your internet traffic and access your home network remotely. <a href='https:\/\/www.wireguard.com\/'>WireGuard<\/a> is the modern choice\u2014faster, simpler, and more secure than older protocols. This guide walks you through a straightforward setup using a Raspberry Pi 3 or newer running Raspberry Pi OS.<\/p>\n<p>First, ensure your Pi is updated and has a static IP address. Open a terminal and run <code>sudo apt update && sudo apt upgrade -y<\/code>. Then install WireGuard: <code>sudo apt install wireguard -y<\/code>. You\u2019ll also need to generate public and private keys for the server and each client.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/via.placeholder.com\/800x600\/4a90d9\/ffffff?text=how%20to%20set%20up%20a%20VPN%20on%20a%20Raspberry%20Pi\" alt=\"Article illustration\" style=\"display:block;margin:20px auto;max-width:100%;height:auto;border-radius:8px;\" \/><\/p>\n<h2>Generate Keys and Configure the Server<\/h2>\n<p>Create a directory for WireGuard configs: <code>sudo mkdir -p \/etc\/wireguard<\/code>. Generate the server key pair:<\/p>\n<pre><code>cd \/etc\/wireguard\nsudo umask 077\nsudo wg genkey | sudo tee server_private.key | sudo wg pubkey | sudo tee server_public.key<\/code><\/pre>\n<p>Now create the server config file <code>sudo nano \/etc\/wireguard\/wg0.conf<\/code> with this content:<\/p>\n<pre><code>[Interface]\nAddress = 10.0.0.1\/24\nListenPort = 51820\nPrivateKey = &lt;paste server_private.key&gt;<\/code><\/pre>\n<p>Add a peer section for your first client (phone\/laptop):<\/p>\n<pre><code>[Peer]\nPublicKey = &lt;client_public_key&gt;\nAllowedIPs = 10.0.0.2\/32<\/code><\/pre>\n<p>Save and exit. Enable IP forwarding: <code>sudo nano \/etc\/sysctl.conf<\/code> and uncomment <code>net.ipv4.ip_forward=1<\/code>. Apply it: <code>sudo sysctl -p<\/code>.<\/p>\n<h2>Set Up the Client and Enable Routing<\/h2>\n<p>On your client device (e.g., a laptop), install WireGuard and generate a key pair. Create a client config:<\/p>\n<pre><code>[Interface]\nAddress = 10.0.0.2\/24\nPrivateKey = &lt;client_private_key&gt;\n\n[Peer]\nPublicKey = &lt;server_public_key&gt;\nEndpoint = your-pi-public-ip:51820\nAllowedIPs = 0.0.0.0\/0\nPersistentKeepalive = 25<\/code><\/pre>\n<p>To route traffic through the Pi, you need to enable NAT\/masquerade. Install iptables: <code>sudo apt install iptables -y<\/code>. Add these rules:<\/p>\n<pre><code>sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\nsudo iptables -A FORWARD -i wg0 -j ACCEPT\nsudo iptables -A FORWARD -o wg0 -j ACCEPT<\/code><\/pre>\n<p>Save rules: <code>sudo netfilter-persistent save<\/code>. Then start WireGuard: <code>sudo systemctl enable --now wg-quick@wg0<\/code>.<\/p>\n<h2>Test the Connection<\/h2>\n<p>On your client, activate the VPN. Check connectivity by visiting <code>whatismyip.com<\/code> \u2014 it should show your Pi\u2019s public IP. If it works, you\u2019re securely tunnelling traffic through your home network.<\/p>\n<h2>Conclusion<\/h2>\n<p>Setting up a WireGuard VPN on a Raspberry Pi is a weekend project that yields permanent privacy and remote access benefits. Keep your Pi updated and monitor logs with <code>sudo wg show<\/code> for any issues. For advanced setups, consider adding a firewall or dynamic DNS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Set Up a WireGuard VPN on a Raspberry Pi Turning your Raspberry Pi into a VPN server is a cost-effective way to secure your internet traffic and access your home network remotely. WireGuard is the modern choice\u2014faster, simpler, and more secure than older protocols. This guide walks you through a straightforward setup using &hellip; <\/p>\n","protected":false},"author":2716,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-2265","post","type-post","status-publish","format-standard","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/users\/2716"}],"replies":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/comments?post=2265"}],"version-history":[{"count":0,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2265\/revisions"}],"wp:attachment":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/media?parent=2265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/categories?post=2265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/tags?post=2265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}