2022-10-10 05:22:08 +02:00
|
|
|
|
[English](README.md) | [中文](README-zh.md) | [Vídeo en Español](https://www.youtube.com/watch?v=99qtaJU2E2k)
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2022-05-26 05:56:33 +02:00
|
|
|
|
# WireGuard VPN 服务器一键安装脚本
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2022-10-05 01:07:17 +02:00
|
|
|
|
[![Build Status](https://github.com/hwdsl2/wireguard-install/actions/workflows/main.yml/badge.svg)](https://github.com/hwdsl2/wireguard-install/actions/workflows/main.yml) [![License: MIT](docs/images/license.svg)](https://opensource.org/licenses/MIT)
|
|
|
|
|
|
2023-09-14 07:17:20 +02:00
|
|
|
|
使用 Linux 脚本一键快速搭建自己的 WireGuard VPN 服务器。支持 Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS, Fedora, openSUSE 和 Raspberry Pi OS。
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2022-05-28 22:19:10 +02:00
|
|
|
|
该脚本可让你在几分钟内建立自己的 VPN 服务器,即使你以前没有使用过 WireGuard。[WireGuard](https://www.wireguard.com) 是一种快速且现代的 VPN,其设计目标是易于使用和高性能。
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2023-04-24 06:55:14 +02:00
|
|
|
|
另见:[OpenVPN](https://github.com/hwdsl2/openvpn-install/blob/master/README-zh.md) 和 [IPsec VPN](https://github.com/hwdsl2/setup-ipsec-vpn/blob/master/README-zh.md) 服务器一键安装脚本。
|
2023-04-10 00:29:12 +02:00
|
|
|
|
|
2023-08-26 06:36:24 +02:00
|
|
|
|
**[» :book: Book: 搭建自己的 VPN 服务器分步指南](https://books2read.com/vpnguidezh)**
|
2022-10-11 08:32:08 +02:00
|
|
|
|
|
2022-10-15 05:07:42 +02:00
|
|
|
|
## 功能特性
|
2022-10-11 08:32:08 +02:00
|
|
|
|
|
2022-10-15 05:07:42 +02:00
|
|
|
|
- 全自动的 WireGuard VPN 服务器配置,无需用户输入
|
|
|
|
|
- 支持使用自定义选项进行交互式安装
|
|
|
|
|
- 生成 VPN 配置文件以自动配置 Windows, macOS, iOS 和 Android 设备
|
|
|
|
|
- 支持管理 WireGuard VPN 用户
|
|
|
|
|
- 优化 `sysctl` 设置以提高 VPN 性能
|
2022-05-26 05:56:33 +02:00
|
|
|
|
|
|
|
|
|
## 安装说明
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2022-10-15 05:07:42 +02:00
|
|
|
|
首先在你的 Linux 服务器\* 上下载脚本:
|
2022-10-01 22:36:59 +02:00
|
|
|
|
|
|
|
|
|
```bash
|
2022-10-03 06:17:30 +02:00
|
|
|
|
wget -O wireguard.sh https://get.vpnsetup.net/wg
|
2022-10-10 05:22:08 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**选项 1:** 使用默认选项自动安装 WireGuard。
|
|
|
|
|
|
|
|
|
|
```bash
|
2022-10-01 22:36:59 +02:00
|
|
|
|
sudo bash wireguard.sh --auto
|
|
|
|
|
```
|
|
|
|
|
|
2022-10-15 05:07:42 +02:00
|
|
|
|
<details>
|
|
|
|
|
<summary>
|
|
|
|
|
查看脚本的示例输出(终端记录)。
|
|
|
|
|
</summary>
|
|
|
|
|
|
2022-10-25 07:21:31 +02:00
|
|
|
|
**注:** 此终端记录仅用于演示目的。
|
2022-10-15 05:07:42 +02:00
|
|
|
|
|
|
|
|
|
<p align="center"><img src="docs/images/demo1.svg"></p>
|
|
|
|
|
</details>
|
2022-10-03 06:17:30 +02:00
|
|
|
|
|
2023-09-13 06:00:02 +02:00
|
|
|
|
对于有外部防火墙的服务器(比如 [EC2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html)/[GCE](https://cloud.google.com/firewall/docs/firewalls)),请为 VPN 打开 UDP 端口 51820。
|
2022-10-03 06:17:30 +02:00
|
|
|
|
|
2022-10-01 22:36:59 +02:00
|
|
|
|
**选项 2:** 使用自定义选项进行交互式安装。
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo bash wireguard.sh
|
|
|
|
|
```
|
|
|
|
|
|
2023-09-14 07:17:20 +02:00
|
|
|
|
你可以自定义以下选项:VPN 服务器的域名,UDP 端口,VPN 客户端的 DNS 服务器以及第一个客户端的名称。
|
|
|
|
|
|
|
|
|
|
对于有外部防火墙的服务器,请为 VPN 打开所选的 UDP 端口。
|
2023-09-12 06:27:45 +02:00
|
|
|
|
|
2022-05-28 22:19:10 +02:00
|
|
|
|
<details>
|
|
|
|
|
<summary>
|
2022-10-10 05:22:08 +02:00
|
|
|
|
如果无法下载,请点这里。
|
2022-05-28 22:19:10 +02:00
|
|
|
|
</summary>
|
|
|
|
|
|
2022-06-03 15:29:35 +02:00
|
|
|
|
你也可以使用 `curl` 下载:
|
|
|
|
|
|
2022-05-28 22:19:10 +02:00
|
|
|
|
```bash
|
2022-10-03 06:17:30 +02:00
|
|
|
|
curl -fL -o wireguard.sh https://get.vpnsetup.net/wg
|
2022-05-28 22:19:10 +02:00
|
|
|
|
```
|
|
|
|
|
|
2022-10-10 05:22:08 +02:00
|
|
|
|
然后按照上面的说明安装。
|
|
|
|
|
|
2022-09-20 05:54:10 +02:00
|
|
|
|
或者,你也可以使用这些链接:
|
2022-06-03 15:29:35 +02:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
https://github.com/hwdsl2/wireguard-install/raw/master/wireguard-install.sh
|
2022-09-20 05:54:10 +02:00
|
|
|
|
https://gitlab.com/hwdsl2/wireguard-install/-/raw/master/wireguard-install.sh
|
2022-06-03 15:29:35 +02:00
|
|
|
|
```
|
|
|
|
|
|
2022-05-28 22:19:10 +02:00
|
|
|
|
如果无法下载,打开 [wireguard-install.sh](wireguard-install.sh),然后点击右边的 `Raw` 按钮。按快捷键 `Ctrl/Cmd+A` 全选,`Ctrl/Cmd+C` 复制,然后粘贴到你喜欢的编辑器。
|
|
|
|
|
</details>
|
2022-11-02 05:52:06 +01:00
|
|
|
|
<details>
|
|
|
|
|
<summary>
|
|
|
|
|
高级:使用自定义选项自动安装。
|
|
|
|
|
</summary>
|
|
|
|
|
|
|
|
|
|
高级用户可以使用自定义选项自动安装 WireGuard,方法是提供一个 Bash "here document" 作为安装脚本的输入。此方法还可用于在安装后提供输入以管理用户。
|
|
|
|
|
|
|
|
|
|
首先,使用自定义选项以交互方式安装 WireGuard,并写下你对脚本的所有输入值。
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo bash wireguard.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如需删除 WireGuard,请再次运行脚本并选择适当的选项。
|
|
|
|
|
|
|
|
|
|
然后使用你的输入值创建自定义安装命令。例如:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
sudo bash wireguard.sh <<ANSWERS
|
2023-09-13 06:00:02 +02:00
|
|
|
|
n
|
2022-11-02 05:52:06 +01:00
|
|
|
|
51820
|
|
|
|
|
client
|
|
|
|
|
2
|
|
|
|
|
y
|
|
|
|
|
ANSWERS
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**注:** 安装选项可能会在脚本的未来版本中发生变化。
|
|
|
|
|
</details>
|
2022-05-28 22:19:10 +02:00
|
|
|
|
|
2022-06-02 16:09:51 +02:00
|
|
|
|
\* 一个云服务器,虚拟专用服务器 (VPS) 或者专用服务器。
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2022-06-02 16:09:51 +02:00
|
|
|
|
## 下一步
|
2022-05-22 05:46:20 +02:00
|
|
|
|
|
2022-06-02 16:09:51 +02:00
|
|
|
|
安装完成后,你可以再次运行脚本来管理用户或者卸载 WireGuard。
|
|
|
|
|
|
2022-10-03 06:17:30 +02:00
|
|
|
|
配置你的计算机或其它设备使用 VPN。请参见:
|
|
|
|
|
|
|
|
|
|
**[配置 WireGuard VPN 客户端](docs/clients-zh.md)**
|
2022-06-02 16:09:51 +02:00
|
|
|
|
|
2023-08-11 06:16:21 +02:00
|
|
|
|
**阅读 [:book: VPN book](https://ko-fi.com/post/Support-this-project-and-get-access-to-supporter-o-X8X5FVFZC) 以访问 [额外内容](https://ko-fi.com/post/Support-this-project-and-get-access-to-supporter-o-X8X5FVFZC)。**
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2023-07-01 23:58:12 +02:00
|
|
|
|
开始使用自己的专属 VPN! :sparkles::tada::rocket::sparkles:
|
2022-07-14 05:07:44 +02:00
|
|
|
|
|
2022-05-26 05:56:33 +02:00
|
|
|
|
## 致谢
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2022-05-24 15:39:32 +02:00
|
|
|
|
此脚本基于 [Nyr 和 contributors](https://github.com/Nyr/wireguard-install) 的出色工作,并进行了增强和更改以与 [Setup IPsec VPN](https://github.com/hwdsl2/setup-ipsec-vpn) 项目兼容。
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
2022-09-20 05:54:10 +02:00
|
|
|
|
<details>
|
|
|
|
|
<summary>
|
|
|
|
|
对 Nyr/wireguard-install 的改进列表。
|
|
|
|
|
</summary>
|
|
|
|
|
|
|
|
|
|
- 改进了与 Setup IPsec VPN 的兼容性
|
|
|
|
|
- 改进了脚本的可靠性,用户输入和输出
|
2022-10-01 22:36:59 +02:00
|
|
|
|
- 支持使用默认选项自动安装
|
2023-09-12 06:27:45 +02:00
|
|
|
|
- 支持使用域名作为服务器地址
|
|
|
|
|
- 增加了对 openSUSE Linux 的支持
|
2022-09-26 05:53:24 +02:00
|
|
|
|
- 支持列出现有的 VPN 客户端
|
2022-09-20 07:11:10 +02:00
|
|
|
|
- 支持为 VPN 客户端自定义 DNS 服务器
|
2022-09-20 05:54:10 +02:00
|
|
|
|
- 优化 `sysctl` 设置以提高 VPN 性能
|
|
|
|
|
- 使用 `sudo` 时改进了客户端配置文件的创建
|
|
|
|
|
|
|
|
|
|
...和更多!
|
|
|
|
|
</details>
|
|
|
|
|
|
2022-05-26 05:56:33 +02:00
|
|
|
|
## 授权协议
|
2022-05-22 05:10:28 +02:00
|
|
|
|
|
|
|
|
|
MIT
|