0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

既存の VNET 統合済み AppService に後から NAT ゲートウェイを追加してみた

Posted at

AppService 送信されるトラフィックは、AppService が持っている複数の送信 IP アドレスが使用されます。例えば、対向先のシステムで IP アドレス制限をしたい場合、これらの送信 IP アドレスを全て許可すれば良いのですが、他人の AppService からも許可してしまうことになります。そこで、静的なパブリック IP アドレスを付与した NAT ゲートウェイを追加して、送信 IP アドレスを一つに固定してみました。

検証用 VNET 統合 AppService を用意

bash
prefix=mnrappnat
region=japaneast

az group create \
  --name ${prefix}-rg \
  --location $region

az network vnet create \
  --name ${prefix}-vnet \
  --resource-group ${prefix}-rg \
  --address-prefixes 10.0.0.0/24

az network nsg create \
  --resource-group ${prefix}-rg \
  --name ${prefix}-nsg

az network vnet subnet create \
  --resource-group ${prefix}-rg \
  --vnet-name ${prefix}-vnet \
  --name app-subnet \
  --address-prefix 10.0.0.0/26 \
  --network-security-group ${prefix}-nsg

az appservice plan create \
  --name ${prefix}-plan \
  --resource-group ${prefix}-rg \
  --is-linux \
  --sku B1

az webapp create \
  --name ${prefix}-app \
  --resource-group ${prefix}-rg \
  --plan ${prefix}-plan \
  --runtime "PHP|8.2" \
  --https-only true

az webapp config set \
  --name ${prefix}-app \
  --resource-group ${prefix}-rg \
  --always-on true \
  --ftps-state Disabled

az webapp vnet-integration add \
  --name ${prefix}-app \
  --resource-group ${prefix}-rg \
  --vnet ${prefix}-vnet \
  --subnet app-subnet

AppService の SSH から送信 IP アドレスを確認

appservice-natgw-02.png

下記、赤枠の送信 IP アドレスが使用されています。

appservice-natgw-01.png

NAT ゲートウェイを追加

bash
az network public-ip create \
  --resource-group ${prefix}-rg \
  --name ${prefix}-pip \
  --sku Standard

az network nat gateway create \
  --resource-group ${prefix}-rg \
  --name ${prefix}-ngw \
  --public-ip-addresses ${prefix}-pip

az network vnet subnet update \
  --name app-subnet \
  --resource-group ${prefix}-rg \
  --vnet-name ${prefix}-vnet \
  --nat-gateway ${prefix}-ngw

AppService のトラフィック全てを VNET に向ける

bash
az webapp config set \
  --resource-group ${prefix}-rg \
  --name ${prefix}-app \
  --vnet-route-all-enabled

下記の「送信インターネットトラフィック」にチェックを入れるのと同じです。

appservice-natgw-05.png

再度、AppService の SSH から送信 IP アドレスを確認

appservice-natgw-04.png

下記の静的 IP アドレスが使われるようになりました。

appservice-natgw-03.png

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?