Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 WireGuard Client Gateway

WireGuard Client Gateway Installer

Turn any Raspberry Pi or Debian device into a WireGuard VPN gateway for your entire network.

English | TΓΌrkΓ§e

License: MIT Shell


πŸ“– What is this?

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.conf from a WireGuard server. Set one up with πŸ‘‰ wg-secure-gateway

🧭 How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   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  β”‚       β”‚                   β”‚       β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. Install this script on your Raspberry Pi
  2. Import the client.conf from your VPN server
  3. Point any device's default gateway to the RPi's IP
  4. βœ… All traffic now flows through the encrypted VPN tunnel

✨ Features

  • 🌐 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+

πŸš€ Quick Start

⏱️ Installation takes approximately 2–3 minutes.

Step 1: Set up a VPN Server

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

Step 2: Copy client.conf to your RPi

# From your server to your RPi:
scp /etc/wireguard/client.conf pi@<RPI_IP>:~/client.conf

Step 3: Run this script on the RPi

curl -fsSL https://raw.githubusercontent.com/sinezty/wg-client-gateway/main/install.sh | sudo bash

πŸ“¦ Alternative Installation

# Download first, then run
wget https://raw.githubusercontent.com/sinezty/wg-client-gateway/main/install.sh
chmod +x install.sh
sudo ./install.sh

βš™οΈ Configuration

The 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

πŸ“‹ What Happens During Installation

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

πŸ“± Using the Gateway

After installation, just change the default gateway on any device:

πŸ–₯️ Windows

Settings β†’ Network β†’ IPv4 β†’ Gateway: RPi IP address

🐧 Linux

sudo ip route replace default via <RPi_IP>

🍎 macOS

System Preferences β†’ Network β†’ Advanced β†’ TCP/IP β†’ Router: RPi IP address

πŸ“± iPhone / Android

Wi-Fi Settings β†’ Configure IP β†’ Manual β†’ Router/Gateway: RPi IP address

🌐 Router (Best Option)

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!

πŸ“ Generated Files

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

🧰 Under the Hood

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.

πŸ’» Requirements

  • 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.conf from a WireGuard server

πŸ”— Related Projects

Project Description
πŸ‘‰ wg-secure-gateway Set up the WireGuard VPN server that this gateway connects to

🀝 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss.

πŸ“ License

MIT

πŸ‘€ Author

BarışY

About

Turn a Raspberry Pi or any Linux device into a WireGuard VPN gateway for your entire LAN. One script, full network routing. Supports DietPi, Raspbian, Debian, Ubuntu.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages