LoginSignup
2
2

More than 5 years have passed since last update.

Oracle Cloud 仮想ネットワーク を cli で作成

Last updated at Posted at 2019-02-01

はじめに

Oracle Cloud の勉強の一環で、公式のチュートリアルを進めています。公式のチュートリアルでは日本語、かつ、GUI操作の内容となっています。わかりやすく書かれているので、基本はこちらを参照していただけるとよいと思います。

このQiitaの記事は、上記のチュートリアルを CLI であえて実施した備忘録として書きます。
CLI の理由は、GUIと比べて再現性や再実行性が高いのと、なんとなくかっこいいから

今回のテーマ

Virtual Cloud Network を作成
https://community.oracle.com/docs/DOC-1019114

前提作業

oci cli と jq コマンドを使用可能なこと。次のQiita記事で導入した手順を書いています
https://qiita.com/sugimount/items/63a8cfe1163030ae8804

Virtual Cloud Network を作成

VCNを作成します。以下のパラメータを指定

  • CIDR を指定
  • VCNの名前を指定
  • VCN 内部で使用される Resolver に付与する、VCN名を指定
oci network vcn create --cidr-block 172.16.0.0/16 --display-name TutorialVCN --dns-label tutorial

作成したVCNのOCID (Oracle Cloud Identifier) を変数に格納。 変数格納の書式は fish shell となっています

set vcn_ocid (oci network vcn list | jq -r '.data | map(select(.["display-name"] == "TutorialVCN"))[].id')

memo VCNの削除

oci network vcn delete --vcn-id $vcn_ocid --force

Public Subnet を作成

作成したVCNにSubnet を3つ作成します。以下のパラメータを指定します。
若干わかりにくいパラメータを説明すると、--prohibit-public-ip-on-vnic は、Public Subnet か Private Subnet のどちらを作成するか指定します。

oci network subnet create --availability-domain AJtg:US-ASHBURN-AD-1 --cidr-block 172.16.1.0/24 --vcn-id $vcn_ocid --display-name tutorial_subnet1 --dns-label subnet1 --prohibit-public-ip-on-vnic false
oci network subnet create --availability-domain AJtg:US-ASHBURN-AD-2 --cidr-block 172.16.2.0/24 --vcn-id $vcn_ocid --display-name tutorial_subnet2 --dns-label subnet2 --prohibit-public-ip-on-vnic false
oci network subnet create --availability-domain AJtg:US-ASHBURN-AD-3 --cidr-block 172.16.3.0/24 --vcn-id $vcn_ocid --display-name tutorial_subnet3 --dns-label subnet3 --prohibit-public-ip-on-vnic false

Internet Gateway を作成

Internet側から、VCN上のインスタンスへアクセスできるように、Internet Gateway を作成します

oci network internet-gateway create --is-enabled true --vcn-id $vcn_ocid --display-name tutorial-int-gw1

作成したInternet GatewayのOCID (Oracle Cloud Identifier) を変数に格納。 変数格納の書式は fish shell となっています

set ig_ocid (oci network internet-gateway list --vcn-id $vcn_ocid | jq -r '.data | map(select(.["display-name"] == "tutorial-int-gw1"))[].id')

Route Table に Internet Gateway を使用した Static Route を指定

VCNを作成したときに、DefaultのRoute Tables が作成されています。これのデフォルトルート (0.0.0.0/0) に対して、作成したInternet Gateway を指定します。

まずは、Route Table の OCID を変数に格納します

set routetable_ocid (oci network route-table list --vcn-id $vcn_ocid  | jq -r '.data | map(select(.["display-name"] == "Default Route Table for TutorialVCN"))[].id')

Route Table に デフォルトルートとして、Internet Gateway を指定します。

route-rules で指定するルールは、上書きになるので注意してください。複数ルールが追加されている状態で、1個のルールを追加したい場合は、既存のものもJSONで指定しないと消えます

oci network route-table update --rt-id $routetable_ocid --route-rules "[{\"cidrBlock\":\"0.0.0.0/0\",\"networkEntityId\":\"$ig_ocid\"}]"

Security Listを確認

以下のコマンドで VCN 上に存在している Security List のルールを確認します。
VCN → Internet への通信です。

> oci network security-list list --vcn-id $vcn_ocid | jq '.data[0]."egress-security-rules"'
[
  {
    "destination": "0.0.0.0/0",
    "destination-type": "CIDR_BLOCK",
    "icmp-options": null,
    "is-stateless": false,
    "protocol": "all",
    "tcp-options": null,
    "udp-options": null
  }
]

Internet → VCNへの通信です。

> oci network security-list list --vcn-id $vcn_ocid | jq '.data[0]."ingress-security-rules"'
[
  {
    "icmp-options": null,
    "is-stateless": false,
    "protocol": "6",
    "source": "0.0.0.0/0",
    "source-type": "CIDR_BLOCK",
    "tcp-options": {
      "destination-port-range": {
        "max": 22,
        "min": 22
      },
      "source-port-range": null
    },
    "udp-options": null
  },
  {
    "icmp-options": {
      "code": 4,
      "type": 3
    },
    "is-stateless": false,
    "protocol": "1",
    "source": "0.0.0.0/0",
    "source-type": "CIDR_BLOCK",
    "tcp-options": null,
    "udp-options": null
  },
  {
    "icmp-options": {
      "code": null,
      "type": 3
    },
    "is-stateless": false,
    "protocol": "1",
    "source": "172.16.0.0/16",
    "source-type": "CIDR_BLOCK",
    "tcp-options": null,
    "udp-options": null
  }
]

DHCP Optionを確認

> oci network dhcp-options list --vcn-id $vcn_ocid | jq '.data[0].options'
[
  {
    "custom-dns-servers": [],
    "server-type": "VcnLocalPlusInternet",
    "type": "DomainNameServer"
  },
  {
    "search-domain-names": [
      "tutorial.oraclevcn.com"
    ],
    "type": "SearchDomain"
  }
]

参考URL

チュートリアル一覧

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2