以前VPSにIKEv2のVPNを構築しましたが、今回は家庭内LANにVPN接続のセットアップを行いました。ルーターはバッファーロー製でOpenWrt(Chaos Calmer 15.05.1)が入っています。このルーターはVPSに strongSwanクライアントとして接続してあり、かつ今回はVPNサーバーとして同時に活用しようとする計画です。IPsecの設定はサーバー側もクライアント側もほぼ同じです。ネットワークのルーティングがうまく行くか不安なところがありますが、今後検証してみるつもりです。
構成図
Internet : VPS:10.0.0.0/24 === 192.168.1.0/24:Router:192.168.100.0/24 === Users(Road Warriors)
Router側の設定
まずDynamic DNSをセットアップします。認証局(CA)をサーバ側にインストールするので必須になります。OpenWRTのパッケージはstrongswan-fullで一通り全てのパッケージを入れておけば間違い無いのですが、必要なパッケージが判れば個別にインストールして最小限に済ませておく事も出来ます。モジュールはstrongswan-mod-eap-mschapv2とstrongswan-mod-pubkeyは最低限必要になります。また対応するカーネルモジュールも入れておきます。
今回接続するクライアントはAndroidとLinux、Windows、macOSのPCを想定して設定しています。
/etc/ipsec.conf:
# ipsec.conf - strongSwan IPsec configuration file config setup #plutostart=no conn %default ikelifetime=60m keylife=20m rekeymargin=3m keyingtries=1 conn common keyexchange=ikev2 left=%any leftcert=vpnClientCert.pem leftsourceip=%config leftauth=pubkey leftfirewall=yes # VPNと接続 conn vps-router keyexchange=ikev2 left=moon.mydns.jp leftid="C=JP, O=MyDomain, CN=router@moon.mydns.jp --san=router@moon.mydns.jp" leftid2=router@moon.mydns.jp leftsubnet=192.168.1.0/24 leftauth=pubkey leftfirewall=yes leftcert=vpnClientCert.pem right=vps.net.jp rightid=@vps.net.jp rightsubnet=10.0.0.0/24 rightauth=pubkey rightfirewall=yes ike=aes128-sha256-modp2048 esp=aes128-sha256-modp2048 auto=start # 家のRouterに接続 # IKEv2 Certificate for Linux and Android conn home-linux-android keyexchange=ikev2 left=moon.mydns.jp leftid2=router@moon.mydns.jp leftsubnet=0.0.0.0/0,::/0 leftauth=pubkey leftfirewall=yes leftcert=HomeServerCert.pem right=%any rightid2=*linux@roadwarrior rightauth=pubkey rightallowany=yes rightsourceip=192.168.100.0/26 dpdaction=clear dpddelay=300s rekey=no reauth=no fragmentation=yes auto=add # EAP/MSCHAPv2 for Windows and macOS conn home-windows-macos keyexchange=ikev2 left=moon.mydns.jp leftid2=router@moon.mydns.jp leftsubnet=0.0.0.0/0,::/0 leftauth=pubkey leftfirewall=yes leftcert=HomeServerCert.pem right=%any rightid2=*@roadwarrior rightsourceip=192.168.100.64/26 rightauth=eap-mschapv2 ike=aes256-sha1-modp1024,aes128-sha1-modp1024,3des-sha1-modp1024! esp=aes256-sha256,aes256-sha1,3des-sha1! dpdaction=clear dpddelay=300s rekey=no reauth=no fragmentation=yes auto=add
/etc/ipsec.secrets:
# /etc/ipsec.secrets - strongSwan IPsec secrets file MyName : EAP "MyPass" : RSA vpnClientKey.pem : RSA HomeServerKey.pem
/etc/ipsec.d/certs/vpnClientCert.pem /etc/ipsec.d/certs/HomeServerCert.pem /etc/ipsec.d/cacerts/caCert.pem /etc/ipsec.d/private/HomeServerKey.pem /etc/ipsec.d/private/vpnClientKey.pem
認証局、鍵の作成は過去の記事を参考に作成します。
/etc/strongswan.conf:
# strongswan.conf - strongSwan configuration file # Refer to the strongswan.conf(5) manpage for details # Configuration changes should be made in the included files charon { load_modular = yes dns1 = 8.8.8.8 dns2 = 8.8.4.4 threads = 16 plugins { include strongswan.d/charon/*.conf } }
/etc/strongswan.d/charon/kernel-netlink.conf:
mtu = 1376を追加
Note: MTU値1500からPPPoEヘッダー長+IPsecヘッダー長を引いた値
Firewallの設定
/etc/config/firewall:
次の設定を追加します。
config rule option src 'wan' option dest 'lan' option proto 'esp' option target 'ACCEPT' config rule option src 'wan' option dest 'lan' option dest_port '500' option proto 'udp' option target 'ACCEPT' config rule option src 'wan' option proto 'esp' option target 'ACCEPT' config rule option src 'wan' option proto 'udp' option dest_port '500' option target 'ACCEPT' config rule option src 'wan' option proto 'udp' option dest_port '4500' option target 'ACCEPT'
/etc/firewall.user:
設定を追加します。
iptables -I INPUT -m policy --dir in --pol ipsec --proto esp -j ACCEPT iptables -I FORWARD -m policy --dir in --pol ipsec --proto esp -j ACCEPT iptables -I FORWARD -m policy --dir out --pol ipsec --proto esp -j ACCEPT iptables -I OUTPUT -m policy --dir out --pol ipsec --proto esp -j ACCEPT iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -m policy --dir out --pol ipsec -j ACCEPT iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o eth0 -j MASQUERADE
Client側の設定
Android
strongSwanのクライアントアプリをストアからインストールします。
PKCS#12ファイルをコピーして設定のセキュリティからインストールします。
strongSwanのアプリからAdd VPN Profileでサーバー名をFQDNで入れます。
VPNタイプをIKEv2 Certificateにします。
User identityを選択します。
CA certificateを指定します。
Saveして接続します。
macOS(High Sierra)の場合
Apple Configurator 2でCertificatesとVPNを編集します。名前をつけて保存したらダブルクリックしてプロファイルをインストールします。
設定のNetworkでVPNを起動します。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PayloadContent</key> <array> <dict> <key>IKEv2</key> <dict> <key>AuthenticationMethod</key> <string>Certificate</string> <key>ChildSecurityAssociationParameters</key> <dict> <key>DiffieHellmanGroup</key> <integer>14</integer> <key>EncryptionAlgorithm</key> <string>AES-256</string> <key>IntegrityAlgorithm</key> <string>SHA1-96</string> <key>LifeTimeInMinutes</key> <integer>1440</integer> </dict> <key>DeadPeerDetectionRate</key> <string>Medium</string> <key>DisableMOBIKE</key> <integer>0</integer> <key>DisableRedirect</key> <integer>0</integer> <key>EnableCertificateRevocationCheck</key> <integer>0</integer> <key>EnablePFS</key> <integer>0</integer> <key>ExtendedAuthEnabled</key> <true/> <key>IKESecurityAssociationParameters</key> <dict> <key>DiffieHellmanGroup</key> <integer>14</integer> <key>EncryptionAlgorithm</key> <string>AES-128</string> <key>IntegrityAlgorithm</key> <string>SHA1-96</string> <key>LifeTimeInMinutes</key> <integer>1440</integer> </dict> <key>LocalIdentifier</key> <string>user@roadwarriior</string> <key>PayloadCertificateUUID</key> <string>E1D73F77-FB03-428E-BD5B-8167B90C80D1</string> <key>RemoteAddress</key> <string>moon.mydns.jp</string> <key>RemoteIdentifier</key> <string>moon.mydns.jp</string> <key>ServerCertificateCommonName</key> <string>mmoon.mydns.jp</string> <key>ServerCertificateIssuerCommonName</key> <string>Root CA</string> <key>UseConfigurationAttributeInternalIPSubnet</key> <integer>0</integer> </dict> <key>IPv4</key> <dict> <key>OverridePrimary</key> <integer>0</integer> </dict> <key>PayloadDescription</key> <string>Configures VPN settings</string> <key>PayloadDisplayName</key> <string>VPN</string> <key>PayloadIdentifier</key> <string>com.apple.vpn.managed.EA117620-4605-48FA-A5AA-1D8EE6D1F97A</string> <key>PayloadType</key> <string>com.apple.vpn.managed</string> <key>PayloadUUID</key> <string>EA117620-4605-48FA-A5AA-1D8EE6D1F97A</string> <key>PayloadVersion</key> <integer>1</integer> <key>Proxies</key> <dict> <key>HTTPEnable</key> <integer>0</integer> <key>HTTPSEnable</key> <integer>0</integer> </dict> <key>UserDefinedName</key> <string>home vps</string> <key>VPNType</key> <string>IKEv2</string> </dict> </array> <key>PayloadDisplayName</key> <string>ikv2.home</string> <key>PayloadIdentifier</key> <string>MacBook-Pro.C852D634-193B-4ACC-84F0-EA8FC55AF9C0</string> <key>PayloadRemovalDisallowed</key> <false/> <key>PayloadType</key> <string>Configuration</string> <key>PayloadUUID</key> <string>A5E63D53-E8B1-4796-AD2A-285930D9A88F</string> <key>PayloadVersion</key> <integer>1</integer> </dict> </plist>