Many Android users rely on commercial VPN apps that only work on the phone itself. If you have a spare Android device with a decent data plan or a stable Wi‑Fi connection, you can turn it into a WireGuard server and let other phones, laptops, or IoT gadgets route their traffic through it. The whole process uses Termux, the official Linux terminal for Android, and does not require unlocking the bootloader or rooting the device.
pkg update && pkg upgrade -y
pkg install wireguard-tools iproute2 iptables -y
wg --version
You should see something like wireguard-tools v1.0.20210914.mkdir -p $HOME/wgserver && cd $HOME/wgserver
wg genkey | tee privatekey | wg pubkey > publickey
nano wg0.conf
<SERVER_PRIVATE_KEY> with the content of privatekey (you can view it with cat privatekey):
[Interface]
PrivateKey = <SERVER_PRIVATE_KEY>
Address = 10.0.0.1/24
ListenPort = 51820
# Optional: set a DNS server for clients
DNS = 1.1.1.1, 8.8.8.8
WireGuard needs the kernel to forward packets between the VPN interface (wg0) and the physical network interface (usually wlan0). Android disables this by default.
sysctl -w net.ipv4.ip_forward=1
~/.bashrc file:
echo "sysctl -w net.ipv4.ip_forward=1" >> ~/.bashrc
Without NAT, devices that connect to the VPN would not be able to reach the internet because the Android kernel would try to forward packets with the VPN’s private address range (10.0.0.0/24) directly.
wlan0 for Wi‑Fi and rmnet0 for mobile data. Run:
ip link
Look for the interface that has an IP address in your local network.
wlan0, add a MASQUERADE rule:
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i wg0 -j ACCEPT
iptables -A FORWARD -o wg0 -m state --state RELATED,ESTABLISHED -j ACCEPT
~/.bashrc (or create a small script that runs on boot via Termux:Widget).wg-quick up $HOME/wgserver/wg0.conf
wg show
You should see the interface, its public key, and the listening port (51820).
wg-quick down $HOME/wgserver/wg0.conf.Android can broadcast a hotspot while still using its own internet connection (the “Wi‑Fi tethering” feature). Devices that join the hotspot will automatically receive the VPN’s address range if we route the traffic correctly.
ap0 or wlan0 in hotspot mode) is added to the NAT rule. If the hotspot interface is ap0, update the iptables rule:
iptables -t nat -A POSTROUTING -o ap0 -j MASQUERADE
Each device that will use the VPN needs its own key pair and a tiny config file that points to the Android server.
wg genkey | tee client_privatekey | wg pubkey > client_publickey
wg0.conf for this client (replace placeholders):
[Peer]
PublicKey = <CLIENT_PUBLIC_KEY>
AllowedIPs = 10.0.0.2/32
Save the file and reload the interface:
wg-quick down $HOME/wgserver/wg0.conf && wg-quick up $HOME/wgserver/wg0.conf
client.conf:
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 10.0.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = <SERVER_PUBLIC_IP_OR_DDNS>:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
Endpoint note: If the Android phone is on the same local network as the client, use its local IP (e.g., 192.168.1.45). For remote access, set up a dynamic DNS service and forward UDP port 51820 on your home router to the phone.
client.conf, and toggle the connection.When the tunnel is up, visit https://www.whatismyip.com/ on the client. The displayed IP should be the public address of your Android phone (or of your home router if you used port forwarding).
ListenPort in wg0.conf to an unused port and update the client config accordingly.modprobe wireguard; if the command fails, the device’s kernel does not support WireGuard without root.sysctl net.ipv4.ip_forward should return 1).iptables -t nat -L -v to list rules).DNS line is present in the [Interface] section on the server and client. If the client still uses the local DNS, add DNS = 1.1.1.1 to the client config.privatekey or client_privatekey publicly.By following these steps you now have a fully functional WireGuard VPN server running on a standard Android device, without any rooting or custom ROMs. You can securely route traffic from laptops, other phones, or IoT gadgets through your phone’s connection, and you retain full control over encryption keys and network policies.
Because the setup lives entirely inside Termux, you can stop the server at any time with wg-quick down … and the Android system remains untouched. This makes the solution portable: move the wgserver folder to another Android device, run the same commands, and you are back online in minutes.









