このチュートリアルでは、Azure Virtual Network Gateway を使って、Cloudflare WAN(旧 Magic WAN)を Azure Virtual Network に接続する方法を説明します。
Azure アカウントに、既存の Resource group、Virtual Network、Virtual Machine が必要です。作成方法は Microsoft のドキュメント ↗ を参照してください。
すでに Virtual Network(VNET)を作成し、サブネットを割り当て済みである前提です。次に、Azure が Virtual Network Gateway 関連のサービス用アドレスに使う Gateway subnet を作成します。Gateway subnet がすでにある場合、Azure は 2 つ目の作成を拒否します。その場合は、既存の Gateway subnet 設定を更新します。
- Virtual Network > Subnets を開きます。
- Gateway subnet を追加するオプションを選択します。
- サブネットのアドレス範囲を設定します。Gateway subnet は仮想ネットワークのアドレス空間に含まれ、サブネットマスクは
/27以上である必要があります。 - ほかの設定はすべて None にします。
Virtual Network Gateway は、構内デバイスとのトンネルを形成するために使います。
- Virtual Network Gateway を作成します。
- 新しいパブリック IP アドレスを 2 つ作成するか、既存の IP を使います。Virtual Network Gateway に割り当てられたパブリック IP アドレスを控えてください。これらが Cloudflare WAN の IPsec トンネル設定における Customer endpoint になります。
- 先ほど作成した Virtual Network Gateway を開きます。
- Configuration で Active-active mode を有効にし、Gateway Private IPs を無効にします。
- Create を選択します。
- Virtual Network Gateway を作成します。
- 新しいパブリック IP アドレスを作成するか、既存の IP を使います。Virtual Network Gateway に割り当てられたパブリック IP アドレスを控えてください。これが Cloudflare WAN の IPsec トンネル設定における Customer endpoint になります。
- 作成済みのリソースグループと VNET を選択します。
- Configuration で Active-active mode と Gateway Private IPs を無効にします。
- Create を選択します。
- Cloudflare ダッシュボードで IPsec トンネル を作成します。
- 次の設定になっていることを確認します。
- Interface address: Azure Local Network Gateway は
/31サブネットの下位 IP アドレスしか指定できないため、/31サブネット内の上位 IP アドレスを追加します。対応する/32アドレスは、後の手順で Azure 側に設定します(IPsec トンネルヘルスチェック用に Local Network Gateway を設定する を参照)。詳細は トンネルエンドポイント を参照してください。 - Customer endpoint: Azure Virtual Network Gateway に関連付けられたパブリック IP。例:
40.xxx.xxx.xxx。 - Cloudflare endpoint: アカウントに割り当てられた Cloudflare anycast アドレスの 1 つを使います。Leased IPs ↗ で確認できます。このアドレスは、Azure 側の Local Network Gateway に対応する IP にもなります。例:
162.xxx.xxx.xxx。 - Health check rate: デフォルト(Medium)のままにします。
- Health check type: デフォルト(Reply)のままにします。
- Health check direction: デフォルト(Bidirectional)のままにします。
- Health check target: Custom を選択します。
- Target address: Customer endpoint と同じアドレスを入力します。
- Add pre-shared key later: 後で Azure 側で使う PSK を作成するため、このオプションを選択します。
- Replay protection: Enable。
- Interface address: Azure Local Network Gateway は
- Active/Active 構成を使う場合は Add IPsec tunnel を選択し、手順 2 を繰り返して 2 本目の Cloudflare WAN IPsec トンネルを作成します。Cloudflare endpoint は 1 本目と同じ値を使います。
- 完了したら Add Tunnels を選択します。
- Cloudflare ダッシュボードにトンネル一覧が表示されます。作成したトンネルを編集し、Generate a new pre-shared key を選択して、生成されたキーをコピーします。Active/Active 構成の場合は、2 本目のトンネルで Change to a new custom pre-shared key を選択し、1 本目で生成した PSK を使います。
- Azure Virtual Network のサブネット向けに 静的ルート を作成し、ネクストホップに作成したトンネルを指定します。
Local Network Gateway は通常、オンプレミスの拠点を指します。この場合は、接続の Cloudflare 側を表します。
Cloudflare IPsec トンネル用に Local Network Gateway を作成することを推奨します。
- 新しい Local Network Gateway を作成します。
- Instance details > Endpoint で IP address を選択し、IP アドレス欄に Cloudflare anycast アドレスを入力します。
- Address space(s) に、Cloudflare WAN 接続経由でリモートからアクセスしたいサブネットのアドレス範囲を指定します。たとえば、
192.168.1.0/24のネットワークに到達したい場合で、そのネットワークが Cloudflare WAN テナントに接続されているなら、Local Network Gateway のアドレス空間に192.168.1.0/24を追加します。 - Advanced タブ > BGP settings を開き、No を選択します。
Cloudflare WAN は、トンネルが利用可能かどうかを監視するために Tunnel Health Checks を使います。
トンネルヘルスチェックは、IPsec トンネルの Cloudflare 側からリモートエンドポイント(Azure)へ送る ICMP プローブを使います。プローブはトンネルのインターフェースアドレスから送られます。このアドレスは次の 2 か所で指定します。
- Cloudflare Dashboard: IPsec トンネル設定の仮想トンネルインターフェース(VTI)アドレスとして指定します(Cloudflare がプローブの送信元アドレスを知るため)。Cloudflare では、このアドレスを Classless Inter-Domain Routing(CIDR)表記の
/31ネットマスクで指定する必要があります。 - Azure Portal: VPN サイトのアドレス空間として指定します(Azure がプローブ応答をトンネル経由で返すため)。Azure では、このアドレスを CIDR 表記の
/32ネットマスクで指定する必要があります。
Cloudflare では、IPsec トンネルごとに一意の /31 サブネット(RFC 1918 - Address Allocation for Private Internets ↗)を選ぶことを推奨します。Point-to-Point Link として扱い、両方の要件を満たす理想的なアドレス方式になります。
例:
- 一意のポイントツーポイントリンクサブネットとして
10.252.3.55/31を選びます。 - Cloudflare ダッシュボードでは、トンネルの IPv4 Interface address に
10.252.3.55/31を設定します(Cloudflare WAN を設定する を参照)。 - Azure ポータルでは、Local Network Gateway の Address space に
10.252.3.55/32を追加します。
トンネルヘルスチェックに対応するよう、Local Network Gateway の Address Space を設定するには、次の手順を実行します。
- 前のセクションで設定した Local Network Gateway を編集します。
- Connections を選択します。
- Address Space(s) に、Cloudflare ダッシュボードの IPsec トンネルの Interface Address を CIDR 表記で追加します(例:
10.252.3.55/32)。 - Active/Active 構成の場合は、Cloudflare ダッシュボードの 2 本目の IPsec トンネルの Interface Address も CIDR 表記で Address Space(s) に追加します(例:
10.252.3.56/32)。両方のトンネルインターフェースアドレスを Local Network Gateway の Address Space に設定すると、両方のトンネルが健全な状態を保てます。 - Save を選択します。
VPN Connection の作成時は、次の設定を選びます。
- Virtual network gateway: Virtual Network Gateway を作成する で作成した Virtual Network Gateway を選択します。
- Local network gateway: Local Network Gateway を作成する で作成した Local Network Gateway を選択します。
- Use Azure Private IP Address: Disabled
- BGP: Disabled
- IPsec / IKE policy: Custom
- IKE Phase 1
- Encryption: GCMAES256
- Integrity/PRF: SHA384
- DH Group: ECP384
- IKE Phase 2(IPsec)
- IPsec Encryption: GCMAES256
- IPsec Integrity: GCMAES256
- PFS Group: ECP384
- IPsec SA lifetime in KiloBytes:
0 - IPsec SA lifetime in seconds:
28800 - Use policy based traffic selector: Disable
- DPD timeout in seconds:
45 - Connection mode: InitiatorOnly
- Use custom traffic selectors: Disabled
- IKE Phase 1
- 接続作成後、Settings > Authentication を選択し、PSK を入力します(Cloudflare WAN の設定で使った PSK と一致させる必要があります)。
冗長な Cloudflare anycast IP アドレスに対応する Local Network Gateway への Connection についても、同じ手順で設定を定義します。
Cloudflare Zero Trust のお客様は、インターネット宛てのトラフィックを Cloudflare WAN 経由で Cloudflare Gateway からインターネットへ出せます。
Microsoft は、Local Network Gateway の Address Space にデフォルトルート(0.0.0.0/0)を指定することを許可していません。ただし、ルート集約を使えば、この制限を回避できます。
- Local network gateways を開き、対象のオブジェクトを選択します。
- Configuration > Address Space(s) を開き、次の 2 つのサブネットを指定します:
0.0.0.0/1と128.0.0.0/1。 - トンネルヘルスチェック用に設定したサブネットは削除しないでください。
- Save を選択します。
インターネット宛てトラフィックをすべて Cloudflare WAN 経由にし、HTTPS TLS 復号 を使う場合は、ユーザーのデバイスに Cloudflare Zero Trust のルート認証局(CA)証明書をインストールして信頼する必要があります。Cloudflare が提供する証明書をインストールするか(デフォルト)、独自のカスタム証明書を生成して Cloudflare にアップロードできます。
ルート CA 証明書のインストール手順は、Cloudflare Zero Trust ドキュメントの ユーザー側証明書 を参照してください。
ルート CA 証明書をインストールしたら、Web ブラウザーを開くか curl を使って、インターネット接続を確認します。
curl https://ipinfo.io{
"ip": "104.xxx.xxx.225",
"city": "Reston",
"region": "Virginia",
"country": "US",
"loc": "xx.xxxx,-xx.xxxx",
"org": "AS13335 Cloudflare, Inc.",
"postal": "20190",
"timezone": "America/New_York",
"readme": "https://ipinfo.io/missingauth"
}接続が確立したことを確認したら、Azure Virtual Network Gateway のサイト間 VPN 接続ではアンチリプレイ保護を無効にすることを推奨します。これは Microsoft Azure API で行えます。
- PowerShell で API トークンを取得します。
Get-AzAccessTokenToken: eyJ0e<REDACTED>AH-PdSPg
ExpiresOn : 04/08/2024 23:32:47 +00:00
Type : Bearer
TenantId : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
UserId : [email protected]- Azure Virtual Network Gateway に関連付けられたサイト間 VPN Connection の詳細を表示する API 呼び出し(
GETリクエスト)を実行します。
curl --location 'https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}?api-version=2022-05-01' \
--header 'Authorization: Bearer eyJ0e<REDACTED>AH-PdSPg'- 応答全体をテキストエディターにコピーして貼り付けます。
{
"name": "{{virtualNetworkGatewayName}}",
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}",
"etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
"type": "Microsoft.Network/virtualNetworkGateways",
"location": "eastus"
},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"packetCaptureDiagnosticState": "None",
"enablePrivateIpAddress": false,
"isMigrateToCSES": false,
"ipConfigurations": [
{
"name": "default",
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}/ipConfigurations/default",
"etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
"type": "Microsoft.Network/virtualNetworkGateways/ipConfigurations",
"properties": {
"provisioningState": "Succeeded",
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/publicIPAddresses/{{virtualNetworkGatewayPublicIpAddress}}"
},
"subnet": {
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworks/{{virtualNetworkGatewayName}}/subnets/GatewaySubnet"
}
}
}
],
"natRules": [],
"virtualNetworkGatewayPolicyGroups": [],
"enableBgpRouteTranslationForNat": false,
"disableIPSecReplayProtection": false,
"sku": {
"name": "VpnGw2AZ",
"tier": "VpnGw2AZ",
"capacity": 2
},
"gatewayType": "Vpn",
"vpnType": "RouteBased",
"enableBgp": false,
"activeActive": false,
"bgpSettings": {
"asn": 65515,
"bgpPeeringAddress": "172.25.40.30",
"peerWeight": 0,
"bgpPeeringAddresses": [
{
"ipconfigurationId": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}/ipConfigurations/default",
"defaultBgpIpAddresses": [
"172.25.40.30"
],
"customBgpIpAddresses": [],
"tunnelIpAddresses": [
"{{CF ANYCAST IP}}"
]
}
]
},
"gatewayDefaultSite": {
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/localNetworkGateways/{{localNetworkGatewayName}}"
},
"vpnGatewayGeneration": "Generation2",
"allowRemoteVnetTraffic": false,
"allowVirtualWanTraffic": false
}
}- IPsec アンチリプレイ保護を無効にする行を探し、
falseからtrueに変更します。
"disableIPSecReplayProtection": true- 応答全体を、続く API 呼び出し(
PUTリクエスト)でアップロードします。
curl --location --request PUT \
'https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}?api-version=2022-05-01' \
--header "Authorization: Bearer eyJ0e<REDACTED>AH-PdSPg" \
--header "Content-Type: application/json" \
--data '{
"name": "{{virtualNetworkGatewayName}}",
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}",
"etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
"type": "Microsoft.Network/virtualNetworkGateways",
"location": "eastus"
},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"packetCaptureDiagnosticState": "None",
"enablePrivateIpAddress": false,
"isMigrateToCSES": false,
"ipConfigurations": [
{
"name": "default",
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}/ipConfigurations/default",
"etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
"type": "Microsoft.Network/virtualNetworkGateways/ipConfigurations",
"properties": {
"provisioningState": "Succeeded",
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/publicIPAddresses/{{virtualNetworkGatewayPublicIpAddress}}"
},
"subnet": {
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworks/{{virtualNetworkGatewayName}}/subnets/GatewaySubnet"
}
}
}
],
"natRules": [],
"virtualNetworkGatewayPolicyGroups": [],
"enableBgpRouteTranslationForNat": false,
"disableIPSecReplayProtection": true,
"sku": {
"name": "VpnGw2AZ",
"tier": "VpnGw2AZ",
"capacity": 2
},
"gatewayType": "Vpn",
"vpnType": "RouteBased",
"enableBgp": false,
"activeActive": false,
"bgpSettings": {
"asn": 65515,
"bgpPeeringAddress": "172.25.40.30",
"peerWeight": 0,
"bgpPeeringAddresses": [
{
"ipconfigurationId": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}/ipConfigurations/default",
"defaultBgpIpAddresses": [
"172.25.40.30"
],
"customBgpIpAddresses": [],
"tunnelIpAddresses": [
"{{CF ANYCAST IP}}"
]
}
]
},
"gatewayDefaultSite": {
"id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/localNetworkGateways/{{localNetworkGatewayName}}"
},
"vpnGatewayGeneration": "Generation2",
"allowRemoteVnetTraffic": false,
"allowVirtualWanTraffic": false
}
}'- Cloudflare ダッシュボードのリプレイ保護設定はオンのままにし、数分待ってから、もう一度接続を確認します。