*OpenVPN [#d4842728]

RIGHT:更新日&lastmod();

**インストール [#of1fa316]

OpenVPNをトンネルをトンネルモードでインストール。2つのネットワークのサブネットが異なる設定
OpenVPNをトンネルをトンネルモードでインストール。2つのネットワークのサブネットが異なる設定~
NetA(Client)からVPNに接続、NetBは(Server)は常にVPNに接続

 (10.0.0.0/8) === VPN(192.168.33.0/24) === (192.168.31.0/24)
 A(10.0.0.0/8) === VPN(192.168.33.0/24) === B(192.168.31.0/24)

OpenSSLの確認
 # rpm -q openssl
 openssl-1.0.0j-1vl6.x86_64

openvonのインストール
 # apt-get install openvpn


CentOSでは以下のことが必要かも

[[RPMforgeリポジトリを導入>http://centossrv.com/rpmforge.shtml]]して、標準リポジトリで提供されないパッケージをyumでインストールできるようにする

-64bitでは以下のファイルを導入した( uname -a で確認)(CentOS 5.8)

 # rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

-CentOS6の場合

 # yum -y install yum-plugin-priorities
 # wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

-CentOS5の場合

 # yum -y install yum-priorities
 # wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

以下のことが成り立つためにyum-plugin-prioritiesまたは yum-prioritiesをインストールしておく

''/etc/yum.repos.d/CentOS-Base.repo''に追加「[centosplus]」以降はenabled=0なので関係ないと思うが、 priority=1の追加で、priorityを設定することで同じパッケージがあった場合に、優先順位が高いほうが優先される。priorityは数値で1〜99を設定するが、数値が大きいほど「優先順位は低い」

 [base]
 name=CentOS-$releasever - Base
 mirrorlist=http://mirrorlist.centos.org/? release=$releasever&arch=$basearch&repo=os
 #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
 gpgcheck=1
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
 priority=1   <==追加
 
 #released updates
 [updates]
 (略)
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
 priority=1   <==追加
 
 #released updates
 [extras]
 (略)
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
 priority=1   <==追加
 
 #additional packages that extend functionality of existing packages
 [centosplus]
 name=CentOS-$releasever - Plus
 (略)
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
 priority=1   <==追加
 
 #contrib - packages by Centos Users
 [contrib]
 name=CentOS-$releasever - Contrib
 (略)
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
 priority=1   <==追加



**設定 [#v86ae830]

 # cd /etc/openvpn
 # cp /usr/share/doc/openvpn-2.1.3/sample-config-files/server.conf .
 
 # cp -a /usr/share/openvpn/easy-rsa .

-プライベートCAの構築とCA証明書・秘密鍵の作成


 # cd easy-rsa/2.0/

以下を修正

以下の最後の行あたりを修正

''vars''

 # generation process.
 ##export KEY_SIZE=1024
 export KEY_SIZE=2048

最後の行あたり
 export KEY_COUNTRY="JP"
 export KEY_PROVINCE="MIE"
 export KEY_CITY="MEIWA"
 export KEY_ORG="TEST"
 export KEY_EMAIL="okada@ism21.net"


''/etc/openvpn/easy-rsa/2.0''で

 # source ./vars
 NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/2.0/keys

以下のコマンドは証明書/鍵作成先ディレクトリ初期化~
※OpenVPNインストール後最初の1回のみ

 # ./clean-all


-認証局の作成
 # ./build-ca
 Generating a 1024 bit RSA private key
 .............................++++++
 .....................................++++++
 writing new private key to 'ca.key'
 -----
 You are about to be asked to enter information that will be incorporated
 into your certificate request.
 What you are about to enter is what is called a Distinguished Name or a DN.
 There are quite a few fields but you can leave some blank
 For some fields there will be a default value,
 If you enter '.', the field will be left blank.
 -----
 Country Name (2 letter code) [JP]: <= Enter
 State or Province Name (full name) [MIE]: <= Enter
 Locality Name (eg, city) [MEIWA]: <= Enter
 Organization Name (eg, company) [TEST]: <= Enter
 Organizational Unit Name (eg, section) []: <= Enter
 Common Name (eg, your name or your server's hostname) [TEST CA]: <= Enter
 Name []: <= Enter
 Email Address [okada@ism21.net]: <= Enter

-作成ファイル
 # ls -l keys
 合計 12
 -rw-r--r-- 1 root root 1155  9月 11 14:54 ca.crt  <=出来ているファイル
 -rw------- 1 root root  916  9月 11 14:54 ca.key  <=出来ているファイル
 -rw-r--r-- 1 root root    0  9月 11 14:53 index.txt
 -rw-r--r-- 1 root root    3  9月 11 14:53 serial


-サーバ証明書・サーバ秘密鍵の作成
サーバ秘密鍵を作成し、先ほど構築したプライベートCAで署名

 #  ./build-key-server server
 Generating a 1024 bit RSA private key
 .........................++++++
 .++++++
 writing new private key to 'server.key'
 -----
 You are about to be asked to enter information that will be incorporated
 into your certificate request.
 What you are about to enter is what is called a Distinguished Name or a DN.
 There are quite a few fields but you can leave some blank
 For some fields there will be a default value,
 If you enter '.', the field will be left blank.
 -----
 Country Name (2 letter code) [JP]: <= Enter
 State or Province Name (full name) [MIE]: <= Enter
 Locality Name (eg, city) [MEIWA]: <= Enter
 Organization Name (eg, company) [TEST]: <= Enter
 Organizational Unit Name (eg, section) []: <= Enter
 Common Name (eg, your name or your server's hostname) [server]:
 Name []: <= Enter
 Email Address [okada@ism21.net]: <= Enter
 
 Please enter the following 'extra' attributes
 to be sent with your certificate request
 A challenge password []: <= Enter
 An optional company name []: <= Enter
 Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
 Check that the request matches the signature
 Signature ok
 The Subject's Distinguished Name is as follows
 countryName           :PRINTABLE:'JP'
 stateOrProvinceName   :PRINTABLE:'MIE'
 localityName          :PRINTABLE:'MEIWA'
 organizationName      :PRINTABLE:'TEST'
 commonName            :PRINTABLE:'server'
 emailAddress          :IA5STRING:'okada@ism21.net'
 Certificate is to be certified until Sep  9 05:57:54 2022 GMT (3650 days)
 Sign the certificate? [y/n]:y <= y Enter 
 
 
 1 out of 1 certificate requests certified, commit? [y/n]y <= y Enter
 Write out database with 1 new entries
 Data Base Updated


-確認

以下のようにファイルが増えているserver.crtとserver.keyは確認すること

 # ls -l keys
 合計 40
 -rw-r--r-- 1 root root 3761  9月 11 14:58 01.pem
 -rw-r--r-- 1 root root 1155  9月 11 14:54 ca.crt
 -rw------- 1 root root  916  9月 11 14:54 ca.key
 -rw-r--r-- 1 root root   95  9月 11 14:58 index.txt
 -rw-r--r-- 1 root root   21  9月 11 14:58 index.txt.attr
 -rw-r--r-- 1 root root    0  9月 11 14:53 index.txt.old
 -rw-r--r-- 1 root root    3  9月 11 14:58 serial
 -rw-r--r-- 1 root root    3  9月 11 14:53 serial.old
 -rw-r--r-- 1 root root 3761  9月 11 14:58 server.crt  <=出来ているファイル
 -rw-r--r-- 1 root root  655  9月 11 14:57 server.csr
 -rw------- 1 root root  916  9月 11 14:57 server.key  <=出来ているファイル


-クライアント証明書・クライアント秘密鍵の作成
***クライアント証明書・クライアント秘密鍵の作成(ユーザ用証明書作成) [#p27ca7f4]

ここではsample1として1クライアントを作成、クライアントの人数に応じて作成する

/etc/openvpn/easy-rsa/2.0で

 # source ./build-key-pass sample1
以前に実行されて場合は

 # source ./vars

を実行

 # ./build-key-pass sample1
 Generating a 1024 bit RSA private key
 ...++++++
 .............................................................++++++
 writing new private key to 'sample1.key'
 Enter PEM pass phrase:******   (1)
 Verifying - Enter PEM pass phrase:********
 -----
 You are about to be asked to enter information that will be incorporated
 into your certificate request.
 What you are about to enter is what is called a Distinguished Name or a DN.
 There are quite a few fields but you can leave some blank
 For some fields there will be a default value,
 If you enter '.', the field will be left blank.
 -----
 Country Name (2 letter code) [JP]:
 State or Province Name (full name) [MIE]:
 Locality Name (eg, city) [MEIWA]:
 Organization Name (eg, company) [TEST]:
 Organizational Unit Name (eg, section) []:
 Common Name (eg, your name or your server's hostname) [sample1]:
 Name []:
 Email Address [okada@ism21.net]:
 
 Please enter the following 'extra' attributes
 to be sent with your certificate request
 A challenge password []:
 An optional company name []:
 Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
 Check that the request matches the signature
 Signature ok
 The Subject's Distinguished Name is as follows
 countryName           :PRINTABLE:'JP'
 stateOrProvinceName   :PRINTABLE:'MIE'
 localityName          :PRINTABLE:'MEIWA'
 organizationName      :PRINTABLE:'TEST'
 commonName            :PRINTABLE:'sample1'
 emailAddress          :IA5STRING:'okada@ism21.net'
 Certificate is to be certified until Sep  9 06:03:01 2022 GMT (3650 days)
 Sign the certificate? [y/n]:y
 
 
 1 out of 1 certificate requests certified, commit? [y/n]y
 Write out database with 1 new entries
 Data Base Updated

''&color(red){エラーの場合};

 failed to update database 
 TXT_DB error number 2 
 
前に作成したクライアント証明書と鍵のコモンネームが重複している可能性がある

TXT_DBファイル(index.txt)ファイルがあり、1行1証明書の形式で生成した証明書・鍵に関する情報が追加されていく。問題が出たクライアント証明書のコモンネームで該当する行を見つけた場合、その行をindex.txtファイルから削除することでエラーは回避できる。

 V       221003003423Z           01      unknown /C=JP/ST=MIE/L=Matsusaka/O=Ootsuji \
 Clinic/CN=gw/emailAddress=okada@acb-c.com
 V       221003003508Z           02      unknown /C=JP/ST=MIE/L=Matsusaka/O=Ootsuji \
 Clinic/CN=okada/emailAddress=okada@abc-c.com \  
 V       221003003546Z           03                unknown /C=JP/ST=MIE/L=Matsusaka/O=Ootsuji <=たとえばここを削除  
 Clinic/CN=ootsuji/emailAddress=ootsuji@abc-c.com \
 R       221003005115Z   121005005139Z   04      unknown /C=JP/ST=MIE/L=Matsusaka/O=Ootsuji \
 Clinic/CN=dummy/emailAddress=okada@abc-c.com



-TXT_DBファイル(index.txt)…証明書・鍵のコモンネームを管理しているデータベースファイル
-属性ファイル(index.txt.attr)…属性ファイル
-項番ファイル(serial)…データベースに追加する際の次の番号を記録しているファイル



-確認

 # ls -l keys
 合計 64
 -rw-r--r-- 1 root root 3761  9月 11 14:58 01.pem
 -rw-r--r-- 1 root root 3645  9月 11 15:03 02.pem
 -rw-r--r-- 1 root root 1155  9月 11 14:54 ca.crt
 -rw------- 1 root root  916  9月 11 14:54 ca.key
 -rw-r--r-- 1 root root  191  9月 11 15:03 index.txt
 -rw-r--r-- 1 root root   21  9月 11 15:03 index.txt.attr
 -rw-r--r-- 1 root root   21  9月 11 14:58 index.txt.attr.old
 -rw-r--r-- 1 root root   95  9月 11 14:58 index.txt.old
 -rw-r--r-- 1 root root 3645  9月 11 15:03 sample1.crt
 -rw-r--r-- 1 root root  655  9月 11 15:03 sample1.csr
 -rw------- 1 root root 1041  9月 11 15:03 sample1.key
 -rw-r--r-- 1 root root    3  9月 11 15:03 serial
 -rw-r--r-- 1 root root    3  9月 11 14:58 serial.old
 -rw-r--r-- 1 root root 3761  9月 11 14:58 server.crt <=出来ているファイル
 -rw-r--r-- 1 root root  655  9月 11 14:57 server.csr
 -rw------- 1 root root  916  9月 11 14:57 server.key <=出来ているファイル


-サーバで使用するDH(Diffie-Hellman)[鍵交換方式]パラメータを生成。

デフォルトでは1024bitなので2048で作成

''1024bit''
 # ./build-dh
 Generating DH parameters, 1024 bit long safe prime, generator 2
 This is going to take a long time
 .........................................................................++*++*++*

''2048bit''

''vars''内の以下を変更 

 # generation process.
 export KEY_SIZE=1024

または

 # openssl dhparam -out dh2048.pem 2048
 Generating DH parameters, 2048 bit long safe prime, generator 2
 This is going to take a long time
 ..........................................................................................




-CA証明書、サーバ証明書、サーバ秘密鍵、DHパラメータを/etc/openvpn/にコピー


 # cp keys/ca.crt /etc/openvpn/
 # cp keys/server.crt /etc/openvpn/
 # cp keys/server.key /etc/openvpn/
 # cp keys/dh1024.pem /etc/openvpn/



上記のファイル名を以下のファイルの中身を確認

''/etc/openvpn/server.conf''

&color(red){conquestでK-PACSとの接続はイメージ送信時にudpだと転送に失敗するようでだ};

 # TCP or UDP server?
 proto tcp
 ;;proto udp

 # On most systems, the VPN will not function
 # unless you partially or fully disable
 # the firewall for the TUN/TAP interface.
 ;dev tap <=L2レベルのトンネル(ブリッジなどような場合tap0を指定するようだ)
 dev tun  <=トンネルモードを指定(IPレベル)

 # Any X509 key management system can be used.
 # OpenVPN can also use a PKCS #12 formatted key file
 # (see "pkcs12" directive in man page).
 ca ca.crt <=確認
 cert server.crt  <=確認
 key server.key   <=確認 # This file should be kept secret

 # Diffie hellman parameters.
 # Generate your own with:
 #   openssl dhparam -out dh1024.pem 1024
 # Substitute 2048 for 1024 if you are using
 # 2048 bit keys.
 ;dh dh1024.pem  
 dh dh2048.pem 


以下のように指定するとVPNネットワークが192.168.33.0/24でサーバのVPN側のIPは
192.168.33.1になる。
192.168.33.1になる。~
自動的にDHCPサーバ機能も有効となるようだ。~
(192.168.33.0/24が割り振られる)~
後で設定するクライアント固定IPにはぶつからないようだ(未確認)

 # on 10.8.0.1. Comment this line out if you are
 # ethernet bridging. See the man page for more info.
 ;server 10.8.0.0 255.255.255.0
 server 192.168.33.0 255.255.255.0


以下の設定でクライアント側にrouteを設定する。192.168.31.0/24はVPN側のインターフェイス側にあることを設定できる。

Active Routes:~
Network Destination     Netmask          Gateway       Interface  Metric~
192.168.31.0     255.255.255.0    192.168.33.22   192.168.33.21       1~
                 ^^^^^^^^^^^^^   ^^^^^^^^^^^^^~
                 VPN 側GW        VPNのIPアドレス~

のようなrouteが追加される

 # to know to route the OpenVPN client
 # address pool (10.8.0.0/255.255.255.0)
 # back to the OpenVPN server.
 ;push "route 192.168.10.0 255.255.255.0"
 ;push "route 192.168.20.0 255.255.255.0"
 push "route 192.168.31.0 255.255.255.0"
 push "route 192.168.33.0 255.255.255.0"



実行アクセス権を下げる
 # You can uncomment this out on
 # non-Windows systems.
 ;user nobody
 ;group nobody
 user nobody
 group nobody


-TLS化認証を有効化

/etc/openvpn/にkeyを作成

 # openvpn --genkey --secret /etc/openvpn/ta.key

''server.conf''
 # The second parameter should be '0'
 # on the server and '1' on the clients.
 ;tls-auth ta.key 0 # This file is secret
 tls-auth ta.key 0 # This file is secret

最後パラメータ 0:サーバ側  1:クライアント側

-logの作成

 ;log-append  openvpn.log
 log-append  /var/log/openvpn.log

***対称鍵 : AES(256bit) [#y7b4cb4f]

 cipher AES-256-CBC

を追加。

クライアント側のconfigファイルにも必要

デフォルトではOpenVPNがBlowfish128ビット対称暗号方式を用いる。以下はクライアントのログ

-サーバ、クライアント両方128bit
 Wed Sep 19 11:26:20 2012 VERIFY OK:
 depth=1, /C=JP/ST=MIE/L=MEIWA/O=TEST/CN=TEST_CA/emailAddress=okada@ism21.net
 Wed Sep 19 11:26:20 2012 VERIFY OK: nsCertType=SERVER
 Wed Sep 19 11:26:20 2012 VERIFY OK:
 depth=0, /C=JP/ST=MIE/L=MEIWA/O=TEST/CN=server/emailAddress=okada@ism21.net
 Wed Sep 19 11:26:22 2012 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
 Wed Sep 19 11:26:22 2012 Data Channel Encrypt: Using 160 bit message
 hash 'SHA1' for HMAC authentication
 Wed Sep 19 11:26:22 2012 Data Channel Decrypt: Cipher 'BF-CBC' initialized  with 128 bit key
 Wed Sep 19 11:26:22 2012 Data Channel Decrypt: Using 160 bit message 
 hash 'SHA1' for HMAC authentication


-サーバ側が256bitでクライアントが128bit時のアラーム
 Wed Sep 19 11:24:18 2012 VERIFY OK:  
 depth=1, /C=JP/ST=MIE/L=MEIWA/O=TEST/CN=TEST_CA/emailAddress=okada@ism21.net
 Wed Sep 19 11:24:18 2012 VERIFY OK: nsCertType=SERVER
 Wed Sep 19 11:24:18 2012 VERIFY OK: 
 depth=0, /C=JP/ST=MIE/L=MEIWA/O=TEST/CN=server/emailAddress=okada@ism21.net
 
 Wed Sep 19 11:24:20 2012 WARNING: 'link-mtu' is used inconsistently, 
 local='link-mtu 1544', remote='link-mtu 1560'
 Wed Sep 19 11:24:20 2012 WARNING: 'cipher' is used inconsistently, 
 local='cipher BF-CBC', remote='cipher AES-256-CBC'
 Wed Sep 19 11:24:20 2012 WARNING: 'keysize' is used inconsistently, 
 local='keysize 128', remote='keysize 256'

-両方256bitのとき
 Wed Sep 19 11:52:20 2012 VERIFY OK: 
 depth=1, /C=JP/ST=MIE/L=MEIWA/O=TEST/CN=TEST_CA/emailAddress=okada@ism21.net
 Wed Sep 19 11:52:20 2012 VERIFY OK: nsCertType=SERVER
 Wed Sep 19 11:52:20 2012 VERIFY OK: 
 depth=0, /C=JP/ST=MIE/L=MEIWA/O=TEST/CN=server/emailAddress=okada@ism21.net
 Wed Sep 19 11:52:21 2012 Data Channel Encrypt: Cipher 'AES-256-CBC' 
 initialized with 256 bit key
 Wed Sep 19 11:52:21 2012 Data Channel Encrypt: Using 160 bit message  
 hash 'SHA1' for HMAC authentication
 Wed Sep 19 11:52:21 2012 Data Channel Decrypt: Cipher 'AES-256-CBC' 
 initialized with 256 bit key
 Wed Sep 19 11:52:21 2012 Data Channel Decrypt: Using 160 bit message  
 hash 'SHA1' for HMAC authentication
 Wed Sep 19 11:52:21 2012 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-
 AES256-SHA, 1024 bit RSA



***固定IPをクライアントに設定 [#tfab2d89]

''/etc/openvpn/server.conf''

 # EXAMPLE: Suppose the client
 # having the certificate common name "Thelonious"
 # also has a small subnet behind his connecting
 # machine, such as 192.168.40.128/255.255.255.248.
 # First, uncomment out these lines:
 ;client-config-dir ccd
 client-config-dir ccd  <=コメント削除
 ;route 192.168.40.128 255.255.255.248


ccdディレクトリ作成

 # mkdir /etc/openvpn/ccd

sample1として1クライアントを作成した場合は

ccdの下にsample1というファイルを作成し

 ifconfig-push 192.168.33.21 192.168.33.22

の一行追加すると

192.168.33.21が割り振られる


ifconfig-push 192.168.33.x 192.168.33.y

x=4n+1, y=4n+2のルールがあるようだ。それ以外では接続できなかった。

また以下ようにすると指定クライアントにrouteが追加される

***証明書廃止リスト作成 [#e49b47f3]
 push "route 192.168.202.0 255.255.255.0"

-その他のパラメータ(server.conf)

 client-to-client       ←OpenVPNクライアント同士の通信を許可(サーバのみ設定)
 keepalive 10 120       ←サーバ・クライアント間の死活監視の設定

***証明書廃止リスト作成 (ユーザの証明書の廃止)[#e49b47f3]

廃止リストファイルcrl.pem を作成しておきserver.conf の最後に

 crl-verify crl.pem 

を追加しておく

crl.pem作成のためdummyを作成し、廃棄する


 # cd /etc/openvpn/easy-rsa
 # cd /etc/openvpn/easy-rsa/2.0
 # source ./vars
 NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/2.0/keys
 # ./build-key dummy
 (すべて Enter)

''openssl.cnf'' 以下をコメントアウト
''/etc/openvpn/easy-rsa/2.0/openssl.cnf'' 以下をコメントアウト

 ##[ pkcs11_section ]
 ##engine_id = pkcs11
 ##dynamic_path = /usr/lib/engines/engine_pkcs11.so
 ##MODULE_PATH = $ENV::PKCS11_MODULE_PATH
 ##PIN = $ENV::PKCS11_PIN
 ##init = 0

-廃棄
 # ./revoke-full dummy
 Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
 Revoking Certificate 04.
 Data Base Updated
 Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf 
 dummy.crt: C = JP, ST = MIE, L = Matsusaka, O = Ootsuji Clinic, CN = dummy, 
 emailAddress = okada@ootsuji-c.com
 error 23 at 0 depth lookup:certificate revoked



-廃棄(上記をコメントアウトしないとき)

 # ./revoke-full dummy
 Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
 unable to load certificate
 139693420025512:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:696:Expecting: TRUSTED CERTIFICATE
 Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
 unable to load certificate
 140523615540904:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:696:Expecting: TRUSTED CERTIFICATE


 # cp /etc/openvpn/easy-rsa/2.0/keys/crl.pem /etc/openvpn/

新しい廃棄を行うごとにcrl.pem が出来るので/etc/openvpn/にコピーする
削除したユーザを復旧するときは以前のcrl.pem を書き戻せばOK

openvpnの再起動は不要だが、すでに接続済ユーザは再接続するまで切れないようだ。
そのためにも再起動したほうが良いようだ。

ただ、再起動すると未廃棄ユーザも一度切れるので再接続が費用になるようだ。
運用を考える



***IPのルーティング [#n4ba2507]

ここまでVPNがルーティングVPN (dev tun)として接続できる。IPで接続をコントロールする


 (自分のLAN 10.0.0.0/8)
 ----------------------
 | Client             |
 |             VPN IP | 192.168.33.21     VPN Client GW 192.168.33.22
 |                    |-----------------------------|
 |                    |                             |
 |                    |                             |
 ----------------------                             |
                                                    |
                                                    |
                                                    |
 ----------------------                   VPN Server|GW 192.168.33.2
 |VPN Server          |                             |
 |             VPN IP | 192.168.33.1                |
 |                    |------------------------------
 |                 IP | | 182.236.42.XX(eth0)
 |                    | | 192.168.31.8(eth0:1)
 |                    | |
 ---------------------- |
                        |
                        |eth0 192.168.31.14
           ----------------------------
           |   Data Server            |
           |                          |
           ----------------------------
           |   Data Server            | Defalut GW 192.168.31.1
           |                          |そのため 192.168.33.0/24は192.168.31.8に
           ----------------------------route addされている

上のような構成のときClientのIPアドレスでDataServerに接続する場合は
Data ServerにはいかのようにRoute addの必要がある

 C:\Windows\system32>route add 192.168.33.0 mask 255.255.255.0 192.168.31.8 metric 1

クライアント側にはVPNサーバのserver.confに
 push "route 192.168.31.0 255.255.255.0"
があるので接続Route addされる


あとはVPNServerがパケットを転送する必要があるので

 # echo 1 > /proc/sys/net/ipv4/ip_forward

***Windows client [#abf25e6b]
**Windows client [#abf25e6b]

[[ここ>http://openvpn.jp/openvpn-gui-jp.html]]からDownload.

OpenVPN\configにサーバで作成した/etc/openvpn/easy-rsa/2.0/keys/のca.crt、sample1.crt、sample1.key、ta.keyをコピー。~
OpenVPN\sample-config\client.ovpnもここにコピー

''client.ovpn''

host名とポートを指定
 remote 182.236.42.23 1194

 ca ca.crt
 cert sample1.crt
 key sample1.key

 # then every client must also have the key.
 ;tls-auth ta.key 1
 tls-auth ta.key 1


を修正


後は起動してタスクトレイから接続

接続時のパスワードはクライアントの証明書作成(# source ./build-key-pass sample1)に入力したもの(1)
接続時のパスワードはクライアントの証明書作成(# ./build-key-pass sample1)に入力したもの(1)


&color(red){vista,7については管理者権限で起動しないとサーバ側のserver.confで指定したpush "route 192.168.31.0 255.255.255.0"のroute追加が権限上の問題で追加されない。また、vistaではクライアント側の設定ファイルclient.ovpn等に以下の2行をファイル末尾に追加の必要があるかもしれない};

 route-method exe
 route-delay 2

***起動時スケジューラで動かす [#sf811afc]

コマンドプロンプトが最小化でタスクバーに残り、これを削除すると接続が切れる

''openvpn.bat''
 @echo off
 c:\usr\OpenVPN\bin\openvpn.exe --config c:\Usr\OpenVPN\config\okada2.ovpn

''openvpn.vbs''
 Set objWSHShell = CreateObject("WScript.Shell")
 objWSHShell.Run "C:\Usr\OpenVPN\bin\openvpn.bat", 7

を作成し、スケジューラに''openvpn.vbs''を登録

-トリガー:ログオン時
-全般:最上位の特権で実行する




**Linux Client [#c856ab3c]

# apt-get install openvpn

でインストール後

/etc/openvpn

に、Windowsと同様にca.crt、linuxuser.crt 、linuxuser.key 、ta.keyをサーバ側からコピー

''linuxuser.conf''をWindowsと同じ用に作成

 client
 proto tcp
 dev tun
 remote my-disk.stock-cube.net 1194
 ca /etc/openvpn/ca.crt
 cert /etc/openvpn/linuxuser.crt
 key /etc/openvpn/linuxuser.key
 tls-auth /etc/openvpn/ta.key 1
 ns-cert-type server
 resolv-retry infinite
 nobind
 comp-lzo LZO圧縮の利用
 persist-key 再接続を行う設定
 persist-tun 再接続を行う設定


***起動 [#z7e14127]

 # /usr/sbin/openvpn /etc/openvpn/linuxuser.conf


&color(red){Windowsでは問題ないようだが、Linuxでは時間がサーバと一致していないと以下のようなエラーで接続できない};

 VERIFY ERROR: depth=1, error=certificate is not yet valid:

***パスワードを聞かれないためには [#h1a806a1]

 # openssl rsa -in linuxuser.key -out linuxuser.key
 Enter pass phrase for linuxuser.key:******
 writing RSA key

とすればOK。Windowsにも同じkeyファイルを渡せばOKなようだ



***iptablesについて [#ka35bb7b]

VPNサーバ上でudpまたはtcpでserver.confで指定したportを通過させるデフォルトは

 port 1194

**参考 [#m32fa21a]

-http://linux-story.seesaa.net/article/193524147.html

-http://kilin.clas.kitasato-u.ac.jp/howto/openvpn.html

-http://centossrv.com/openvpn.shtml

-http://jehupc.exblog.jp/14096411/

-http://freescitech.net/2/ovpn2_howto_ja.html

''VPN比較表''

-http://jp.giganews.com/vyprvpn/compare-vpn-protocols.html


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS