【ConoHa VPS】簡単にOpenVPNサーバーを構築する方法

ConoHa VPSで簡単にOpenVPNサーバーを構築する方法についてまとめました。

スポンサーリンク

OpenVPNサーバーを構築

● アカウント画面からサーバー追加を選択し、以下の設定でサーバーを構築します。

リージョン 東京
OS CentOS 7.7

● VPSサーバーを作成したら、サーバーのIPアドレスを確認します。

● SSHでサーバーにログインします。

ssh root@ -p 22

● フィンガープリントの確認を求められたら[yes]を選択します。

● パスワードの入力を求められたら、サーバー作成時に設定したrootパスワードを入力します。

● ログインしたら、以下のコマンドを実行します。

wget https://raw.githubusercontent.com/Angristan/openvpn-install/master/openvpn-install.sh -O openvpn-install.sh && bash openvpn-install.sh

● いくつか質問されるので、回答の一例を以下に示します。

IP address: [VPSのグローバルIPが表示される] → [Enter]

(IPv6を有効にしますか?)
Do you want to enable IPv6 support (NAT)? [y/n] :  → n

(OpenVPNのポートはどうしますか?)
What port do you want OpenVPN to listen to?
   1) Default: 1194
   2) Custom
   3) Random [49152-65535]
Port choice [1-3]:  → 1

(UDPとTCPのどちらを使いますか?UDPが使える場合はUDPを選んでください)
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] : 1

 (どのDNSを使いますか?)
What DNS resolvers do you want to use with the VPN?
DNS [1-12]: 9

(圧縮を有効にしますか?)
Enable compression?  [y/n]: n

(暗号化の設定を変更しますか)
Customize encryption settings? [y/n]: n

(続けるならなにかキーを押してください)
Press any key to continue... → Enter押す

これで、OpenVPNのインストールと初期設定が開始されるのでしばらく待つ

(作成するクライアント名はどうしますか?)
Tell me a name for the client.
Use one word only, no special characters.
Client name : TestVPN(任意の名前でOK)

(設定ファイルをパスワード保護しますか?):
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 (パスワード保護なし)

● これで[Enter]を押すと、以下の表示が出てきてOpenVPNのインストールと設定は完了です。

The configuration file has been written to /root/TestVPN.ovpn.
Download the .ovpn file and import it in your OpenVPN client.

接続用ファイル(/root/TestVPN.ovpn)が作成されているので、SFTPクライアントソフト等でサーバーからダウンロードします。
めんどくさい場合は、Catコマンドで接続用ファイル(/root/TestVPN.ovpn)を開いて中身をコピペして同じファイル名でローカルに保存します。
あとは、OpenVPNクライアントソフトでTestVPN.ovpnを読み込ませればVPNサーバーに接続できます。

参考サイト様:OpenVPNサーバーを5分で立ち上げる方法

スポンサーリンク

クライアントを追加

ライアントを複数作成(追加)したい場合は、「openvpn-install.sh 」を再び実行し先ほどと同じようにクライアントを追加してovpnファイルを作成します。

bash openvpn-install.sh

(どうしますか?)
What do you want to do?
   1) Add a new user
   2) Revoke existing user
   3) Remove OpenVPN
   4) Exit
Select an option [1-4]: 1 ← 新規ユーザー追加を選択

(作成するクライアント名はどうしますか?)
Tell me a name for the client.
Use one word only, no special characters.
Client name : TestVPN2(任意の名前でOK)

(設定ファイルをパスワード保護しますか?):
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 (パスワード保護なし)
スポンサーリンク

VPNサーバーの設定ファイル

「/etc/openvpn/server.conf」にVPNサーバーの設定が書き込まれています。

port 1194
proto udp
dev tun
user nobody
group nogroup
persist-key
persist-tun
keepalive 10 120
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
push "redirect-gateway def1 bypass-dhcp"
dh none
ecdh-curve prime256v1
tls-crypt tls-crypt.key
crl-verify crl.pem
ca ca.crt
cert server_cKiCiG9XlKqWunzq.crt
key server_cKiCiG9XlKqWunzq.key
auth SHA256
cipher AES-128-GCM
ncp-ciphers AES-128-GCM
tls-server
tls-version-min 1.2
tls-cipher TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256
client-config-dir /etc/openvpn/ccd
status /var/log/openvpn/status.log
verb 3
スポンサーリンク

クライアント間の接続を有効化

OpenVPNの初期設定では、クライアント間の接続はできません。
「client-to-client」を設定ファイル(/etc/openvpn/server.conf)に追記すると接続可能になります。「」を入れると、同一LAN上のマシン同士のイメージで接続できるようになります。

● /etc/openvpn/server.conf

port 1194
proto udp
dev tun

(略)

client-to-client
【Mac入門】基本設定、使い方、カスタマイズ術
macOSの基本設定、使い方、カスタマイズ術について解説します。
コンピュータ
スポンサーリンク

コメント