IP 地址白名單
白名單中,可以是單一IP,也可以是CIDR IP 區間(CIDR-notated range of addresses)。
CIDR IP 區間
甚麼是CIDR IP 區間?
舉例來說:
- 10.0.0.0/24 代表的最小IP是10.0.0.0,最大IP是10.0.0.255
- 10.0.0.0/16 代表的最小IP是10.0.0.0,最大IP是10.0.255.255
- 10.0.0.0/8 代表的最小IP是10.0.0.0,最大IP是10.255.255.255
- 0.0.0.0/0 代表說有的IP
- 10.0.0.0/32 代表單一IP,即10.0.0.0
摘錄 https://www.ipaddressguide.com/cidr 網站的一段話
CIDR is the short for Classless Inter-Domain Routing, an IP addressing scheme that replaces the older system based on classes A, B, and C. A single IP address can be used to designate many unique IP addresses with CIDR. A CIDR IP address looks like a normal IP address except that it ends with a slash followed by a number, called the IP network prefix. CIDR addresses reduce the size of routing tables and make more IP addresses available within organizations.
該網站也提供CIDR IP 區間對應的最小IP、最大IP與Netmask。
將 Azure Web App 的 IP 地址列入白名單
Azure Web App 要存取 MongoDB Atlas,必須將 App 的 outbound IP 地址列入資料庫的白名單中。
問題來了,App 的 outbound IP 地址不是一個而是一大串(當 App Scale Up/Down 時還會變動)。
我們可以用 Azure Powershell 指令 (Get-AzWebApp -Name gglapp-azure).outboundIpAddresses 來取得 outbound IP 群後,在資料庫端的 Network Access > IP Access IP List > Add Ip Address 裡一筆一筆的的加入白名單內。
請參考 Azure App Service Documentation > Concepts > Networking > Inbound and outbound IPs 的 https://docs.microsoft.com/en-us/azure/app-service/overview-inbound-outbound-ips 。