tun
(IP レベルトンネル用) と tap
(イーサネットレベルトンネル用) インターフェースをサポートします。実際には、VPN クライアントをイーサネットブリッジ経由でサーバのローカルネットワークに参加させる場合を除いて、tun
インターフェースが最もよく使われます。
openssl
コマンドを使うスクリプト群として実装されています。
$
make-cadir pki-falcot
$
cd pki-falcot
vars
file, which can be uncommented and edited:
$
vim vars
$
grep EASYRSA vars
export KEY_CONFIG=`$EASY_RSA/whichopensslcnf $EASY_RSA` export KEY_DIR="$EASY_RSA/keys" echo NOTE: If you run ./clean-all, I will be doing a rm -rf on $KEY_DIR export KEY_SIZE=2048 export KEY_EXPIRE=3650 export KEY_COUNTRY="FR" export KEY_PROVINCE="Loire" export KEY_CITY="Saint-Étienne" export KEY_ORG="Falcot Corp" export KEY_EMAIL="admin@falcot.com" export KEY_OU="Certificate authority" export KEY_NAME="Certificate authority for Falcot Corp" # If you'd like to sign all keys with the same Common Name, uncomment the KEY_CN export below # export KEY_CN="CommonName" $
keys/ca.crt
と keys/ca.key
に保存されます)。
pki/ca.crt
and pki/private/ca.key
during this step). We can add the option nopass
to avoid entering a password each time the private key is used:
$
./easyrsa build-ca nopass
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 Generating RSA private key, 2048 bit long modulus (2 primes) ......................................................................................+++++ ......................+++++ e is 65537 (0x010001) 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. ----- Common Name (eg: your user, host, or server name) [Easy-RSA CA]: CA creation complete and you may now import and sign cert requests. Your new CA certificate file for publishing is at: /home/roland/pki-falcot/pki/ca.crt
vpn.falcot.com
で識別されます。ここで指定した DNS 名は作成される鍵ファイルの名前としても使われます (keys/vpn.falcot.com.crt
は公開鍵証明書、keys/vpn.falcot.com.key
は秘密鍵です)。
$
./easyrsa gen-req vpn.falcot.com nopass
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 Generating a RSA private key .................................................................................+++++ ........+++++ writing new private key to '/home/roland/pki-falcot/pki/private/vpn.falcot.com.key.E5c3RGJBUd' ----- 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. ----- Common Name (eg: your user, host, or server name) [vpn.falcot.com]: Keypair and certificate request completed. Your files are: req: /home/roland/pki-falcot/pki/reqs/vpn.falcot.com.req key: /home/roland/pki-falcot/pki/private/vpn.falcot.com.key $
./easyrsa sign-req server vpn.falcot.com
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 You are about to sign the following certificate. Please check over the details shown below for accuracy. Note that this request has not been cryptographically verified. Please be sure it came from a trusted source or that you have verified the request checksum with the sender. Request subject, to be signed as a server certificate for 1080 days: subject= commonName = vpn.falcot.com Type the word 'yes' to continue, or any other input to abort. Confirm request details:
yes
Using configuration from /home/roland/pki-falcot/pki/safessl-easyrsa.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows commonName :ASN.1 12:'vpn.falcot.com' Certificate is to be certified until Jun 14 10:44:44 2022 GMT (1080 days) Write out database with 1 new entries Data Base Updated Certificate created at: /home/roland/pki-falcot/pki/issued/vpn.falcot.com.crt $./easyrsa gen-dh
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 Generating DH parameters, 2048 bit long safe prime, generator 2 This is going to take a long time […] DH parameters of size 2048 created at /home/roland/pki-falcot/pki/dh.pem
$
./build-key JoeSmith
Note: using Easy-RSA configuration from: ./vars Using SSL: openssl OpenSSL 1.1.1b 26 Feb 2019 Generating a RSA private key ....+++++ ..............................+++++ writing new private key to '/home/roland/pki-falcot/pki/private/JoeSmith.key.mY21iP8ysv' ----- 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. ----- Common Name (eg: your user, host, or server name) [JoeSmith]: Keypair and certificate request completed. Your files are: req: /home/roland/pki-falcot/pki/reqs/JoeSmith.req key: /home/roland/pki-falcot/pki/private/JoeSmith.key
pki/ca.crt
) will be stored on all machines (both server and clients) as /etc/ssl/certs/Falcot_CA.crt
. The server's certificate is installed only on the server (pki/issued/vpn.falcot.com.crt
goes to /etc/ssl/vpn.falcot.com.crt
, and pki/private/vpn.falcot.com.key
goes to /etc/ssl/private/vpn.falcot.com.key
with restricted permissions so that only the administrator can read it), with the corresponding Diffie-Hellman parameters (pki/dh.pem
) installed to /etc/openvpn/dh.pem
. Client certificates are installed on the corresponding VPN client in a similar fashion.
/etc/openvpn/*.conf
. Setting up a VPN server is therefore a matter of storing a corresponding configuration file in this directory. A good starting point is /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz
, which leads to a rather standard server. Of course, some parameters need to be adapted: ca
, cert
, key
and dh
need to describe the selected locations (respectively, /etc/ssl/certs/Falcot_CA.crt
, /etc/ssl/vpn.falcot.com.crt
, /etc/ssl/private/vpn.falcot.com.key
and /etc/openvpn/dh.pem
). The server 10.8.0.0 255.255.255.0
directive defines the subnet to be used by the VPN; the server uses the first IP address in that range (10.8.0.1
) and the rest of the addresses are allocated to clients.
tun0
という名前の仮想ネットワークインターフェースが作成されます。しかしながら、ファイアウォールは OpenVPN の開始前に実ネットワークインターフェースと同時に設定される場合が多いです。このため、永続的な仮想ネットワークインターフェースを作成し、OpenVPN が事前に作成された仮想インターフェースを使うように設定することを推奨します。この追加的設定により、インターフェースの名前を選ぶことが可能になります。この目的を達成するには、openvpn --mktun --dev vpn --dev-type tun
を使って tun
型の vpn
と名付けられた仮想ネットワークインターフェースを作成します。さらに、このコマンドをファイアウォール設定スクリプトの中で使えば、簡単に設定を統合できます。つまり /etc/network/interfaces
ファイルの up
指示文を使います。OpenVPN 設定ファイルをファイアウォール設定に対応させるためには dev vpn
と dev-type tun
指示文を使います。
10.8.0.1
アドレスの VPN サーバにアクセスできるだけです。クライアントをローカルネットワーク (192.168.0.0/24) へアクセスできる状態にするには、push route 192.168.0.0 255.255.255.0
指示文を OpenVPN 設定に追加します。こうすることで、VPN クライアントは自動的にネットワーク経路を取得し、VPN 経由でローカルネットワークに到達できるようになります。さらに、ローカルネットワークにいるマシンに対して VPN サーバに通じる VPN への経路を知らせる必要もあります (VPN サーバがゲートウェイにインストールされている場合、これは自動的に動きます)。別の方法として、VPN サーバが IP マスカレードを動かすように設定する方法があります。そうすれば、VPN クライアントからの接続はあたかもクライアントが VPN サーバからアクセスしたかのように見えます (第 10.1 節「ゲートウェイ」を参照してください)。
/etc/openvpn/
に設定ファイルを置きます。標準的な設定の良い足掛かりとして /usr/share/doc/openvpn/examples/sample-config-files/client.conf
が用意されています。remote vpn.falcot.com 1194
指示文は OpenVPN サーバのアドレスとポート番号を表します。さらに ca
、cert
、key
も鍵ファイルの場所に合わせて設定が必要です。
AUTOSTART
directive to none
in the /etc/default/openvpn
file. Starting or stopping a given VPN connection is always possible with the commands systemctl start openvpn@name
and systemctl stop openvpn@name
(where the connection name matches the one defined in /etc/openvpn/name.conf
).
tun*
) を作り、仮想インターフェースをあたかも物理インターフェースのように設定することが可能です。このトンネルシステムを有効化するにはまず、SSH サーバの設定ファイル (/etc/ssh/sshd_config
) の中で PermitTunnel
を「yes」に設定しなければいけません。SSH 接続を確立する際には、-w any:any
オプションを使って明示的にトンネルの作成を要求しなければいけません (ここで any
は必要な tun
デバイス番号で置き替えます)。トンネルを作成するには、サーバおよびクライアント側でそのユーザが管理者権限を持っていることが必要です。そうすればネットワークデバイスを作成することが可能です (言い換えれば、接続は root で確立されなければいけません)。
/etc/ipsec-tools.conf
にはホストが接続する IPsec トンネル (IPsec 用語で Security Association) のパラメータが含まれます。/etc/init.d/setkey
スクリプトを使うことで、トンネルを開始したり停止することが可能です (それぞれのトンネルは仮想ネットワークに接続された他のホストと安全なリンクを確立しています)。このファイルは setkey(8) マニュアルページに含まれる文書を使って手作業で作ることも可能です。しかしながら、多数のマシン群にすべてのホスト用のパラメータを明示的に書くことはすぐに難しい作業になります。なぜなら、トンネルの数はすぐに増えるからです。たとえば racoon や strongswan などの IKE (IPsec Key Exchange の略語) デーモンをインストールすることで、一元管理による作業の簡素化と鍵の定期的な切り替えによる作業の安全化が可能になります。
/etc/ppp/options.pptp
、/etc/ppp/peers/falcot
、/etc/ppp/ip-up.d/falcot
、/etc/ppp/ip-down.d/falcot
を作成しました。
例 10.3 /etc/ppp/peers/falcot
ファイル
# vpn.falcot.com は PPTP サーバです pty "pptp vpn.falcot.com --nolaunchpppd" # "vpn" ユーザで本人確認して接続します user vpn remotename pptp # 暗号化を有効にします require-mppe-128 file /etc/ppp/options.pptp ipparam falcot
pptpd
は Linux 用の PPTP サーバです。主設定ファイル /etc/pptpd.conf
にはいくつかの変更が必要です。すなわち localip (ローカル IP アドレス) と remoteip (リモート IP アドレス) を変更する必要があります。以下の例では、PPTP サーバは常に 192.168.0.199
アドレスを使い、PPTP クライアントは 192.168.0.200
から 192.168.0.250
までの IP アドレスを受け取ります。
例 10.6 /etc/pptpd.conf
ファイル
# TAG: speed # # PPTP デーモンの通信速度を指定します。 # speed 115200 # TAG: option # # PPP オプションファイルの場所を指定します。 # PPP はデフォルトで '/etc/ppp/options' を使います # option /etc/ppp/pptpd-options # TAG: debug # # syslog に詳細なデバッグ情報を出力します # # debug # TAG: localip # TAG: remoteip # # ローカルとリモートの IP アドレス範囲を指定します。 # # コンマで区切ることで、単独の IP アドレスおよび # IP アドレス範囲を指定できます。以下は利用例です。 # # 192.168.0.234,192.168.0.245-249,192.168.0.254 # # 以下の重要な制約事項に注意してください。 # # 1. コンマ間およびアドレス内部で空白文字を使わないでください。 # # 2. MAX_CONNECTIONS よりも多くの IP アドレス を指定した場合、 # 使われる IP アドレスはリストの先頭から MAX_CONNECTIONS # 個までの IP アドレスです。それ以外は使われません。 # # 3. アドレス範囲を略記しないでください! たとえば 234 から 238 の範囲を指定するために # 234-8 と記述するのは間違いです。その代わり 234-238 と記述してください。 # # 4. ローカル IP は 1 つだけでも構いません。この場合、すべてのローカル IP は # 指定したものになります。しかしながら、同時接続中のクライアントには # 必ず異なるリモート IP を割り振らなければいけません。 # #localip 192.168.0.234-238,192.168.0.245 #remoteip 192.168.1.234-238,192.168.1.245 #localip 10.0.1.1 #remoteip 10.0.1.2-100 localip 192.168.0.199 remoteip 192.168.0.200-250
/etc/ppp/pptpd-options
を編集して、PPTP サーバの使う PPP 設定を変更します。重要なパラメータはサーバ名 (pptp
)、ドメイン名 (falcot.com
)、DNS と WINS サーバの IP アドレスです。
例 10.7 /etc/ppp/pptpd-options
ファイル
## pppd の syslog デバッグを有効化します #debug ## 「サーバ名」を chap-secrets 内の自分のサーバ名として指定したものに変更します name pptp ## ドメイン名をローカルドメインに変更します domain falcot.com ## 以下は WinXXXX クライアントに対して ## 適当とされるデフォルトセキュリティ関連設定です # Debian の pppd パッケージは MSCHAP と MPPE の両方をサポートしています。そのため # ここでは両方を有効化しています。カーネルの MPPE サポートが必須という点にも注意してください! auth require-chap require-mschap require-mschap-v2 require-mppe-128 ## サービスに対応するアドレスを指定してください ms-dns 192.168.0.1 ms-wins 192.168.0.1 ## ネットマスクを指定してください netmask 255.255.255.0 ## 一部のデフォルト設定 nodefaultroute proxyarp lock
vpn
ユーザ (と対応するパスワード) を /etc/ppp/chap-secrets
ファイルに登録します。サーバ名だけは、アスタリスク (*
) を使える他のインスタンスと異なり、明示的に指定しなければいけません。さらに、Windows PPTP クライアントはユーザ名ではなく DOMAIN\\USER
という形を認証を行います。このため、/etc/ppp/chap-secrets
ファイルに FALCOT\\vpn
ユーザが追加されています。ユーザに割り当てる IP アドレスを明記することも可能です。IP アドレスフィールドのアスタリスクは動的にアドレスを割り当てることを意味します。