A comprehensive set of scripts for automated WireGuard VPN setup, management, and maintenance on OpenWrt routers.
- Automated Installation - Complete WireGuard setup with interactive prompts
- Auto Package Installation - Detects and installs missing packages automatically
- Interactive Peer Management - User-friendly menu interface for managing peers
- QR Code Generation - Instant mobile device setup with QR codes
- Key Rotation - Security-focused key rotation with backup
- Backup & Rollback - Automatic configuration backups with rollback option
- System Backup Integration - Adds WireGuard to OpenWrt backup configuration
- Clean Uninstall - Complete removal tool with dry-run preview
| Script | Purpose | Version |
|---|---|---|
wg-openwrt-installer.sh |
Main installer and initial peer setup | 2025.11.2 |
wg-peer-manage.sh |
Interactive peer management | 2025.11.2 |
wg-key-rotate.sh |
Key rotation for security | 2025.9.1 |
wg-uninstall.sh |
Clean removal of WireGuard | 2025.11.2 |
- OpenWrt 23.05 or later
- Internet connectivity for package installation
The installer will automatically detect and offer to install:
wireguard-tools- WireGuard command-line utilitieskmod-wireguard- WireGuard kernel moduleluci-app-wireguard- LuCI web interface integration
qrencode- QR code generation for mobile devices
Note: You no longer need to manually install packages! The installer will handle this for you.
cd /root
wget https://raw.githubusercontent.com/Coralesoft/Openwrt-Wireguard-Installer/main/wg-openwrt-installer.sh
wget https://raw.githubusercontent.com/Coralesoft/Openwrt-Wireguard-Installer/main/wg-peer-manage.sh
wget https://raw.githubusercontent.com/Coralesoft/Openwrt-Wireguard-Installer/main/wg-key-rotate.sh
wget https://raw.githubusercontent.com/Coralesoft/Openwrt-Wireguard-Installer/main/wg-uninstall.sh
chmod +x wg-*.sh./wg-openwrt-installer.shThe installer will:
- Check for missing packages and offer to install them
- Guide you through configuration with helpful prompts
- Generate server and peer keys
- Configure network and firewall
- Generate QR codes for easy mobile setup
- Add
/etc/wireguardto backup configuration
Interactive Prompts:
- WireGuard interface name (default:
wg0) - UDP port (default:
51820) - VPN subnet (default:
192.168.20.1/24) - Public endpoint (your router's public IP/domain)
- LAN/WAN zone names
- DNS server for peers
- Number of initial peers to create
Use the interactive peer management tool:
./wg-peer-manage.shInteractive Menu:
WireGuard Peer Management
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Interface: wg0
1. List all peers
2. Add new peer
3. Manage existing peer
4. Show traffic statistics
5. Show active connections
6. Restart WireGuard interface
7. Exit
Select option [1-7]: _
Features:
- ๐ List peers with numbers and status
- โ Add new peers with auto-IP allocation
- ๐ง Enable/disable peers without removing them
- ๐๏ธ Remove peers with automatic archiving
- ๐ View traffic statistics
- ๐ Show peer details and regenerate QR codes
- ๐ Restart interface when needed
Command-Line Mode (Scriptable):
./wg-peer-manage.sh --list # List all peers
./wg-peer-manage.sh --add # Add new peer
./wg-peer-manage.sh --show=laptop # Show peer details + QR
./wg-peer-manage.sh --remove=old-phone # Remove peer
./wg-peer-manage.sh --disable=tablet # Temporarily disable
./wg-peer-manage.sh --enable=tablet # Re-enable
./wg-peer-manage.sh --traffic # Show bandwidth usage
./wg-peer-manage.sh --active # Show connected peers
./wg-peer-manage.sh --no-clear # Disable screen clearingAfter adding peers, configurations are available in:
/etc/wireguard/peers/
Each peer gets:
.conffile - WireGuard configuration-privatekey- Peer's private key-publickey- Peer's public key.png- QR code (if qrencode installed)
- Install WireGuard app
- Tap "+" โ "Scan from QR code"
- Scan the displayed QR code
- Activate tunnel
# Copy the .conf file to the peer device, then:
sudo cp peer.conf /etc/wireguard/wg0.conf
sudo wg-quick up wg0
# Enable at boot (optional):
sudo systemctl enable wg-quick@wg0Regular key rotation is essential for security. Use the included rotation script:
./wg-key-rotate.sh --server --all-peers./wg-key-rotate.sh --peer=laptop --peer=phone./wg-key-rotate.sh --serverImportant Notes:
- After rotating server keys, ALL peers must update their configurations!
- Old keys are backed up to
/etc/wireguard/backup/ - New peer configs and QR codes are automatically generated
- The script will prompt to restart the interface
Options:
--server Rotate server keypair
--peer=NAME Rotate specific peer (can use multiple times)
--all-peers Rotate all peer keypairs
--no-backup Skip creating backups
--interface=NAME Specify interface (default: wg0)To completely remove WireGuard configuration:
# Preview what will be removed (recommended first step)
./wg-uninstall.sh --dry-run
# Full uninstall
./wg-uninstall.sh
# Uninstall specific interface
./wg-uninstall.sh --interface=wg1The uninstaller removes:
- โ Network interface configuration (UCI)
- โ All peer configurations
- โ Firewall rules and zones
- โ
WireGuard keys and configs (
/etc/wireguard/) - โ Live network interface
- โ
/etc/wireguardfrom backup configuration
Note: The uninstaller will ask for confirmation before making changes.
After installation, WireGuard files are organized as:
/etc/wireguard/
โโโ privatekey # Server private key
โโโ publickey # Server public key
โโโ peers/ # Peer configurations
โ โโโ laptop.conf # Peer config file
โ โโโ laptop-privatekey # Peer private key
โ โโโ laptop-publickey # Peer public key
โ โโโ laptop.png # QR code
โโโ backup/ # Key rotation backups
โ โโโ 20251101-120000/ # Timestamped backup directory
โโโ removed/ # Archived removed peers
โโโ 20251101-130000-old-device/
/etc/config/
โโโ network # UCI network config
โโโ firewall # UCI firewall config
โโโ network.bak.* # Automatic backups
โโโ firewall.bak.* # Automatic backups
/etc/sysupgrade.conf # Contains /etc/wireguard for backups
- Regular Key Rotation: Rotate keys every 3-6 months
- Secure Key Distribution: Never send configs over unencrypted channels
- Firewall Configuration: Ensure only necessary ports are open
- Peer Management: Remove unused peers promptly using
wg-peer-manage.sh - Backup Keys: System backups now include
/etc/wireguardautomatically - Monitor Connections: Use
--activeto check connected peers regularly
The installer automatically adds /etc/wireguard/ to OpenWrt's backup configuration (/etc/sysupgrade.conf).
This means:
- โ Your WireGuard keys are included in system backups
- โ Configurations persist across system upgrades
- โ Backups created via LuCI include WireGuard
# Create backup archive
sysupgrade -b /tmp/backup-$(date +%Y%m%d).tar.gz
# Verify WireGuard is included
tar -tzf /tmp/backup-*.tar.gz | grep wireguard# After fresh install or upgrade:
sysupgrade -r /tmp/backup-20251101.tar.gz
# Router will reboot and restore WireGuard configurationDuring installation, simply enter a different interface name when prompted:
./wg-openwrt-installer.sh
# When prompted: Enter WireGuard interface name [wg0]: wg1Run the installer multiple times with different interface names:
# First VPN
./wg-openwrt-installer.sh # Use wg0
# Second VPN
./wg-openwrt-installer.sh # Use wg1
# Manage each separately
./wg-peer-manage.sh --interface=wg0
./wg-peer-manage.sh --interface=wg1After installation, you can manually edit:
# Show current configuration
uci show network.wg0
# Change port
uci set network.wg0.listen_port='51821'
uci commit network
/etc/init.d/network restart
# Add manual peer
uci add network wireguard_wg0
uci set network.@wireguard_wg0[-1].description='manual-peer'
uci set network.@wireguard_wg0[-1].public_key='<PUBLIC_KEY>'
uci set network.@wireguard_wg0[-1].allowed_ips='192.168.20.10/32'
uci commit network./wg-peer-manage.sh --active # Show currently connected peers
./wg-peer-manage.sh --traffic # Show bandwidth usage per peer
./wg-peer-manage.sh --list # List all configured peers# Show interface status
wg show wg0
# Show all connected peers with details
wg show wg0 peers
# Check latest handshakes (indicates active connections)
wg show wg0 latest-handshakes
# Show transfer statistics
wg show wg0 transfer
# Compact view of all info
wg show wg0 dumpIf luci-app-wireguard is installed:
- Navigate to:
StatusโWireGuard - View connected peers and traffic statistics
- Or:
NetworkโInterfacesโwg0โEdit
# 1. Check if WireGuard is running
wg show wg0
# 2. Verify interface has correct IP
ip addr show wg0
# 3. Check firewall rules
uci show firewall | grep wg0
# 4. Verify port is listening
netstat -ulnp | grep 51820
# 5. Check logs
logread | grep -i wireguard
# 6. Test from peer device
ping 192.168.20.1 # Should work if connected- Verify endpoint in peer config matches your public IP/domain
- Check that UDP port is open/forwarded on router
- Ensure time is synchronized on both devices (WireGuard requires this)
- Verify keys match between server and peer configs
- Check if peer is enabled:
./wg-peer-manage.sh --list
- Check DNS server in peer configs:
cat /etc/wireguard/peers/device.conf - Verify DNS forwarding is enabled on OpenWrt
- Test with IP addresses first:
ping 192.168.1.1 - Check LAN firewall accepts DNS requests from VPN
If WireGuard doesn't work after restoring backup:
# 1. Verify files were restored
ls -la /etc/wireguard/
# 2. Check UCI configuration
uci show network.wg0
# 3. Restart network
/etc/init.d/network restart
# 4. Check interface
wg show wg0# If you see "Server public key not found":
# WireGuard server not installed yet
./wg-openwrt-installer.sh
# Clear screen issues on some terminals:
./wg-peer-manage.sh --no-clearPurpose: Initial WireGuard server setup
Features:
- Auto-detects and installs missing packages
- Interactive configuration with helpful prompts
- Creates initial peers with QR codes
- Configures network, firewall, and UCI
- Adds WireGuard to backup configuration
- Rollback option if something goes wrong
Usage:
./wg-openwrt-installer.sh
# Follow interactive promptsPurpose: Day-to-day peer management
Interactive Mode:
./wg-peer-manage.sh # Full interactive menu
./wg-peer-manage.sh --no-clear # Without screen clearingCommand-Line Mode:
./wg-peer-manage.sh --list
./wg-peer-manage.sh --add
./wg-peer-manage.sh --show=NAME
./wg-peer-manage.sh --remove=NAME
./wg-peer-manage.sh --enable=NAME
./wg-peer-manage.sh --disable=NAME
./wg-peer-manage.sh --traffic
./wg-peer-manage.sh --active
./wg-peer-manage.sh --interface=wg1
./wg-peer-manage.sh --helpPurpose: Security key rotation
Usage:
./wg-key-rotate.sh --server # Rotate server only
./wg-key-rotate.sh --peer=laptop # Rotate one peer
./wg-key-rotate.sh --peer=laptop --peer=phone # Multiple peers
./wg-key-rotate.sh --all-peers # All peers
./wg-key-rotate.sh --server --all-peers # Everything
./wg-key-rotate.sh --no-backup # Skip backup
./wg-key-rotate.sh --interface=wg1 # Specific interface
./wg-key-rotate.sh --helpPurpose: Complete removal of WireGuard
Usage:
./wg-uninstall.sh --dry-run # Preview only
./wg-uninstall.sh # Full removal
./wg-uninstall.sh --interface=wg1 # Specific interface
./wg-uninstall.sh --helpThis project is open source and available under the MIT License.
Copyright: C.Brown CoraleSoft, 2025
For issues, questions, or suggestions:
- Open an issue on GitHub
- Check existing issues for solutions
- Provide router model and OpenWrt version when reporting issues
- โจ Added automatic package installation
- โจ Added interactive peer management tool (
wg-peer-manage.sh) - โจ Added backup configuration integration (
/etc/sysupgrade.conf) - โจ Improved uninstaller with dry-run and interface options
- ๐ Fixed sed delimiter bug in key rotation
- ๐ Fixed IP allocation detection in peer manager
- โจ Initial key rotation script
- ๐ Secure key backup functionality
- โจ Initial public release
- ๐ Basic installer with QR code support
Note: Always test in a safe environment before deploying to production. Keep backups of working configurations!
Tested on: OpenWrt 23.05.x with various routers including Flint 2 (MT6000)