如何在 Debian 9 Stretch 上安裝 OpenVPN


本教程將向您展示如何在 Debian 9 Stretch 上安裝 OpenVPN。對於那些不知道的人,OpenVPN 是一種廣泛使用的開源應用程序,用於在不安全的公共互聯網上創建安全的虛擬專用網絡。 OpenVPN 是一種 SSL VPN 解決方案,可通過 Internet 安全地排出系統連接。 OpenVPN 在客戶端-服務器結構上工作。連接到虛擬專用網絡的所有設備的行為就像它們連接到局域網一樣。 通過 VPN 隧道發送的數據包使用 256 位 AES 加密進行加密,以防止數據被盜。

本文假設您至少具有 Linux 的基本知識,知道如何使用 shell,最重要的是,您在自己的 VPS 上託管您的網站。 假設您在 root 帳戶下運行,安裝非常簡單。sudo‘ 到命令以獲得 root 權限。 我將逐步向您展示如何在 Debian 9 (Stretch) 服務器上安裝 OpenVPN。

在 Debian 9 Stretch 上安裝 OpenVPN

步驟1。在安裝任何軟件之前,請務必通過運行以下命令來確保您的系統是最新的: apt-get 終端中的命令:

apt-get update
apt-get upgrade

步驟 2. 在 Debian 9 上安裝 OpenVPN。

注意:本教程使用 IP 地址。例如,公網 IP 為 216.58.197.67。

首先,下載 Debian 的 OpenVPN road Warriors 安裝程序。

wget https://git.io/vpn -O openvpn-install.sh

下載後,運行 OpenVPN-install.sh 腳本來安裝和配置 OpenVPN 服務器。

bash openvpn-install.sh

系統將提示您輸入 IP 地址、端口等。 將 IP 地址更改為您的公共 IP 地址。

Welcome to this quick OpenVPN "road warrior" installer

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

First I need to know the IPv4 address of the network interface you want OpenVPN
listening to.
IP address: 216.58.197.67

Which protocol do you want for OpenVPN connections?
 1) UDP (recommended)
 2) TCP
Protocol [1-2]: 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) Google
 3) OpenDNS
 4) NTT
 5) Hurricane Electric
 6) Verisign
DNS [1-6]: 2

Finally, tell me your name for the client certificate
Please, use one word only, no special characters
Client name: idroot-openvpn

Okay, that was all I needed. We are ready to setup your OpenVPN server now
Press any key to continue...

此時,您的 OpenVPN 服務器已準備就緒。您現在可以檢查防火牆規則。

cat /etc/rc.local

示例輸出:

#!/bin/sh -e
iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -I FORWARD -s 10.8.0.0/24 -j ACCEPT
iptables -I INPUT -p udp --dport 1194 -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to 139.59.105.37
exit 0

然後啟用並啟動 OpenVPN 服務。

## start service ##
systemctl start [email protected]

## stop service ##
systemctl stop [email protected]

## check status ##
systemctl status [email protected]

現在您可以下載 ovpn 配置文件。該文件用於連接服務器。 您可以使用 SCP 命令執行此操作。

scp [email protected]:~/idroot-openvpn.ovpn /home/godet/Desktop

恭喜! 您已成功安裝 OpenVPN。感謝您使用本教程在您的 Debian 9 Stretch 服務器上安裝 OpenVPN。如需更多幫助或有用信息,我們建議您查看 OpenVPN官網.