Turn any Raspberry Pi or Debian device into a WireGuard VPN gateway for your entire network.
A bash script that turns a Raspberry Pi (or any Debian-based device) into a VPN gateway for your local network. Once set up, any device on your network can route its traffic through the VPN β just by changing its default gateway.
Need the server first? This script requires a
client.conffrom a WireGuard server. Set one up with π wg-secure-gateway
ββββββββββββββββββββ βββββββββββββββββββββ ββββββββββββββββ
β Your Devices β β Raspberry Pi β β VPN Server β
β β β (this script) β β β
β Phone, PC, ββββββββΈβ ββββββββΈβ Public IP ββββΈ Internet
β Smart TV, etc. β LAN β Gateway IP: β WG β of server β
β β β 192.168.1.x β Tunnelβ β
β GW: 192.168.1.x β β β β β
ββββββββββββββββββββ βββββββββββββββββββββ ββββββββββββββββ
- Install this script on your Raspberry Pi
- Import the
client.conffrom your VPN server - Point any device's default gateway to the RPi's IP
- β All traffic now flows through the encrypted VPN tunnel
- π Full Network Gateway β Any LAN device can use the VPN, no software needed on clients
- π‘ Static IP Setup β Auto-detects DHCP IP, converts to static (dhcpcd / netplan / interfaces)
- π Config Import β Paste contents or specify file path, with format validation
- π Automatic NAT β IP forwarding + MASQUERADE rules handled automatically
- πΎ Persistent Rules β iptables rules saved across reboots
- β Connection Verify β Automatic tunnel and public IP check after setup
- π Re-runnable β Safe to run again if something goes wrong, cleans previous config
- π₯οΈ Multi-Platform β Raspbian, DietPi, Debian 11+, Ubuntu 20.04+
β±οΈ Installation takes approximately 2β3 minutes.
If you haven't already, set up a WireGuard server and get a client.conf:
# On your remote VPS/server:
curl -fsSL https://raw.githubusercontent.com/sinezty/wg-secure-gateway/main/install.sh | sudo bash# From your server to your RPi:
scp /etc/wireguard/client.conf pi@<RPI_IP>:~/client.confcurl -fsSL https://raw.githubusercontent.com/sinezty/wg-client-gateway/main/install.sh | sudo bash# Download first, then run
wget https://raw.githubusercontent.com/sinezty/wg-client-gateway/main/install.sh
chmod +x install.sh
sudo ./install.shThe script interactively configures:
| Setting | Default | Description |
|---|---|---|
| Static IP | Current DHCP IP | Keep your current IP or enter a new one |
| Subnet | Auto-detected | CIDR notation (e.g. /24) |
| Gateway | Auto-detected | Your router's IP address |
| Device DNS | 1.1.1.1 | DNS for the gateway device itself |
| client.conf | β | Path to your WireGuard client config |
1. System Checks β Root, existing configs
2. Network Detection β Interface, IP, subnet, gateway
3. Static IP Setup β DHCP β Static (dhcpcd / netplan / interfaces)
4. Config Import β Validates [Interface] + [Peer] + PrivateKey
5. Package Install β wireguard, iptables, iptables-persistent
6. IP Forwarding β net.ipv4.ip_forward = 1
7. NAT Rules β MASQUERADE via PostUp/PostDown
8. Service Start β wg-quick@wg0 enabled
9. Verification β Tunnel status + public IP check
After installation, just change the default gateway on any device:
Settings β Network β IPv4 β Gateway: RPi IP address
sudo ip route replace default via <RPi_IP>System Preferences β Network β Advanced β TCP/IP β Router: RPi IP address
Wi-Fi Settings β Configure IP β Manual β Router/Gateway: RPi IP address
Set the RPi IP as the default gateway in your router's DHCP settings β all devices automatically route through VPN. No per-device setup needed!
| File | What it is |
|---|---|
/etc/wireguard/wg0.conf |
Client config with gateway NAT rules |
/var/log/wg_client_setup.log |
Full installation log |
/root/gateway_notes.txt |
Setup summary & usage instructions |
/etc/sysctl.d/99-wg-gateway.conf |
IP forwarding config |
The script takes the client.conf generated by the server and converts it into a gateway configuration:
Server (wg-secure-gateway) Client (wg-client-gateway)
βββββββββββββββββββββββ βββββββββββββββββββββββββββ
β /etc/wireguard/ β copy β /etc/wireguard/ β
β client.conf β βββββββββββΈ β wg0.conf β
β β β + PostUp/PostDown β
β β β + NAT MASQUERADE β
β β β + AllowedIPs check β
βββββββββββββββββββββββ βββββββββββββββββββββββββββ
- Server's
client.confβ becomes client's/etc/wireguard/wg0.conf - Script adds PostUp/PostDown gateway NAT rules into the
[Interface]section - Validates AllowedIPs = 0.0.0.0/0 (required for full tunnel gateway mode)
- If existing PostUp/PostDown exist in the config, they are replaced with gateway rules
π‘ Re-run safe: If you made a mistake or want to reconfigure, just run the script again. It will stop the existing service, clean old iptables rules, and apply fresh settings.
- Devices: Raspberry Pi, any Debian-based SBC or mini PC
- OS: Raspbian, DietPi, Ubuntu 20.04+, or Debian 11+
- Access: Root or sudo privileges
- Network: Active internet + LAN connection
- VPN Server: A
client.conffrom a WireGuard server
| Project | Description |
|---|---|
| π wg-secure-gateway | Set up the WireGuard VPN server that this gateway connects to |
Pull requests are welcome. For major changes, please open an issue first to discuss.
MIT
BarΔ±ΕY
