使用外部防火墙(如 EC2/GCE 安全组)时需自行放行 UDP 51820 端口;默认端口为 51820,交互安装可改;脚本需以 sudo 运行,且仅支持 README 列出的 Linux 发行版
wireguard-install
hwdsl2MIT活跃维护一条命令在 Ubuntu、Debian、CentOS 等主流 Linux 上装好 WireGuard VPN 服务端,带交互式配置和客户端管理,省去手动改配置的麻烦。
WireGuard VPN server installer for Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS, Fedora, openSUSE and Raspberry Pi OS. Includes interactive setup and client management.
wget -O wireguard.sh https://get.vpnsetup.net/wg
sudo bash wireguard.sh --autoREADME 未说明硬件要求;需在 Ubuntu、Debian、AlmaLinux、Rocky Linux、CentOS、Fedora、openSUSE 或 Raspberry Pi OS 的服务器上运行,云服务器、VPS 或独立服务器均可
一条脚本在 Linux 服务器上自动装好 WireGuard VPN 服务端并管理客户端
一条命令在 Ubuntu、Debian、CentOS 等主流 Linux 上装好 WireGuard VPN 服务端,带交互式配置和客户端管理,省去手动改配置的麻烦。
核心能力
- 全自动安装 WireGuard 服务端,无需交互输入
- 生成 Windows、macOS、iOS、Android 客户端配置
- 生成二维码方便手机端扫码接入
- 支持命令行增删查客户端并显示二维码
- 优化 sysctl 参数提升 VPN 性能,支持 IPv4/IPv6 双栈
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
English | 简体中文 | 繁體中文 | Русский | Video en Español
WireGuard VPN Server Auto Setup Script
WireGuard VPN server installer for Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS, Fedora, openSUSE and Raspberry Pi OS.
This script will let you set up your own VPN server in just a few minutes, even if you haven't used WireGuard before. WireGuard is a fast and modern VPN designed with the goals of ease of use and high performance.
Features:
- Fully automated WireGuard VPN server setup, no user input needed
- Supports interactive install using custom options
- Generates VPN profiles to auto-configure Windows, macOS, iOS and Android devices
- Generates QR codes for easy mobile device setup
- Supports managing WireGuard VPN users
- Optimizes
sysctlsettings for improved VPN performance - Dual-stack IPv4 and IPv6 support for VPN clients
Also available:
- Docker VPN: WireGuard, OpenVPN, IPsec VPN, Headscale
- AI: Self-Hosted AI Stack for local LLMs, chat, RAG, voice and AI tools
📘 Interested in self-hosted AI? The Self-Hosted AI Builder’s Guide (Kindle · Google Play · paperback) is a practical guide to building, securing, and operating your own private AI stack.
Installation
First, download the script on your Linux server*:
wget -O wireguard.sh https://get.vpnsetup.net/wg
* A cloud server, virtual private server (VPS) or dedicated server.
Option 1: Auto install WireGuard using default options.
sudo bash wireguard.sh --auto
Note: This recording is for demo purposes only.
Tip: Optionally install OpenVPN, IPsec VPN and/or Headscale on the same server.
For servers with an external firewall (e.g. EC2/GCE), open UDP port 51820 for the VPN.
Option 2: Interactive install using custom options.
sudo bash wireguard.sh
You can customize the following options: VPN server's DNS name, UDP port, DNS server for VPN clients and name of the first client.
For servers with an external firewall, open your selected UDP port for the VPN.
You may also use curl to download:
curl -fL -o wireguard.sh https://get.vpnsetup.net/wg
Then follow the instructions above to install.
Alternative setup URLs:
https://github.com/hwdsl2/wireguard-install/raw/master/wireguard-install.sh
https://gitlab.com/hwdsl2/wireguard-install/-/raw/master/wireguard-install.sh
If you are unable to download, open wireguard-install.sh, then click the Raw button on the right. Press Ctrl/Cmd+A to select all, Ctrl/Cmd+C to copy, then paste into your favorite editor.
Advanced users can auto install WireGuard using custom options, by specifying command-line options when running the script. For more details, see the next section "view usage information for the WireGuard script".
Alternatively, you may provide a Bash "here document" as input to the setup script. This method can also be used to provide input to manage users after install.
First, install WireGuard interactively using custom options, and write down all your inputs to the script.
sudo bash wireguard.sh
If you need to remove WireGuard, run the script again and select the appropriate option.
Next, create the custom install command using your inputs. Example:
sudo bash wireguard.sh <<ANSWERS
n
51820
client
2
y
ANSWERS
Note: The install options may change in future versions of the script.
Usage: bash wireguard.sh [options]
Options:
--addclient [client name] add a new client
--dns1 [DNS server IP] primary DNS server for new client (optional, default: Google Public DNS)
--dns2 [DNS server IP] secondary DNS server for new client (optional)
--listclients list the names of existing clients
--removeclient [client name] remove an existing client
--showclientqr [client name] show QR code for an existing client
--uninstall remove WireGuard and delete all configuration
-y, --yes assume "yes" as answer to prompts when removing a client or removing WireGuard
-h, --help show this help message and exit
Install options (optional):
--auto auto install WireGuard using default or custom options
--serveraddr [DNS name or IP] server address, must be a fully qualified domain name (FQDN) or an IPv4 address
--port [number] port for WireGuard (1-65535, default: 51820)
--clientname [client name] name for the first WireGuard client (default: client)
--dns1 [DNS server IP] primary DNS server for first client (default: Google Public DNS)
--dns2 [DNS server IP] secondary DNS server for first client
To customize options, you may also run this script without arguments.
Community
- 📬 Get project updates and free deployment guides (1–2 emails/month)
- 💬 Join the r/selfhostedstack community for discussions
- ⭐ Star the repository if you find it useful — it helps others discover it
Next steps
After setup, you can run the script again to manage users or uninstall WireGuard.
Get your computer or device to use the VPN. Please refer to:
Configure WireGuard VPN Clients
Read 📘 VPN book to access extra content.
Enjoy your very own VPN! :sparkles::tada::rocket::sparkles:
Credits
This script is based on the great work of Nyr and contributors, with enhancements and changes for compatibility with the Setup IPsec VPN project.
- Improved compatibility with Setup IPsec VPN
- Improved script reliability, user input and output
- Supports auto install using default or custom options
- Supports using a DNS name as server address
- Added support for openSUSE Linux
- Supports listing existing VPN clients
- Supports showing QR code for a client
- Supports custom DNS server(s) for VPN clients
- Supports command-line options for managing VPN clients
- Optimizes
sysctlsettings for improved VPN performance - Improved creation of client config files when using
sudo
...and more!
License
MIT