本教程將向您展示如何在 Debian 11 上安裝 OpenVPN 服務器。對於那些不知道的人,OpenVPN 是一種用於創建虛擬專用網絡的服務。這意味著您可以鏈接兩個通過 Internet 連接但不在同一位置的節點。連接到虛擬專用網絡的所有設備的行為就像它們連接到局域網一樣。 通過 VPN 隧道發送的數據包使用 256 位 AES 加密進行加密,以防止數據被盜。
本文假設您至少具有 Linux 的基本知識,知道如何使用 shell,最重要的是,您在自己的 VPS 上託管您的網站。 假設您在 root 帳戶下運行,安裝非常簡單。sudo
‘ 到命令以獲得 root 權限。 在 Debian 11 (Bullseye) 上安裝 OpenVPN 服務器的分步說明。
在 Debian 11 Bullseye 上安裝 OpenVPN 服務器
步驟1。在安裝任何軟件之前,請務必通過運行以下命令來確保您的系統是最新的: apt
終端中的命令:
sudo apt update sudo apt upgrade
步驟 2. 在 Debian 11 上安裝 OpenVPN 服務器。
從這裡下載腳本安裝程序 OpenVPN Server。 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官網.