SolarisでOpenVPN(2)
昨日はインストールまでだったので、今日は設定あたりを。
PKIの構築
サーバ側の証明書、秘密鍵を作成します。作成するためのスクリプトがソースディレクトリ直下にあります。
$ cd openvpn-2.0.9/easy-rsa/ $ ls 2.0 build-inter build-req openssl.cnf README build-key build-req-pass revoke-crt Windows build-key-pass clean-all revoke-full build-ca build-key-pkcs12 list-crl sign-req build-dh build-key-server make-crl vars
このディレクトリごとどこかシステム的なところにコピーします。今回は/usr/local/etc以下にopenvpnというディレクトリをつくって、そこへコピーしました。
# mkdir /usr/local/etc/openvpn # cp -pr ~/openvpn/openvpn-2.0.9/easy-rsa /usr/local/etc/openvpn
CA証明書と秘密鍵作成
自己認証でいくのでまずCA証明書と秘密鍵を生成します。スクリプトでopensslを使っているのでそこへのパスを通してあげる必要があります。このディレクトリにあるbuild-caスクリプトをつかってCA証明書が作成できます。
# cd /usr/local/etc/openvpn/easy-rsa # . ./vars # export PATH=$PATH:/usr/local/ssl/bin # ./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) [KG]:JP State or Province Name (full name) [NA]:Tokyo Locality Name (eg, city) [BISHKEK]:HogeHoge Organization Name (eg, company) [OpenVPN-TEST]:HogeHoge Company Organizational Unit Name (eg, section) []:Hoge Division Common Name (eg, your name or your server's hostname) []:OpenVPN-CA Email Address [me@myhost.mydomain]:
これでCA証明書とCA秘密鍵ができるはず。
# cd keys # ls -l ca.* # ls -l ca.* -rw-r--r-- 1 root other 1484 5月 23日 16:54 ca.crt -rw------- 1 root other 891 5月 23日 16:54 ca.key
サーバ証明書と秘密鍵作成
続いてサーバ証明書と秘密鍵を作成します。build-key-serverスクリプトをつかって作成できます。
# ./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) [KG]:JP State or Province Name (full name) [NA]:Tokyo Locality Name (eg, city) [BISHKEK]:HogeHoge Organization Name (eg, company) [OpenVPN-TEST]:HogeHoge Company Organizational Unit Name (eg, section) []:Hoge Division Common Name (eg, your name or your server's hostname) []:server Email Address [me@myhost.mydomain]: 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/openssl.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'JP' stateOrProvinceName :PRINTABLE:'Hoge' localityName :PRINTABLE:'HogeHoge' organizationName :PRINTABLE:'Hoge Company' organizationalUnitName:PRINTABLE:'Hoge Division' commonName :PRINTABLE:'server' emailAddress :IA5STRING:'me@myhost.mydomain' Certificate is to be certified until May 20 08:52:05 2017 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
# cd keys # ls server.* server.crt server.csr server.key
Diffie-Helmanパラメータ作成
Diffie-Helmanパラメータを作成します。サーバとクライアントで鍵を交換するときに使うものみたい。ちゃんと勉強しないとだめだなぁ。
# ./build-dh Generating DH parameters, 1024 bit long safe prime, generator 2 This is going to take a long time ..............................+.................................... (略)
設定ファイルを作成する
OpenVPNサーバが起動するときに参照する設定ファイルを作成します。サンプルがソースディレクトリ以下のsample-config-fileディレクトリにあるので、これを利用して必要なところを変更します。
# cp ~/openvpn/openvpn-2.0.9/sample-config-file/server.conf /usr/local/etc
変更すべきところは、ca,cert,key,dhのところ。それぞれCA証明書ファイルの場所、サーバ証明書の場所、サーバ秘密鍵の場所、DHパラメータの場所を指定します。自環境ではこんなかんじ。
ca /usr/local/etc/easy-rsa/keys/ca.crt cert /usr/local/etc/easy-rsa/keys/server.crt key /usr/local/etc/easy-rsa/keys/server.key dh /usr/local/etc/easy-rsa/keys/dh1024.pem
それと、VPNで接続するときに使う仮想IPアドレス空間を設定します。serverで始まる行。コメントをよんでください。自環境ではまだデフォルトのまま使っています。
OpenVPNを起動
とりあえず手動で起動してみます。
# /usr/local/sbin/openvpn /usr/local/etc/openvpn/server.conf Wed May 23 17:59:41 2007 OpenVPN 2.0.9 sparc-sun-solaris2.9 [SSL] [LZO] built on May 22 2007 Wed May 23 17:59:41 2007 Diffie-Hellman initialized with 1024 bit key Wed May 23 17:59:41 2007 TLS-Auth MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ] Wed May 23 17:59:41 2007 TUN/TAP device tun0 opened Wed May 23 17:59:41 2007 /usr/sbin/ifconfig tun0 10.8.0.1 10.8.0.2 mtu 1500 up Wed May 23 17:59:41 2007 /usr/sbin/ifconfig tun0 netmask 255.255.255.255 Wed May 23 17:59:41 2007 /usr/sbin/route add 10.8.0.0 -netmask 255.255.255.0 10.8.0.2 add net 10.8.0.0: gateway 10.8.0.2 Wed May 23 17:59:41 2007 Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:0 EL:0 AF:3/1 ] Wed May 23 17:59:41 2007 UDPv4 link local (bound): [undef]:1194 Wed May 23 17:59:41 2007 UDPv4 link remote: [undef] Wed May 23 17:59:41 2007 MULTI: multi_init called, r=256 v=256 Wed May 23 17:59:41 2007 IFCONFIG POOL: base=10.8.0.4 size=62 Wed May 23 17:59:41 2007 IFCONFIG POOL LIST Wed May 23 17:59:41 2007 Initialization Sequence Completed
Initialization Sequence Completedとなったら、ちゃんと起動できているみたいです。
起動スクリプトは書かないとね。
98/100
- 作者: 森鴎外
- 出版社/メーカー: 岩波書店
- 発売日: 2002/10/16
- メディア: 文庫
- クリック: 17回
- この商品を含むブログ (25件) を見る
知らない単語がたくさん。辞書引きながら読みました。
餉(かれい)、鱗(いろづく)、ははそ(作るのにんべんがきへん)、鳥目(ちょうもく)などなど。
安寿と厨子王って聞いたことはあったけれども、ここが出典だったのか。知らなかった。