Azure 仮想ネットワークと仮想サブネットの作成

スポンサーリンク

Azureのネットワークの基本概念である「仮想ネットワーク」と「サブネット」の考え方についてまとめます。Azureでは「仮想ネットワーク」の中に複数の「サブネット」を設ける事ができます。同一の「仮想ネットワーク」に属する「サブネット」同士は互いにルーティングできる状態になっています。

前提

公式ドキュメント

参考になる公式ドキュメントを以下に示します。

事前設定

以下、リソースグループを作成します。

az group create --name MyResourceGroup --location japaneast

仮想ネットワーク

仮想ネットワーク作成

Microsoft Azureでは「仮想ネットワーク」と「サブネット」と呼ばれる概念があります。「仮想ネットワーク」は大きなネットワークの塊で、「仮想ネットワーク」には複数の「サブネット」が収容されます。

まずは「仮想ネットワーク」を作成します。以下のようにaz network vnet createコマンドを使用します。

az network vnet create \
  --resource-group MyResourceGroup \
  --name Vnet01 \
  --address-prefix 172.16.0.0/16

サブネット作成

「仮想ネットワーク」には複数の「サブネット」を収容できます。以下はサブネットを2つ作成する操作例です。

az network vnet subnet create \
  --resource-group MyResourceGroup \
  --name Subnet01 \
  --vnet-name Vnet01 \
  --address-prefixes 172.16.1.0/24

az network vnet subnet create \
  --resource-group MyResourceGroup \
  --name Subnet02 \
  --vnet-name Vnet01 \
  --address-prefixes 172.16.2.0/24

疎通確認

疎通確認用の仮想マシン作成

同一の仮想ネットワーク内に格納されたサブネット同士は特段の考慮なしに互いに疎通可能になります。この事を動作確認してみましょう。

Subnet01とSubnet02に、それぞれ1台ずつの仮想マシンを作成します。

az vm create \
  --resource-group MyResourceGroup \
  --name linux01 \
  --image UbuntuLTS \
  --size Standard_B1s \
  --admin-username azureuser \
  --ssh-key-values ~/.ssh/authorized_keys \
  --vnet-name Vnet01 \
  --subnet Subnet01

az vm create \
  --resource-group MyResourceGroup \
  --name linux02 \
  --image UbuntuLTS \
  --size Standard_B1s \
  --admin-username azureuser \
  --ssh-key-values ~/.ssh/authorized_keys \
  --vnet-name Vnet01 \
  --subnet Subnet02

仮想マシン作成時のログは以下のようになります。仮想マシンのプライベートIPアドレスとパブリックIPアドレスが表示されるので、これをメモに控えましょう。

$ az vm create \
  --resource-group MyResourceGroup \
  --name linux01 \
  --image UbuntuLTS \
  --size Standard_B1s \
  --admin-username azureuser \
  --ssh-key-values ~/.ssh/authorized_keys \
  --vnet-name Vnet01 \
  --subnet Subnet01
It is recommended to use parameter "--public-ip-sku Standard" to create new VM with Standard public IP. Please note that the default public IP used for VM creation will be changed from Basic to Standard in the future.
{
  "fqdns": "",
  "id": "/subscriptions/2e2f81a9-b030-410f-9784-c582580c932e/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/linux01",
  "location": "japaneast",
  "macAddress": "00-0D-3A-50-AD-3E",
  "powerState": "VM running",
  "privateIpAddress": "172.16.1.4",
  "publicIpAddress": "20.89.105.29",
  "resourceGroup": "MyResourceGroup",
  "zones": ""
}

メモを失念してしまった場合は、showコマンドやポータルから再確認もできます。以下スクリーンショットのように「仮想マシン」の「概要」画面にはパブリックIPアドレスとプライベートIPアドレスが表示されています。

仮想マシンに割り当てられたIPアドレスの確認

仮想マシンにSSHでログインしてみましょう。

admin@mac19 ~ % ssh 20.89.105.29 -l azureuser
The authenticity of host '20.89.105.29 (20.89.105.29)' can't be established.
ED25519 key fingerprint is SHA256:xA7dFDN1d10r6DsyrNfIRP3BL+Fgpe90nSbTz0Hs2P8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '20.89.105.29' (ED25519) to the list of known hosts.
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 5.4.0-1072-azure x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Tue Mar 22 18:33:22 UTC 2022

  System load:  0.19              Processes:           116
  Usage of /:   4.7% of 28.90GB   Users logged in:     0
  Memory usage: 21%               IP address for eth0: 172.16.1.4
  Swap usage:   0%

0 updates can be applied immediately.



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

azureuser@linux01:~$ 

仮想マシン作成の構成説明

Azureに作成された仮想マシンはDHCPによってIPアドレスを割り当てられます。末尾「.1」がデフォルトゲートウェイで、「.2」「.3」は何らかの用途として予約されているようです。仮想マシンには「.4」から順番にIPアドレスが割り当てられます。

仮想マシンに割り当てられたIPアドレスとデフォルトゲートウェイを確認すると以下の通りです。

azureuser@linux01:~$ ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.1.4  netmask 255.255.255.0  broadcast 172.16.1.255
        inet6 fe80::20d:3aff:fe50:ad3e  prefixlen 64  scopeid 0x20<link>
        ether 00:0d:3a:50:ad:3e  txqueuelen 1000  (Ethernet)
        RX packets 3386  bytes 2570708 (2.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2113  bytes 540588 (540.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 184  bytes 17104 (17.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 184  bytes 17104 (17.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

azureuser@linux01:~$ 
azureuser@linux01:~$ 
azureuser@linux01:~$ ip route
default via 172.16.1.1 dev eth0 proto dhcp src 172.16.1.4 metric 100 
168.63.129.16 via 172.16.1.1 dev eth0 proto dhcp src 172.16.1.4 metric 100 
169.254.169.254 via 172.16.1.1 dev eth0 proto dhcp src 172.16.1.4 metric 100 
172.16.1.0/24 dev eth0 proto kernel scope link src 172.16.1.4 
azureuser@linux01:~$ 

疎通確認

Subnet01に作成された仮想マシンから、Subent02に作成された仮想マシンへ、pingの疎通確認をします。特別な設定なしに、同一の仮想ネットワークに属するサブネット同士は疎通可能な事が分かりました。

azureuser@linux01:~$ ping 172.16.2.4 -c 3
PING 172.16.2.4 (172.16.2.4) 56(84) bytes of data.
64 bytes from 172.16.2.4: icmp_seq=1 ttl=64 time=2.79 ms
64 bytes from 172.16.2.4: icmp_seq=2 ttl=64 time=1.79 ms
64 bytes from 172.16.2.4: icmp_seq=3 ttl=64 time=1.00 ms

--- 172.16.2.4 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.003/1.864/2.791/0.731 ms
azureuser@linux01:~$ 
タイトルとURLをコピーしました