几秒钟内即可托管您自己的 OpenVPN 服务器
披露:本帖包含 ExpressVPN 和 Vultr 的附属链接。
托管自己的 VPN 从未如此简单。现在有多个 Github 项目可以减轻您设置 VPN 服务器的麻烦。
在我们开始安装 VPN 之前,让我们先讨论一下什么是 VPN 以及它如何帮助我们。
什么是 VPN?
VPN ,即虚拟专用网络,是 VPN 客户端和 VPN 服务器之间的网络。这种网络的优势在于完全加密,VPN 客户端的整个网络流量都将通过加密隧道传输。
VPN 客户端永远不会直接访问其他(Web)服务器,所有内容都将从 VPN 服务器请求,并且 VPN 服务器将转发请求。
为什么我要托管自己的 VPN 服务器?
拥有自己的 VPN 意味着您可以完全控制它,并且只有您才能读取服务器的日志。
以下是 VPN 可以发挥作用的一些用例:
- 隐藏您的真实IP地址
- 在公共 Wi-Fi 中安全上网
- 访问VPN服务器网络内的服务
为什么我不应该托管自己的 VPN 服务器?
如果您想访问位于不同位置的多个服务器,您应该从知名提供商(例如ExpressVPN或NordVPN)购买 VPN 。这些提供商在不同国家/地区拥有大量 VPN 服务器。
托管您的VPN服务器
我正在使用Vultr上托管的 Ubuntu 18.04.3 LTS 服务器
本教程也适用于 Debian、Ubuntu 和 CentOS
为了在几秒钟内安装我们的 VPN 服务器,我们使用了由Nyr创建的名为openvpn-install的 shell 脚本。
OpenVPN 安装
wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh
脚本会询问你如何设置 VPN 服务器。按 Enter 键使用默认选项(通常也是推荐的选项)。
我只将默认 DNS 更改为使用1.1.1.1
Welcome to this OpenVPN road warrior installer!
I need to ask you a few questions before starting setup.
You can use the default options and just press enter if you are ok with them.
Which protocol do you want for OpenVPN connections?
1) UDP (recommended)
2) TCP
Protocol [1]:
What port do you want OpenVPN listening to?
Port [1194]:
Which DNS do you want to use with the VPN?
1) Current system resolvers
2) 1.1.1.1
3) Google
4) OpenDNS
5) Verisign
DNS [1]: 2
Finally, tell me a name for the client certificate.
Client name [client]:
Okay, that was all I needed. We are ready to set up your OpenVPN server now.
Press any key to continue...
该脚本现在将在您的服务器上安装 OpenVPN。
添加新用户
安装完成后,您需要制作openvpn-install.sh
可执行文件。
chmod +x openvpn-install.sh
要添加新用户,只需再次运行脚本,选择 1,然后输入要使用此客户端证书的设备名称。在本例中,我为我的 iPhone 创建了一个用户。
./openvpn-install.sh
Looks like OpenVPN is already installed.
What do you want to do?
1) Add a new user
2) Revoke an existing user
3) Remove OpenVPN
4) Exit
Select an option: 1
Tell me a name for the client certificate.
Client name: iphone
Using SSL: openssl OpenSSL 1.1.1 11 Sep 2018
Can't load /etc/openvpn/server/easy-rsa/pki/.rnd into RNG
140236248433088:error:2406F079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:88:Filename=/etc/openvpn/server/easy-rsa/pki/.rnd
Generating a RSA private key
................................+++++
.................+++++
writing new private key to '/etc/openvpn/server/easy-rsa/pki/private/iphone.key.BnNBhJXQKm'
-----
Using configuration from ./safessl-easyrsa.cnf
Can't load /etc/openvpn/server/easy-rsa/pki/.rnd into RNG
140374526300608:error:2406F079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:88:Filename=/etc/openvpn/server/easy-rsa/pki/.rnd
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'iphone'
Certificate is to be certified until Jan 19 18:31:07 2030 GMT (3650 days)
Write out database with 1 new entries
Data Base Updated
Client iphone added, configuration is available at: /root/iphone.ovpn
从服务器检索 .ovpn 文件
在 macOS 和 Linux 上,您可以使用 将文件从服务器复制到您的计算机scp
。在 Windows 上,最好下载Filezilla或WinSCP并使用 SFTP 登录服务器。
要复制文件,请scp
运行以下命令:
scp <USERNAME>@<SERVER_IP>:/root/<CLIENT>.ovpn .
示例如下:
scp root@123.45.67.89:/root/iphone.ovpn .
如果证书是用于智能手机的,请务必使用安全介质进行复制。对于 Mac 和 iPhone,建议使用 AirDrop 复制 .ovpn 文件。
如果您必须使用电子邮件,请在发送之前压缩 .ovpn 文件并为 zip 文件设置一个强密码。
Using the .ovpn file
On macOS you can use the app Tunnelblick, on Windows there is an official programm from OpenVPN and on iOS and Android there are offical OpenVPN Connect apps on the App Store and Google Play.
Usually the process is the same for every client. You have to import the .ovpn file into the client and connect to the server. If the connection was successful you can type into google "what is my ip address" and Google should show you your current IP address.
If the IP address is the same as the server, you can congratulate yourself! You just set up your (first) self hosted VPN server 🎉
鏂囩珷鏉ユ簮锛�https://dev.to/phiilu/host-your-own-openvpn-server-in-a-few-seconds-73l