Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

はじめに

最終更新 Markdown で表示Agent セットアップ

Spectrum は有料プランすべてで利用できます。Pro と Business は一部のプロトコルのみ対応し、Enterprise はすべての TCP および UDP ベースのトラフィックに対応します。設定の詳細は 設定オプション を参照してください。

Spectrum アプリケーションの作成には、IP アドレス、CNAME レコード、またはロードバランサーを使えます。いずれの方法でも、ダッシュボードまたは API から作成できます。

Spectrum のリクエストおよびレスポンス本文の一部のフィールドは、Enterprise プランが必要です。詳細は プラン別の設定 を参照してください。

IP アドレスで Spectrum アプリケーションを作成する

IP アドレスで Spectrum アプリケーションを作成する場合、Cloudflare は通常、Cloudflare の IP プールから任意の IP をアプリケーションに割り当てます。独自の IP アドレスを使う場合は、BYOIP または Static IP を使えます。この 2 つの場合は、ダッシュボードでは利用できないため、API で Spectrum アプリケーションを作成する必要があります。API を使う場合、origin_direct フィールドに IP アドレスを入力します。

ダッシュボードでアプリケーションを追加する

  1. Cloudflare ダッシュボードで Spectrum ページを開きます。

    Spectrum を開く ↗
  2. Create an Application を選択します。Spectrum を初めて使う場合は、Create an Application モーダルが表示されます。

  3. Application Type を選択します。

  4. Domain に、Spectrum を使うドメインを入力します。

  5. Edge Port に、Cloudflare がアプリケーションに使うポートを入力します。

  6. Origin に、アプリケーションのオリジン IP とポートを入力します。

  7. アプリケーションがクライアント IP を必要とし、Proxy Protocol に対応している場合は、Proxy Protocols を有効にします。Proxy Protocol は、Cloudflare のようなプロキシがクライアント IP をオリジンアプリケーションへ送る方法です。

  8. Add を選択します。

API でアプリケーションを追加する

次は curl の例と、API へ送信するデータです。

API の例:

Required API token permissions

At least one of the following token permissions is required:
  • Zone Settings Write
Create Spectrum application using a name for the originbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/spectrum/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"protocol": "tcp/22",
		"dns": {
				"type": "CNAME",
				"name": "ssh.example.com"
		},
		"origin_direct": [
				"tcp://192.0.2.1:22"
		],
		"proxy_protocol": "off",
		"ip_firewall": true,
		"tls": "full",
		"edge_ips": {
				"type": "dynamic",
				"connectivity": "all"
		},
		"traffic_type": "direct",
		"argo_smart_routing": true
	}'

データの例:

{
	"success": true,
	"errors": [],
	"messages": [],
	"result": {
		"id": "ea95132c15732412d22c1476fa83f27a",
		"protocol": "tcp/22",
		"dns": {
			"type": "CNAME",
			"name": "ssh.example.com"
		},
		"origin_direct": ["tcp://192.0.2.1:22"],
		"proxy_protocol": "off",
		"ip_firewall": true,
		"tls": "full",
		"edge_ips": {
			"type": "dynamic",
			"connectivity": "all"
		},
		"traffic_type": "direct",
		"argo_smart_routing": true,
		"created_on": "2014-01-02T02:20:00Z",
		"modified_on": "2014-01-02T02:20:00Z"
	}
}

CNAME レコードで Spectrum アプリケーションを作成する

CNAME レコードで Spectrum アプリケーションを作成する場合は、Cloudflare がホストするゾーンに、オリジンのホスト名を指す CNAME レコード を作成します。オリジンのホスト名を解決するために必要です。詳細は DNS レコードを作成する を参照してください。オリジンに CNAME を使う場合、Cloudflare がそのゾーンの権威である必要があります。API を使う場合、origin_dns フィールドに CNAME レコードを入力します。

ダッシュボードでアプリケーションを追加する

  1. Cloudflare ダッシュボードで Spectrum ページを開きます。

    Spectrum を開く ↗
  2. Create an Application を選択します。Spectrum を初めて使う場合は、Create an Application モーダルが表示されます。

  3. Application Type を選択します。

  4. Domain に、Spectrum を使うドメインを入力します。

  5. Edge Port に、Cloudflare がアプリケーションに使うポートを入力します。

  6. Origin に、CNAME レコード名を入力します。

  7. Add を選択します。

API でアプリケーションを追加する

次は curl の例と、API へ送信するデータです。

API の例:

Required API token permissions

At least one of the following token permissions is required:
  • Zone Settings Write
Create Spectrum application using a name for the originbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/spectrum/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"dns": {
				"type": "CNAME",
				"name": "spectrum-cname.example.com"
		},
		"ip_firewall": false,
		"protocol": "tcp/22",
		"proxy_protocol": "off",
		"tls": "off",
		"origin_dns": {
				"name": "cname-to-origin.example.com",
				"ttl": 1200
		},
		"origin_port": 22
	}'

データの例:

{
	"dns": {
		"type": "CNAME",
		"name": "spectrum-cname.example.com"
	},
	"ip_firewall": false,
	"protocol": "tcp/22",
	"proxy_protocol": "off",
	"tls": "off",
	"origin_dns": {
		"name": "cname-to-origin.example.com",
		"ttl": 1200
	},
	"origin_port": 22
}

ロードバランサーで Spectrum アプリケーションを作成する

ロードバランサーで Spectrum アプリケーションを作成する場合は、ダッシュボードまたは API でロードバランサーを作成します。詳細は Load Balancing のドキュメント を参照してください。

ダッシュボードでアプリケーションを追加する

  1. Cloudflare ダッシュボードで Spectrum ページを開きます。

    Spectrum を開く ↗
  2. Create an Application を選択します。Spectrum を初めて使う場合は、Create an Application モーダルが表示されます。

  3. Application Type を選択します。

  4. Domain に、Spectrum を使うドメインを入力します。

  5. Edge Port に、Cloudflare がアプリケーションに使うポートを入力します。

  6. OriginLoad Balancer を選択します。

  7. ドロップダウンから使うロードバランサーを選択します。無効なロードバランサーは Load Balancer メニューに表示されません。

  8. Add を選択します。

API でアプリケーションを追加する

以下は curl の例と、API に POST するデータです。

API の例:

Required API token permissions

At least one of the following token permissions is required:
  • Zone Settings Write
Create Spectrum application using a name for the originbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/spectrum/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"dns": {
				"type": "CNAME",
				"name": "spectrum-cname.example.com"
		},
		"ip_firewall": false,
		"protocol": "tcp/22",
		"proxy_protocol": "off",
		"tls": "off",
		"origin_dns": {
				"name": "cname-to-origin.example.com",
				"ttl": 1200
		},
		"origin_port": 22
	}'

データの例:

{
  "dns": {
    "type": "CNAME",
    "name": "spectrum-cname.example.com"
  },
  "ip_firewall": false,
  "protocol": "tcp/22",
  "proxy_protocol": "off",
  "tls": "off",
  "origin_dns": {
    "name": "cname-to-origin.example.com",
    "ttl": 1200
  },
  "origin_port": 22
}

仮想ネットワークオリジンで Spectrum アプリケーションを作成する

プライベートネットワーク上のオリジンへ TCP または UDP トラフィックをプロキシするには、Cloudflare Tunnel の 仮想ネットワーク を Spectrum アプリケーションに関連付けます。Spectrum は、その仮想ネットワークに紐づくコネクター(Cloudflare Tunnel または Cloudflare WAN 接続)経由でトラフィックをルーティングします。プライベートオリジンの前にロードバランサーを置く従来の構成に代わる方法です。

仮想ネットワークオリジンは、TCP および UDP アプリケーションのみ対応します。オリジンは、指定した仮想ネットワーク内で到達できる単一のプライベート IP である必要があります。ポート範囲、ホスト名オリジン(origin_dns)、および origin_direct の複数アドレスは非対応です。現時点では Proxy Protocol は非対応のため、proxy_protocoloff に設定します。バリデーションエラーの詳細は エラーコード を参照してください。

仮想ネットワークの概要は 仮想ネットワーク を参照してください。

始める前に

Spectrum アプリケーションを作成する前に、仮想ネットワークと、オリジン IP をカバーするルートを用意します。

コネクターに Cloudflare WAN(旧 Magic WAN)を使う場合は、トンネルエンドポイントとルートの設定について Cloudflare WAN のはじめに を参照してください。

ダッシュボードでアプリケーションを追加する

  1. Cloudflare ダッシュボードで Spectrum ページを開きます。

    Spectrum を開く ↗
  2. Create an Application を選択します。

  3. Application TypeTCP または UDP を選びます。

  4. Domain に、Spectrum を使うドメインを入力します。

  5. Edge Port に、Cloudflare がアプリケーションに使うポートを入力します。

  6. OriginVirtual Network を選びます。

  7. Virtual Network で、オリジンを含む仮想ネットワークを選びます。

  8. IP に、オリジンのプライベート IP アドレスを入力します。

  9. Port に単一のポートを入力します(ポート範囲は非対応です)。

  10. Add を選択します。

API でアプリケーションを追加する

次は curl の例と、API へ送信するデータです。

API の例:

Required API token permissions

At least one of the following token permissions is required:
  • Zone Settings Write
Create Spectrum application using a name for the originbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/spectrum/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"protocol": "tcp/22",
		"dns": {
				"type": "CNAME",
				"name": "ssh.example.com"
		},
		"origin_direct": [
				"tcp://10.0.0.5:22"
		],
		"virtual_network_id": "f70ff985-a4ef-4643-bbbc-4a0ed4fc8415",
		"proxy_protocol": "off",
		"ip_firewall": true,
		"tls": "off",
		"edge_ips": {
				"type": "dynamic",
				"connectivity": "all"
		},
		"traffic_type": "direct"
	}'

origin_direct にはオリジンのプライベート IP を、virtual_network_id にはその IP が到達できる仮想ネットワークの ID を設定します。アカウントの仮想ネットワークは List virtual networks エンドポイントで一覧表示できます。

データの例:

{
	"success": true,
	"errors": [],
	"messages": [],
	"result": {
		"id": "ea95132c15732412d22c1476fa83f27a",
		"protocol": "tcp/22",
		"dns": {
			"type": "CNAME",
			"name": "ssh.example.com"
		},
		"origin_direct": ["tcp://10.0.0.5:22"],
		"virtual_network_id": "f70ff985-a4ef-4643-bbbc-4a0ed4fc8415",
		"proxy_protocol": "off",
		"ip_firewall": true,
		"tls": "off",
		"edge_ips": {
			"type": "dynamic",
			"connectivity": "all"
		},
		"traffic_type": "direct",
		"created_on": "2014-01-02T02:20:00Z",
		"modified_on": "2014-01-02T02:20:00Z"
	}
}

トラフィックを確認する

追加の設定なしで、Cloudflare 経由でトラフィックをプロキシできます。Cloudflare 経由でトラフィックを流すと、ダッシュボードの Spectrum に直近 1 分のトラフィックが表示されます。

フィードバックがある場合は、コミュニティへ投稿 してください。

役に立ちましたか?