如何在 Debian 11 上安裝 OpenVPN 服務器


本教程將向您展示如何在 Debian 11 上安裝 OpenVPN 服務器。對於那些不知道的人,OpenVPN 是一種用於創建虛擬專用網絡的服務。也就是說,您可以鏈接通過 Internet 連接但不在同一位置的兩個節點。連接到虛擬專用網絡的所有設備的行為就像它們連接到局域網一樣。 通過 VPN 隧道發送的數據包使用 256 位 AES 加密進行加密,以防止數據被盜。

本文假設您至少具有 Linux 的基本知識,知道如何使用 shell,最重要的是,將您的網站託管在您的 VPS 上。安裝非常簡單,假設您在 root 帳戶下運行。如果沒有,您需要添加一個’。sudo‘向命令獲取root權限。 我將分階段向您展示如何在 Debian 11 (Bullseye) 上安裝 OpenVPN 服務器。

在 Debian11 Bullseye 上安裝 OpenVPN 服務器

步驟1。在安裝軟件之前,運行以下命令以確保您的系統是最新的很重要。 apt 終端命令:

sudo apt update
sudo apt upgrade

步驟 2. 在 Debian 11 上安裝 OpenVPN 服務器。

從這裡下載腳本安裝程序 OpenVPN 服務器 GitHub 利用 curl 命令:

curl -O https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh

下載後,賦予腳本執行權限並執行。

chmod +x openvpn-install.sh
sudo ./openvpn-install.sh

系統將提示您輸入一些信息。

Welcome to the OpenVPN installer!
The git repository is available at: https://github.com/angristan/openvpn-install

I need to ask you a few questions before starting the setup.
You can leave the default options and just press enter if you are ok with them.

I need to know the IPv4 address of the network interface you want OpenVPN listening to.
Unless your server is behind NAT, it should be your public IPv4 address.
IP address:

系統將詢問您是否要啟用默認禁用的 IPv6。

Checking for IPv6 connectivity...

Your host appears to have IPv6 connectivity.

Do you want to enable IPv6 support (NAT)? [y/n]: y

默認情況下,OpenVPN 使用端口 1194。如果要使用特定端口,請按 2,然後執行以下操作:

What port do you want OpenVPN to listen to?
   1) Default: 1194
   2) Custom
   3) Random [49152-65535]
Port choice [1-3]: 1

接下來,設置 OpenVPN 使用的協議。

What protocol do you want OpenVPN to use?
UDP is faster. Unless it is not available, you shouldn't use TCP.
   1) UDP
   2) TCP
Protocol [1-2]: 2

現在您需要選擇您的 DNS 提供商。

What DNS resolvers do you want to use with the VPN?
   1) Current system resolvers (from /etc/resolv.conf)
   2) Self-hosted DNS Resolver (Unbound)
   3) Cloudflare (Anycast: worldwide)
   4) Quad9 (Anycast: worldwide)
   5) Quad9 uncensored (Anycast: worldwide)
   6) FDN (France)
   7) DNS.WATCH (Germany)
   8) OpenDNS (Anycast: worldwide)
   9) Google (Anycast: worldwide)
   10) Yandex Basic (Russia)
   11) AdGuard DNS (Anycast: worldwide)
   12) NextDNS (Anycast: worldwide)
   13) Custom
DNS [1-12]: 9

系統將詢問您是否要使用壓縮。系統會通知您不建議這樣做,但選項包括:

Do you want to use compression? It is not recommended since the VORACLE attack make use of it.
Enable compression? [y/n]: n

如果您真的知道如何使用 OpenVPN,您可以自定義加密選項。如果沒有,請不要這樣做。

Do you want to customize encryption settings?
Unless you know what you're doing, you should stick with the default parameters provided by the script.
Note that whatever you choose, all the choices presented in the script are safe. (Unlike OpenVPN's defaults)
See https://github.com/angristan/openvpn-install#security-and-encryption to learn more.

Customize encryption settings? [y/n]: n

然後整個安裝過程就開始了。然後,當您添加新客戶端時,您將看到以下輸出屏幕,您需要在其中定義客戶端名稱。

Okay, that was all I needed. We are ready to setup your OpenVPN server now.
You will be able to generate a client at the end of the installation.
Press any key to continue...

Tell me a name for the client.
The name must consist of alphanumeric character. It may also include an underscore or a dash.
Client name: idroot

然後將詢問您是否要使用密碼保護配置文件。

Do you want to protect the configuration file with a password?
(e.g. encrypt the private key with a password)
   1) Add a passwordless client
   2) Use a password for the client
Select an option [1-2]: 1

最後,您將被通知該過程已成功。

Client idroot added.

The configuration file has been written to /home/user/idroot.ovpn.
Download the .ovpn file and import it in your OpenVPN client.

安裝完成後,只需下載它。 idroot.ovpn 創建一個文件並將其複製到客戶端,以便您可以使用以下命令從 Connection Manager GUI 或通過終端進行連接:

openvpn [openvpnfile]

步驟 3. 配置您的防火牆。

默認情況下,OpenVPN 使用端口 1194。您需要打開所需的端口 1194。

sudo ufw allow 1194
sudo ufw enable

恭喜! OpenVPN 現已成功安裝。感謝您使用本教程在 Debian 11 Bullseye 上安裝最新版本的 OpenVPN 服務器。我們鼓勵您查看更多幫助和有用信息。 OpenVPN官網..