GNU/Linux >> Linux の 問題 >  >> Panels >> OpenVPN

OpenVPN-マルチプラットフォームVPN接続でサーバー管理を保護します

OpenVPNは、業界標準のSSL/TLSプロトコルを使用してOSIレイヤー2または3の安全なネットワーク拡張を実装するフル機能のSSLVPNです。証明書、スマートカード、および/またはユーザー名/パスワードクレデンシャルに基づく柔軟なクライアント認証方法をサポートし、VPN仮想インターフェイスに適用されるファイアウォールルールを使用したユーザーまたはグループ固有のアクセス制御ポリシーを許可します。 OpenVPNはWebアプリケーションプロキシではなく、Webブラウザを介して動作しません。

サーバーの準備

このチュートリアルでは、DebianまたはUbuntuサーバーを使用します。すでに本番環境にある任意のサーバーを使用できます。

OpenVPNのインストール

LinuxおよびUNIXサーバーのすべての既知のディストリビューションでは、リポジトリにOpenVPNがあります。インストールは実行するのと同じくらい簡単です:

apt-get install openvpn

ファイアウォール構成

OpenVPNのデフォルトのリスニングポートは1194です。デフォルトのポートを使用しても安全です。 OpenVPNはデフォルトでUDPプロトコルを使用します。これには単純な理由があります:

OpenVPNはレイヤー2と3を使用します

  • レイヤー2は、物理レイヤー上でエラーのないデータフレームの転送を提供するデータリンクレイヤーです。つまり、独自のTUN/TAPネットワークデバイスを使用します。
  • レイヤー3は、ルーティングを提供するネットワークレイヤーです。

これは、レイヤー4(パケット配信を保証するトランスポート層)がOSとアプリケーション自体によって管理されることを意味します。簡単に言うと、トラフィックの制御とパケット配信の制御はOSによって行われるため、OpenVPN自体で2回行う必要はありません。もちろん、OpenVPNにTCPを使用するオプションがあります。これは、より多くのリソースが無駄になることを意味しますが、一部の特別な環境の場合は、便利な場合があります。

要約すると、UDP用にポート1194を開くだけで、VPN接続が可能になります。 OpenVPNには独自の検証と制御が実装されているため、フィルタリングは必要ありません(後のセクションを参照)。次のステートメントをファイアウォール構成に追加します。

-A INPUT -p udp -m udp --dport 1194 -j ACCEPT

サーバー構成

OpenVPNのインストールが正常に完了すると、すべてのOpenVPN構成ファイルが/ etc/openvpnフォルダーにあります。エディターでserver.confファイルを開いて編集しましょう。

nano /etc/openvpn/server.conf

次のセクションを確認して編集します:

# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key).

ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/server.crt
key /etc/openvpn/easy-rsa/keys/server.key # This file should be kept secret

# Diffie hellman parameters.
dh /etc/openvpn/easy-rsa/keys/dh2048.pem

# Configure server mode and supply a VPN subnet
server 10.9.8.0 255.255.255.0

# Push routes to the client
push "route 10.9.8.0 255.255.255.0"

# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
tls-auth /etc/openvpn/easy-rsa/keys/ta.key 0 # This file is secret

# Select a cryptographic cipher.
cipher AES-128-CBC # AES

# Enable compression on the VPN link.
comp-lzo

# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
user vpn
group vpn

内部サブネットとして10.9.8.0/24サブネットを選択したため、クライアントは接続後にこのサブネットからIPアドレスを取得します。デフォルトでは、10.9.8.1はサーバー自体用に予約されています。

証明書の生成

まず、変数を編集する必要があります ファイル。 KEY_COUNTRY、KEY_PROVINCE、KEY_CITY、KEY_ORG、およびKEY_EMAILパラメーターを入力します。これらの値は、新しい証明書を生成するたびに使用されます。

varsファイルをロードするには、次のコマンドを実行します:

./vars

それらをロードした後、認証局を作成できます:

./clean-all
./build-ca

CAが生成されたら、サーバー証明書の生成に進みます。

./build-key-server server

そして、クライアント用のもう1つの証明書:

./build-key client

結局のところ、DHパラメータを生成する必要があります:

./build-dh

セキュリティの強化

OpenVPNサーバーを確実に保護するために、tls-authを使用します。これにより、侵害されたサーバーに証明書を送信することがなくなります。

openvpn –genkey –secret ta.key

このta.keyファイルは、すべてのクライアントの証明書バンドルに含まれている必要があります。

クライアント構成
 ##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
##############################################

# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client

# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun

# Windows needs the TAP-Windows adapter name
# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or
# UDP server? Use the same setting as
# on the server.
;proto tcp
proto udp

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote <your-server-ip> 1194
;remote my-server-2 1194

# Choose a random host from the remote
# list for load-balancing. Otherwise
# try hosts in the order specified.
;remote-random

# Keep trying indefinitely to resolve the
# host name of the OpenVPN server. Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite

# Most clients don't need to bind to
# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nobody

# Try to preserve some state across restarts.
persist-key
persist-tun

# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here. See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca ca.crt
cert client.crt
key client.key

# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server". This is an
# important precaution to protect against
# a potential attack discussed here:
# http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server". The build-key-server
# script in the easy-rsa folder will do this.
;ns-cert-type server

# If a tls-auth key is used on the server
# then every client must also have the key.
tls-auth ta.key 1

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
cipher AES-128-CBC

# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo

# Set log file verbosity.
verb 3

# Silence repeating messages
mute 20 

それをclient.ovpnファイルとして保存し、ta.key、c​​a.crt、client.crt、client.keyを1つのフォルダーに含めます。

openvpnクライアントをコンピューターにインストールし、client.ovpn構成ファイルを実行すると、VPNサーバーに接続できるようになります。その後、設定した10.9.8.0/24の範囲からIPアドレスを取得し、サーバーとプライベートに連携します。


OpenVPN
  1. Debian9でOpenVPNサーバーをセットアップする方法

  2. Dockerを使用してWireguardVPNサーバーをインストールする

  3. CentOS8でLibreswanを使用してIPSecVPNサーバーをセットアップする

  1. OpenVPNを使用してLinuxVPNサーバーをセットアップする–ステップバイステップガイド

  2. VPNを使用したハッキン​​グから電子メールサーバーを保護する方法(Debian / Ubuntu)

  3. VPNを使用したハッキン​​グから電子メールサーバーを保護する方法(CentOS / RHEL)

  1. CentOSとViscosityを使用したOpenVPNサーバーのセットアップ

  2. DD-WRTとViscosityを使用したOpenVPNサーバーのセットアップ

  3. NetgearとViscosityを使用したOpenVPNサーバーのセットアップ