OpenVPN
https://openvpn.net/
OpenVPN を使ってインターネットから自宅のサーバネットワークにセキュアに接続してみました。

機器 構成
VPN サーバ - Raspberry Pi 2
- Ubuntu 14.04 (ARM)
- OpenVPN 2.3.2
Linux クライアント - Ubutu GNOME 15.10 (x86_64)
- GNOME Shell 3.17.4
Android クライアント - Android 4.4.2
- OpenVPN アプリ

VPN サーバの設定

はじめにRaspbery Pi はRTC(Real Time Clock)を持っていないので、ntp で時刻同期をしておきます。

/etc/ntp.conf
#server 0.ubuntu.pool.ntp.org iburst
#server 1.ubuntu.pool.ntp.org iburst
#server 2.ubuntu.pool.ntp.org iburst
#server 3.ubuntu.pool.ntp.org iburst
pool ntp.nict.jp iburst

必要なパッケージをインストールして、認証局用のディレクトリを作成します。

$ sudo apt-get install openvpn libssl-dev openssl easy-rsa
$ sudo su
# make-cadir /etc/openvpn/easy-rsa
# cd /etc/openvpn/easy-rsa

設定ファイルvars を編集します。

/etc/openvpn/easy-rsa/vars
export KEY_COUNTRY="JP"
export KEY_PROVINCE="MyProvince"
export KEY_CITY="MyCity"
export KEY_ORG="MyOrg"
export KEY_EMAIL="MyEmail"
export KEY_OU="MyOU"

認証局、VPN サーバおよびクライアント用の証明書等を作成します。

# source vars && ./clean-all && ./build-ca
# ./build-key-server server
# ./build-key client1
# ./build-dh
# cd keys
# openvpn --genkey --secret ta.key
# cp ca.crt ta.key dh2048.pem server.crt server.key /etc/openvpn/
# cd /etc/openvpn/
# cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
# gzip -d /etc/openvpn/server.conf.gz

VPN サーバの設定ファイルserver.conf を編集します。VPN サーバのローカルアドレスは192.168.0.6/24 です。

before after
dh dh1024.pem dh dh2048.pem
push “route 192.168.0.0 255.255.255.0”
;push “redirect-gateway def1 bypass-dhcp” push “redirect-gateway def1 bypass-dhcp”
push “dhcp-option DNS 192.168.0.1”
;client-to-client client-to-client
;tls-auth ta.key 0 # This file is secret tls-auth ta.key 0 # This file is secret
;user nobody user nobody
;group nogroup group nogroup
;log openvpn.log log /var/log/openvpn.log
mode server
tls-server

OpenVPN サービスを再起動します。

# service openvpn restart

Linux クライアントの設定

接続用のパッケージをインストールします。

sudo apt-get install network-manager network-manager-openvpn network-manager-openvpn-gnome

VPN サーバ上のサンプルファイル/usr/share/doc/openvpn/examples/sample-config-files/client.confをコピーして、client1.ovpnを作成します。

before after
remote my-server-1 1194 remote (VPN サーバのFQDN or IP アドレス) 1194
cert client.crt cert client1.crt
key client.key key client1.key
;tls-auth ta.key 1 tls-auth ta.key 1

VPN サーバ上の以下のファイルを安全な方法でクライアントに転送します。

  • /etc/openvpn/easy-rsa/keys/ca.crt
  • /etc/openvpn/easy-rsa/keys/ta.key
  • /etc/openvpn/easy-rsa/keys/client1.crt
  • /etc/openvpn/easy-rsa/keys/client1.key

設定ファイルをインポートします。

$ gnome-control-center network
  1. + を選択
  2. VPN を選択
  3. Import from file... を選択し、client1.ovpn を取り込みます。

Android クライアントの設定

PC と同様にclient2.ovpn を作成し、OpenVPN アプリで取り込みます。