tun
(IP レベルトンネル) と tap
(イーサネットレベルトンネル) インターフェイスをサポートします。具体的には、VPN クライアントをイーサネットブリッジ経由でサーバのローカルネットワークに参加させる場合を除いて、tun
インターフェイスが最もよく使われます。
openssl
コマンドを使うスクリプト群です; スクリプトは /usr/share/doc/openvpn/examples/easy-rsa/2.0/
以下に含まれています。
$
cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0 pki-falcot
$
cd pki-falcot
vars
ファイルに保存します。パラメータには特に KEY_
接頭辞が付けられています。これらの変数は環境変数に組み込まれます:
$
vim vars
$
grep KEY_ 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" $
. ./vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /home/rhertzog/pki-falcot/keys $
./clean-all
keys/ca.crt
と keys/ca.key
に保存されます):
$
./build-ca
Generating a 2048 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) [FR]: State or Province Name (full name) [Loire]: Locality Name (eg, city) [Saint-Étienne]: Organization Name (eg, company) [Falcot Corp]: Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) [Falcot Corp CA]: Name []: Email Address [admin@falcot.com]:
vpn.falcot.com
で識別されます; 作成された鍵ファイルの名前に、ここで与えた DNS 名が使われます (keys/vpn.falcot.com.crt
は公開鍵証明書、keys/vpn.falcot.com.key
は秘密鍵):
$
./build-key-server vpn.falcot.com
Generating a 2048 bit RSA private key ...............++++++ ...........++++++ writing new private key to 'vpn.falcot.com.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) [FR]: State or Province Name (full name) [Loire]: Locality Name (eg, city) [Saint-Étienne]: Organization Name (eg, company) [Falcot Corp]: Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) [vpn.falcot.com]: Name []: Email Address [admin@falcot.com]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /home/rhertzog/pki-falcot/openssl.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'FR' stateOrProvinceName :PRINTABLE:'Loire' localityName :T61STRING:'Saint-\0xFFFFFFC3\0xFFFFFF89tienne' organizationName :PRINTABLE:'Falcot Corp' commonName :PRINTABLE:'vpn.falcot.com' emailAddress :IA5STRING:'admin@falcot.com' Certificate is to be certified until Oct 9 13:57:42 2020 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 $
./build-dh
Generating DH parameters, 2048 bit long safe prime, generator 2 This is going to take a long time ..............+.......+.................................++*++*++*
$
./build-key JoeSmith
Generating a 2048 bit RSA private key ................++++++ .............................++++++ writing new private key to 'JoeSmith.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) [FR]: State or Province Name (full name) [Loire]: Locality Name (eg, city) [Saint-Étienne]: Organization Name (eg, company) [Falcot Corp]: Organizational Unit Name (eg, section) []: Common Name (eg, your name or your server's hostname) [JoeSmith]:
Joe Smith
Name []: Email Address [admin@falcot.com]:
joe@falcot.com
[…]
keys/ca.crt
) は全てのマシン (サーバもクライアントも) に /etc/ssl/certs/Falcot_CA.crt
という名前で保存されます。サーバの証明書はサーバにだけインストールされます (keys/vpn.falcot.com.crt
は /etc/ssl/vpn.falcot.com.crt
に、keys/vpn.falcot.com.key
は管理者だけが読めるようなパーミッション制限を掛けるために /etc/ssl/private/vpn.falcot.com.key
に、インストールされます)。同時に、対応する Diffie-Hellman パラメータ (keys/dh2048.pem
) は /etc/openvpn/dh2048.pem
にインストールされます。クライアント証明書は対応する VPN クライアントに同様の方法でインストールされます。
/etc/openvpn/*.conf
で定義された全ての仮想プライベートネットワークを開始します。このため、VPN サーバをセットアップする場合、このディレクトリ内に対応する設定ファイルを配置する事になります。設定ファイルの良い足掛かりとして /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz
が用意されています。これは比較的標準的なサーバを作るためのものです。もちろん、一部のパラメータを適切に設定しなければいけません: ca
、cert
、key
、dh
をファイルを設置した場所に設定する必要があります (それぞれ、/etc/ssl/certs/Falcot_CA.crt
、/etc/ssl/vpn.falcot.com.crt
、/etc/ssl/private/vpn.falcot.com.key
、/etc/openvpn/dh2048.pem
)。server 10.8.0.0 255.255.255.0
ディレクティブは VPN によって使われるサブネットを定義します; サーバにはこの範囲に含まれる最初の IP アドレス (10.8.0.1
) が割り当てられ、クライアントには残りの IP アドレスが割り当てられます。
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 サーバからアクセスしたかのように見えます (「ゲートウェイ」 参照)。
/etc/openvpn/
に設定ファイルを置きます。標準的な設定の良い足掛かりとして /usr/share/doc/openvpn/examples/sample-config-files/client.conf
が用意されています。remote vpn.falcot.com 1194
指示文は OpenVPN サーバのアドレスとポート番号を表します; ca
、cert
、key
も鍵ファイルの場所に合わせて設定が必要です。
/etc/default/openvpn
ファイルの AUTOSTART
指示文に none
を設定してください。VPN 接続の開始と停止は /etc/init.d/openpvn start name
と /etc/init.d/openpvn stop name
コマンドを使えばいつでも可能です (ここで、接続名 name は /etc/openvpn/name.conf
で定義したたものにマッチします)。
tun*
) on both sides of an SSH connection, and these virtual interfaces can be configured exactly as if they were physical interfaces. The tunneling system must first be enabled by setting PermitTunnel
to “yes” in the SSH server configuration file (/etc/ssh/sshd_config
). When establishing the SSH connection, the creation of a tunnel must be explicitly requested with the -w any:any
option (any
can be replaced with the desired tun
device number). This requires the user to have administrator privilege on both sides, so as to be able to create the network device (in other words, the connection must be established as root).
/etc/ipsec-tools.conf
には、ホストが接続する IPsec トンネル (IPsec 用語で Security Associations) のパラメータが含まれます; /etc/init.d/setkey
スクリプトを使うことで、トンネルを開始したり停止することが可能です (それぞれのトンネルは、仮想ネットワークに接続された他のホストと、安全なリンクを確立しています)。このファイルは setkey(8) マニュアルページの提供する文書を使って手作業で作ることも可能です。しかしながら、多数のマシン群に全てのホスト用のパラメータを明示的に書くことはすぐに難しい作業になります。なぜなら、トンネルの数はすぐに増えるからです。この作業をより簡単にする、例えば racoon、strongswan、openswan 等の (IPsec Key Exchange 用の) IKE デーモンがあります。これを使えば、一元管理による作業の簡素化と、鍵を定期的に循環することによる作業の安全化が可能になります。
/etc/ppp/options.pptp
、/etc/ppp/peers/falcot
、/etc/ppp/ip-up.d/falcot
、/etc/ppp/ip-down.d/falcot
。
例10.2 /etc/ppp/options.pptp
ファイル
# PPP options used for a PPTP connection lock noauth nobsdcomp nodeflate
例10.3 /etc/ppp/peers/falcot
ファイル
# vpn.falcot.com is the PPTP server pty "pptp vpn.falcot.com --nolaunchpppd" # the connection will identify as the "vpn" user user vpn remotename pptp # encryption is needed 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 # # Specifies the speed for the PPP daemon to talk at. # speed 115200 # TAG: option # # Specifies the location of the PPP options file. # By default PPP looks in '/etc/ppp/options' # option /etc/ppp/pptpd-options # TAG: debug # # Turns on (more) debugging to syslog # # debug # TAG: localip # TAG: remoteip # # Specifies the local and remote IP address ranges. # # You can specify single IP addresses separated by commas or you can # specify ranges, or both. For example: # # 192.168.0.234,192.168.0.245-249,192.168.0.254 # # IMPORTANT RESTRICTIONS: # # 1. No spaces are permitted between commas or within addresses. # # 2. If you give more IP addresses than MAX_CONNECTIONS, it will # start at the beginning of the list and go until it gets # MAX_CONNECTIONS IPs. Others will be ignored. # # 3. No shortcuts in ranges! ie. 234-8 does not mean 234 to 238, # you must type 234-238 if you mean this. # # 4. If you give a single localIP, that's ok - all local IPs will # be set to the given one. You MUST still give at least one remote # IP for each simultaneous client. # #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
ファイル
## turn pppd syslog debugging on #debug ## change 'servername' to whatever you specify as your server name in chap-secrets name pptp ## change the domainname to your local domain domain falcot.com ## these are reasonable defaults for WinXXXX clients ## for the security related settings # The Debian pppd package now supports both MSCHAP and MPPE, so enable them # here. Please note that the kernel support for MPPE must also be present! auth require-chap require-mschap require-mschap-v2 require-mppe-128 ## Fill in your addresses ms-dns 192.168.0.1 ms-wins 192.168.0.1 ## Fill in your netmask netmask 255.255.255.0 ## some defaults nodefaultroute proxyarp lock
vpn
user (and the associated password) in the /etc/ppp/chap-secrets
file. Contrary to other instances where an asterisk (*
) would work, the server name must be filled explicitly here. Furthermore, Windows PPTP clients identify themselves under the DOMAIN\\USER
form, instead of only providing a user name. This explains why the file also mentions the FALCOT\\vpn
user. It is also possible to specify individual IP addresses for users; an asterisk in this field specifies that dynamic addressing should be used.