Many Android users want a personal, encrypted tunnel that never leaves the home network—useful for protecting traffic on public Wi‑Fi, accessing local services, or simply testing network‑related apps. WireGuard is a modern, lightweight VPN protocol that runs on almost any platform, including Android, and it can be hosted on a cheap Raspberry Pi. This tutorial walks you through the entire process without rooting the phone.
ssh access to the Pi, and the official WireGuard Android app from Google Play.Backing up the Pi’s SD card is optional but recommended before installing new packages.
ssh pi@<pi_ip_address>. The default password is raspberry unless you changed it.sudo apt update && sudo apt full-upgrade -y
sudo apt install wireguard qrencode -y
Why? wireguard provides the kernel module and user‑space utilities; qrencode will generate a QR code for easy import on Android.
sudo mkdir -p /etc/wireguard/keys
sudo wg genkey | sudo tee /etc/wireguard/keys/server_private.key
sudo cat /etc/wireguard/keys/server_private.key | wg pubkey | sudo tee /etc/wireguard/keys/server_public.key
sudo wg genkey | sudo tee /etc/wireguard/keys/client_private.key
sudo cat /etc/wireguard/keys/client_private.key | wg pubkey | sudo tee /etc/wireguard/keys/client_public.key
ls -l /etc/wireguard/keys
Note: Keep the private keys secret. Only the server needs its private key; the client will need its own private key on the phone.
sudo nano /etc/wireguard/wg0.conf
<SERVER_PRIVATE_KEY> with the content of server_private.key and adjusting the Address subnet if you already use 10.0.0.0/24 elsewhere:
[Interface]
PrivateKey = <SERVER_PRIVATE_KEY>
Address = 10.200.200.1/24
ListenPort = 51820
# Optional: Save logs for troubleshooting
# SaveConfig = true
# Allow the client to reach the Pi’s LAN (if you need local resources)
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]
PublicKey = <CLIENT_PUBLIC_KEY>
AllowedIPs = 10.200.200.2/32
Why these settings? The Address line defines the VPN subnet; the server gets .1, the client will get .2. PostUp/PostDown rules enable NAT so the client can reach the Pi’s external network.
/etc/sysctl.conf and uncomment (or add) the line:
net.ipv4.ip_forward=1
sudo sysctl -p
This allows packets from the VPN interface to be forwarded to the Pi’s regular network interface.
sudo wg-quick up wg0
sudo wg show
You should see the server’s public key and a single peer (the client) with AllowedIPs set to 10.200.200.2/32.
sudo systemctl enable wg-quick@wg0
Warning: If the Pi reboots and the interface fails to start, run sudo wg-quick up wg0 and inspect the output for missing keys or syntax errors.
sudo nano /etc/wireguard/client.conf
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 10.200.200.2/32
DNS = 1.1.1.1, 8.8.8.8
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = <PI_PUBLIC_IP_OR_LOCAL_IP>:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
Explanation: AllowedIPs = 0.0.0.0/0 routes all traffic through the VPN. If you only need local LAN access, replace it with 10.0.0.0/8 or similar.
qrencode -t ansiutf8 -l L -o - < /etc/wireguard/client.conf
The terminal will display a QR pattern. If you prefer an image file, use qrencode -o client.png < client.conf.
Address and Endpoint fields are correct.When the tunnel is active, you can check the IP address used for outbound traffic by visiting https://ifconfig.me – it should show the Pi’s public IP if you kept AllowedIPs = 0.0.0.0/0.
ping 10.200.200.1
You should receive replies.
http://192.168.1.100. If you configured NAT correctly, the request will be forwarded through the VPN.
If you want to reach your home network while away, you’ll need to expose the WireGuard port (51820 UDP) on your router and forward it to the Pi’s LAN IP.
<PI_LAN_IP>Endpoint line in client.conf (or in the Android app) to use your home’s public IP or a dynamic‑DNS hostname.Test the remote connection by turning off Wi‑Fi on the phone and using cellular data. The tunnel should still come up if the port forward is correct.
ufw or iptables rules, make sure UDP 51820 is allowed.
sudo ufw allow 51820/udp
/etc/wireguard/keys/server_public.key. A typo will cause a handshake failure.AllowedIPs = 0.0.0.0/0, ::/0 in the client config. If you limited it to a subnet, only that traffic will be tunneled.sudo iptables -t nat -L -n -v and look for the MASQUERADE rule added by PostUp. If missing, re‑run the interface or add it manually.sudo wg show wg0. The peer section should list the client’s public key and a recent “latest handshake”.sudo systemctl status wg-quick@wg0. Look for errors about missing key files.
root user (they usually are). If you moved them, update the paths in wg0.conf.
sudo apt update && sudo apt upgrade. Security patches are released frequently.AllowedIPs narrow. Routing all traffic (0.0.0.0/0) can unintentionally expose all apps to your home ISP.By following this guide you now have a fully functional, private WireGuard VPN that runs on a Raspberry Pi and connects securely to your Android phone without any rooting. You can use it to encrypt traffic on public networks, access home services, or experiment with network‑level debugging—all while keeping control over your keys and data.
Feel free to adapt the subnet, add more Android or Linux peers, or integrate the VPN into a broader home‑lab setup. The same principles apply to any device that supports WireGuard, making this a versatile foundation for future projects.









