Running a personal VPN on a spare Android phone can give you a secure tunnel back to your home network without paying for a commercial service. This tutorial walks you through every step required to transform a regular Android device into a reliable OpenVPN server – all without rooting.
pkg update && pkg upgrade -y
pkg install openvpn iproute2 iptables wget curl openssl -y
Why? openvpn provides the server binary, iptables will handle NAT, and openssl is needed for key generation.
nano for easy file editing.
pkg install nano -y
OpenVPN uses X.509 certificates for mutual authentication. Easy‑RSA is a lightweight script that automates key creation.
wget https://github.com/OpenVPN/easy-rsa/releases/download/v3.2.0/EasyRSA-3.2.0.tgz
tar xzf EasyRSA-3.2.0.tgz
mv EasyRSA-3.2.0 easy-rsa
cd easy-rsa
./easyrsa init-pki
./easyrsa build-ca nopass
If you prefer a pass‑protected CA, omit nopass and follow the prompts.
./easyrsa build-server-full server nopass
tls-crypt instead, but we include DH for maximum compatibility:
./easyrsa gen-dh
./easyrsa build-client-full client1 nopass
OpenVPN reads a plain‑text .conf (or .ovpn) file. We will place it in ~/openvpn for clarity.
mkdir -p ~/openvpn
cp pki/ca.crt pki/private/ca.key pki/issued/server.crt pki/private/server.key pki/dh.pem ~/openvpn/
server.conf with nano:
nano ~/openvpn/server.conf
port and proto if you plan to use TCP):
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh.pem
# Use modern TLS authentication (recommended)
#tls-crypt ta.key 0
# Keep the connection alive
keepalive 10 120
cipher AES-256-CBC
auth SHA256
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
# Push routes to the client – adjust to your home LAN
push "route 192.168.1.0 255.255.255.0"
push "dhcp-option DNS 8.8.8.8"
Why these options? keepalive helps detect dead peers, cipher and auth choose strong encryption, and push statements automatically configure the client’s routing.
For connected clients to reach the internet through your phone, the Android kernel must forward packets, and iptables must masquerade the traffic.
sysctl -w net.ipv4.ip_forward=1
Android does not expose /proc/sys/net/ipv4/ip_forward for permanent changes, so we set it each time the server starts.
wlan0 for Wi‑Fi). Verify with:
ip addr show
tun0) to the Wi‑Fi interface:
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
tun0 and wlan0:
iptables -A FORWARD -i tun0 -o wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
cat > ~/openvpn/start-iptables.sh <<'EOF'
#!/data/data/com.termux/files/usr/bin/sh
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i tun0 -o wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -o tun0 -m state --state ESTABLISHED,RELATED -j ACCEPT
EOF
chmod +x ~/openvpn/start-iptables.sh
openvpn --config ~/openvpn/server.conf
You should see messages ending with Initialization Sequence Completed. Keep this terminal open for the next step.
termux-service wrapper (available from termux-services package). Install it first:
pkg install termux-services -y
~/.termux/boot/openvpn.service (Termux:Boot will launch it after a reboot):
mkdir -p ~/.termux/boot
cat > ~/.termux/boot/openvpn.service <<'EOF'
[Unit]
Description=OpenVPN server on Android
After=network-online.target
[Service]
ExecStart=/data/data/com.termux/files/usr/bin/openvpn --config /data/data/com.termux/files/home/openvpn/server.conf
ExecStartPre=/data/data/com.termux/files/home/openvpn/start-iptables.sh
Restart=on-failure
[Install]
WantedBy=default.target
EOF
sv enable openvpn
sv start openvpn
Now the VPN will start automatically after a reboot and stay alive in the background.
Clients need a single .ovpn file that contains the CA certificate, client certificate, private key, and optionally a tls-crypt key.
pki directory and copy the necessary files:
cd ~/easy-rsa/pki
cat ca.crt issued/client1.crt private/client1.key > ~/openvpn/client1.ovpn
cat >> ~/openvpn/client1.ovpn <<'EOF'
client
dev tun
proto udp
remote YOUR_PUBLIC_IP 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-CBC
auth SHA256
verb 3
EOF
Replace YOUR_PUBLIC_IP with the external IP address of your home network (or a dynamic DNS name).
tls-crypt key (highly recommended), add it now:
cat ta.key >> ~/openvpn/client1.ovpn
client1.ovpn file to the device that will act as a client. The simplest way is to use adb pull to your PC, then email or QR‑code it to the client.Without port forwarding, external clients cannot reach the Android server.
192.168.1.1 or 192.168.0.1).192.168.1.42).Install the official OpenVPN Connect app on another Android phone, Windows PC, macOS, or Linux machine.
client1.ovpn file to the client device..ovpn file.auth-user-pass (not required for certificate‑only auth).Connected and the log will end with Initialization Sequence Completed.https://ifconfig.me from the client). The IP should now be the one of your home network.Warning: Making changes to iptables or forwarding settings can break other network functions. Keep a terminal window open with iptables -L -v -n so you can revert changes if needed.
WRITE_EXTERNAL_STORAGE and INTERNET permissions (Settings > Apps > Termux > Permissions).netstat -tunlp | grep 1194 to see if another app occupies the port. Change port in server.conf and update the router rule.ca.crt, server.crt, server.key, and dh.pem are all inside ~/openvpn or provide full paths.net.ipv4.ip_forward is set to 1. Run sysctl net.ipv4.ip_forward.iptables -t nat -L POSTROUTING -n -v. The rule should show traffic from 0.0.0.0/0 being masqueraded on wlan0.proto udp to proto tcp in both server and client configs, and adjust the router forwarding accordingly).keepalive 10 120 line is present. It sends a ping every 10 seconds and expects a response within 120 seconds.push "dhcp-option DNS 8.8.8.8" line is in server.conf. You can replace 8.8.8.8 with any public DNS you trust.pkg update && pkg upgrade openvpn -y inside Termux.tail -f ~/openvpn/openvpn-status.log. Look for lines like CLIENT_LIST to see connected clients.By following this guide you now have a self‑hosted OpenVPN server running on an Android phone that can be started automatically, survives reboots, and provides encrypted access to your home network from anywhere. Because the solution uses only standard Android components and Termux, it works on a wide range of devices without rooting, and you retain full control over keys and traffic.
Remember to keep your private keys safe, use strong passwords for the CA if you chose to protect it, and regularly check your router’s port‑forwarding rules after firmware updates. With these habits in place, your Android‑based VPN will remain a reliable, privacy‑respecting gateway for years to come.









