AZ-104: Configure and manage virtual networks for Azure administrators

Note: สำหรับ Blog นี้ ผมย้ายมาจาก Notion ที่เขียนไว้ตอนเดือน 9-10 ปีที่แล้วนะครับ บาง Service อย่าง Azure AD มีเปลี่ยนชื่อเป็น Microsoft Entra ID เป็นต้นครับ

ปรับฐานกันก่อน

Configure virtual networks

Azure network services

Virtual Network (VNET)

VNET อันนี้ผมเข้าใจนะ มันพวก Hub / Switch แต่ย้ายจาก Physical มา Logical และมีคุณสมบัติอื่นๆ

  • ทำ VPN ได้ - จะเอาไปทำ site-to-site VPNs / Link Hybrid Cloud
  • รองรับ CIDR (Classless Inter-Domain Routing) เป็นวิธีการกำหนด mask ว่ามี IP เท่าไหร่ เพื่อที่จไปแบ่ง subnet
  • VNET ต่อได้ตามรูปเลย On-Premise / VNET

Subnet

จาก VNET มาซอยเป็น Subnet ได้

  • VNET แบ่งหลาย Subnet ก็ได้ IP ห้ามทับกัน (unique within the address space / can't overlap)
  • Reserved addresses - ถ้า IP กำหนดเป็น 192.168.1.0/24 ตัว Azure Reserved 5 IP
    - .0 ของ VNET
    - .1 default gateway
    - .2/.3 Azure DNS IP addresses
    - .255 virtual network broadcast address.
  • subnets ต้องรู้่ก่อน
    - กำหนด IP address space ****แน่นอน วง 10. / 192. / 128.
    - service requirements/resource อะไรบ้าง
    - แยกวง (Subnet) ไหม แบบ App / DB / Storage เสริมด้วย network security groups
    Note Azure private links ตัวเชื่อมระหว่าง VNET กับพวก PAAS
    - private links

อื่นๆ

NOTE: Azure Virtual Network enables communication between Azure resources.

Configure Network Security Groups

  • network security groups
    - DMZ ของ Subnet หรือ NIC ****
    - A DMZ acts as a buffer(Filter Security Rules) between resources
    - ตอนสร้าง NSG มา มันจะ DenyAllInbound traffic and AllowInternetOutbound
  • network security group rules
    - Name
    - Priority เริ่มจาก 65500 overrides by the higher Priority setting
    - Port
    - Protocol (Any, TCP, UDP)
    - Source (Any, IP addresses, Service tag)
    - Destination (Any, IP addresses, Virtual network)
    - Action (Allow or Deny)
  • Determine network security group effective rules
    - For inbound traffic, Azure first processes network security group security rules for any associated subnets and then any associated network interfaces.
    - For outbound traffic, the process is reversed. Azure first evaluates network security group security rules for any associated network interfaces followed by any associated subnets.
    - For both the inbound and outbound evaluation process, Azure also checks how to apply the rules for intra-subnet traffic.
EvaluationSubnet NSGNIC NSGInbound rulesOutbound rules
VM 1Subnet 1NSG 1NIC NSG 2NSG 1 subnet rules have precedence over NSG 2 NIC rulesNSG 2 NIC rules have precedence over NSG 1 subnet rules
VM 2Subnet 1NSG 1NIC noneNSG 1 subnet rules apply to both subnet and NICAzure default rules apply to NICand NSG 1 subnet rules apply to subnet only
VM 3Subnet 2noneNIC NSG 2Azure default rules apply to subnet and NSG 2 rules apply to NICNSG 2 NIC rules apply to NIC and subnet
VM 4Subnet 3noneNIC noneAzure default rules apply to both subnet and NIC and all inbound traffic is allowedAzure default rules apply to both subnet and NICand all outbound traffic is allowed

NOTE:

  • intra-subnet traffic - ปกติแล้ว ถ้ากำหนด Allow ไว้ ทุก Resource จะได้เห็นหมด ถ้าไม่อยากให้คุยกัน เช่น VM ตั้ง Rule มาครอบอีกที
  • allow rules ทำทั้ง subnet + network interface
  • rule priority ใช้เป็นช่วง เผื่อไว้ จะได้ไม่ต้องมา repriority หมด

View effective security rules - ดูว่าเราโดน Rule ไหนอยู่

What's a valid service tag for network security group rules?

Correct. VirtualNetwork is a valid service tag. Service tags represent a group of IP addresses. Other service tags are InternetSQLStorageAzureLoadBalancer, and AzureTrafficManager.

Configure Azure DNS

Azure DNS enables you to host your DNS domains in Azure and access name resolution for your domains by using Microsoft Azure infrastructure

Azure AD (Microsoft Entra ID)

  • และทำสถานะเป็น verified ถึงจะใช้งานได้ โดยใน RFC 1035 มี record 2 แบบ MX (or Mail exchange) / TXT (or Text)
  • รอไปสักพัก

NOTE:

  • ชื่อ Azure DNS zone ใน Resource Group ต้อง Unique นั้นแสดงว่ากำหนดซ้ำได้ ดังนั้น each DNS zone instance is assigned to a different DNS name server address. //ตอนนี้ยัง เข้าใจว่า Point to nearest region นะ
  • The Root/Parent domain is registered at the registrar and then pointed to Azure DNS. - DNS ต้องไปซื่้อกับ Registrar ก่อน จากนั้นเอาชื่อ Domain มากำหนด name server บน Azure DNS
  • Child domains (Sub Domain) are registered directly in Azure DNS.

ดูอันนี้ Azure DNS delegation overview | Microsoft Learn จะได้เข้าใจ Azure DNS / Azure DNS Zone / Delegate DNS

Delegate DNS domains

The delegation process for your domain involves several steps:

  • Identify your DNS name servers - สร้าง Azure DNS Zone ก่อน
  • Update your parent domain
    - บอกให้ registrar รู้ว่า DNS มีแก้แล้วนะ โดย แก่ไข NS records (เช่น ns3-02.azure-dns.org. เอาจุดด้วย) มาเป็นของ Azure DNS
    - To delegate your domain to Azure DNS, you must use the exact names of the DNS name servers as created by Azure DNS.
  • Delegate subdomains (optional)
    - You can delegate a subdomain for your domain in Azure DNS by setting up a separate child DNS zone.
    - ยกตัวอย่าง เช่น Azure AD domain custom domain azureadmininc.org แต่เราจะแยก partners.azureadmininc.org สำหรับ partners child DNS zone

Add DNS record sets

1.DNS record sets(resource record set) - collection of records in a DNS zone

NAME                                  TYPE   VALUE
--------------------------------------------------
bar.example.com.                      CNAME  foo.example.com.
www.contoso.com.        3600    IN    A     134.170.185.46
www.contoso.com.        3600    IN    A     134.170.188.221

2.Individual DNS records

Plan for Azure Private DNS zones

  • ทำ DNS ใช้ในองค์กรเอง จากเดิมต้องใช้ชื่อที่ Azure ให้มา หรือ ต้องไปตั้ง VM แยกแล้วจัดการ
  • Azure Private DNS manages and resolves domain names in a virtual network without adding a custom DNS solution.
  • จุดเด่น
    - No custom DNS solution is required
    - Support for common DNS records types - A, AAAA, CNAME, MX, PTR, SOA, SRV, and TXT.
    - Automatic hostname record management
    - Hostname resolution between virtual networks
    - Familiar tools and user experience
    - Split-horizon DNS support - Resolve to different answers from within a virtual network and from the public internet
    - Azure region support

Review Azure Private DNS zone scenarios

Scenario 1: Name resolution scoped to a single virtual network - Azure should automatically register the virtual machines within the virtual network into the DNS zone.

Scenario 2: Name resolution for multiple networks

Configure Azure Virtual Network peering

VNET peering - ทำให้ VNET แต่ละอัน regions เดียวกัน (Regional) หรือ ต่างกัน(Global) ให้คุยกันได้

  • Global peering of virtual networks in different Azure Government cloud regions isn't permitted. แต่ของจีนทำได้
  • Benefit
    - Private network connections - เมื่อทำ VNET Peering มันจะวิ่งใน Network Azure backbone network.
    - Strong performance
    - Simplified communication
    - Seamless data transfer
    - No resource disruptions
    - ไม่ downtime ตอนทำ VNET Peering

Azure VPN gateway - A virtual network can have only one VPN gateway. จากรูปข้างบนจะบอกว่า

  • VNET A ↔ Hub VNET ↔ VNET B
    - VNET B > ทำ site-to-site On-Premise ผ่าน VPN gateway
    - NVA (Network Virtual Appliance) Route Traffic
  • พอมี Azure VPN Gateway - ต้องกับ resources outside เช่น
    - site-to-site : VPN to connect to an on-premises network.
    - vnet-to-vnet : connection to another virtual network.
    - point-to-site : VPN to connect to a client.

Gateway transit allows peered virtual networks to share the gateway and get access to resources

  • When you configure virtual network peering. you can choose to open or close the network security group to block or allow access to other virtual networks or subnets

Create virtual network peering

  • Role Network Contributor or Classic Network Contributor หรือ อื่นๆได้ Network Permissions.
  • How to create a virtual network peering
    - Create two virtual networks
    - first virtual network to use in the peering, and select Settings > Add (peering).
    - กำหนด Config VNET / Remote VNET (เลือก Subscription / VNET ปลายทาง)
    - Option Block ยังเปิดจาก Network Security Group Allow ได้นะ
  • Your peering isn't successfully established until both virtual networks in the peering have a status of Connected.

Extend peering with user-defined routes and service chaining

เอามาแก้ปัญหา VNET A B C
- A peer B
- B peer C
- แต่ไม่ต้องมาทำ A Peer C นะ เดวมันมีตัวช่วย 3 แบบ

ตัวช่วย (extending peering) มี 3 แบบ

  • Hub and spoke networks
    - hub virtual network NVA or Azure VPN gateway ให้ Traffic ผ่าน
    - spoke virtual networks can then peer with the hub virtual network.
    จากรูป VNET C <-> Hub NVA <-> VNET C
    จากรูป VNET C <-> Hub VPN Gateway <-> VNET C
  • User-defined routes
  • Service chaining - define UDRs. These routes direct traffic from one virtual network to an NVA or VPN gateway.

Lab: Configure Azure Virtual Network peering: Interactive lab simulation

Knowledge Check: Configure Azure Virtual Network peering: Knowledge Check

Configure network routing and endpoints

network routes - tools control the flow of traffic through a network มี 2 แบบ

  • system routes
    • Azure uses system routes to direct network traffic between virtual machines, on-premises networks, and the internet. Information about the system routes is recorded in a route table.
    • route table ตารางบอก ว่า packet ไปที่ไหน ดูจาก matched to routes by using the destination (IP / VPN Gateway / NVM / Internet)
    • ตัวอย่างกำหนด system routes ให้ back-end subnet ต่อได้เฉพาะ front-end subnet
  • User-defined routes
    • user-defined routes บอก Next Hop ว่าควรไปที่ไหน 1 route > n subnets
    • Next Hop - พวก VNET gateway / VNET network / Internet / Network virtual appliance (NVA)
    • ตัวอย่าง ปรับจากอันก่อนหน้าที่ใช้ system routes เป็น NVA + User-defined routes

Virtual network endpoints extend the private address space in Azure. Endpoints restrict the flow of traffic. As service endpoints are created, Azure creates routes in the route table to direct the traffic.

  • Service endpoints - secure Azure service resources to your virtual network by adding a virtual network rule to the resources. โดยมาช่วย
    - improved security for resources.
    - optimal routing for service traffic - จากตัวอย่างข้างต้น ตอนแรกใช้ VM (10.1.1.4) ใช้ Public IP Access Storage Account มันจะวนรอบโลก และไม่ Secure ถ้าทำ Service endpoints คราวนี้จะใช้ Azure Network แทน
    - direct traffic to the Microsoft network - แต่ยังมีบางจุดที่ยังเป็น Public IP นะ เข้าตัว Site-to-Site Peering
    - easy configuration and maintenance
    - อะไรที่ใช้ Service endpoints ได้ Azure Storage / Azure SQL Database and Azure SQL Data Warehouse / Azure Database for PostgreSQL, MySQL / Azure Cosmos DB / Azure Key Vault / Azure Service Bus and Azure Event Hubs
  • Azure Private Link - ทำให้การเชื่อมต่อระหว่าง On-Prem กับคลาวด์วิ่งผ่าน Private Endpoint เท่านั้น ไม่ผ่านเกตเวย์, VPN, ExpressRoute หรือผ่าน Public IP
    - integration with on-premises and peered networks.
    - protection against data exfiltration (ข้อมูลรั่วไหล) for Azure resources - Map private endpoints กับ Azure PaaS resources อยู่ใน Private Network Leak ยากขึ้น
    - services delivered directly to customer virtual networks

Lab: Configure network routing and endpoints: Interactive lab simulation
Knowledge Check: Configure network routing and endpoints: Knowledge Check

Configure Azure Load Balancer

Azure Load Balancer - ใช้เมื่อ applications need to be resilient to failure and scale easily when demand increases.

  • ใช้ในมุม public or internal load balancer

การใช้งานตัว Azure Load Balancer มี 4 ส่วน ได้แก่

Public Load Balancer & Internal Load balancer

  • ใช้กับ Resource ใน virtual network / cross-premises virtual network
  • multi-tier applications
    - External public load balancer
    - Internal app กับ db ใช้ internal load balancer
  • scale line-of-business applications

SKU - ถ้า Prod ควรเลือก Standard มี https

Load balance Rule - default แบ่งเท่ากัน five-tuple hash to map

  • IP version (IPv4 or IPv6)
  • Front-end IP address, *Port, and Protocol (TCP or UDP)
  • Back-end pool and Back-end port
  • Health probe
  • Session persistence
    - None (default)
    - Client IP: IP เดิมจะได้ Back End เดิม
    - Client IP and protocol: IP+protocol เดิมจะได้ Back End เดิม

Lab: Configure Azure Load Balancer: Interactive lab simulation
Knowledge Check: Configure Azure Load Balancer: Knowledge Check

Configure Azure Application Gateway

Azure Application Gateway is a load balancer for web traffic (Application layer routing)

  • Round-robin load balancing
  • Session stickiness-ทุก Request ได้ Server (Backend) เดิมเสมอ
  • Supported protocols-HTTP, HTTPS, HTTP/2, or WebSocket
  • Load autoscaling
  • Round-robin load balancing

traffic routing type

  • Path-based routing
  • Multi-site routing
  • redirect traffic เช่น http > https
  • rewrite HTTP headers / create custom error pages instead of displaying default error pages.

Configure Azure Application Gateway components

  • Front-end IP address
  • Firewall (optional) - Azure Web Application Firewall based on OWASP
  • Listeners
    - Basic (Path-based routing)
    - Multi-site routing
  • Routing rules - binds your listeners to the back-end pools. based on HTTP settings, protocol, session stickiness, connection draining, request timeout period, and health probes.
  • Back-end pools ตัวรับงานตาม Request
  • Health probes

Knowledge Check: Configure Azure Application Gateway: Knowledge check

Design an IP addressing schema for your Azure deployment

Plan IP addressing for your networks

  • คำถามสกัด Requirement
    - How many devices do you have on the network?
    - How many devices are you planning to add to the network in the future?
  • ขยายด้วย
    - Based on the services running on the infrastructure, what devices do you need to separate?
    - How many subnets do you need?
    - How many devices per subnet will you have?
    - How many devices are you planning to add to the subnets in future?
    - Are all subnets going to be the same size?
    - How many subnets do you want or plan to add in future?
  • เพิ่มด้วยตัว classless inter-domain routing (CIDR) - Address Pattern จะได้ลอง IP ได้ถูก

Lab: Exercise - Design and implement IP addressing for Azure virtual networks

Distribute your services across Azure virtual networks and integrate them by using virtual network peering

Connect services by using virtual network peering - RECAP VNET Peering

  • VNET Peering ทำได้ทั้งใน Region / Global
  • Reciprocal connections ทำทั้ง 2 ขา โดย Azure portal กดปุ๊บมันได้เลย แต่ถ้า Azure PowerShell / Azure CLI ต้องเขียน Script ทั้ง 2 ขา
//SalesVNet-To-MarketingVNet

az network vnet peering create \
    --name SalesVNet-To-MarketingVNet \
    --remote-vnet MarketingVNet \
    --resource-group learn-b4987a2d-014f-4e2b-8132-7e1466678fd3 \
    --vnet-name SalesVNet \
    --allow-vnet-access


az network vnet peering create \
    --name MarketingVNet-To-SalesVNet \
    --remote-vnet SalesVNet \
    --resource-group learn-b4987a2d-014f-4e2b-8132-7e1466678fd3 \
    --vnet-name MarketingVNet \
    --allow-vnet-access
  • VNET Peering ไม่ Transitivity เช่น VNET A <-> B <-> C //VNET A ไปหา C ไม่ต้องนะ ต้องทำ Peering A / C หรือใช้ตัวอื่นๆ ถ้าต้องการทำจริงๆ เช่น เคส On Premise ใช้ Gateway transit มาแทน
  • Address Space ของ VNET ห้าม Overlapping กัน

Host your domain on Azure DNS (LAB)

What is Azure DNS? //สรุป >> Azure DNS Knowledge Check

  • How DNS Work
  • DNS record types]
    - A: The IPv4 domain name-mapping record.
    - AAAA: The IPv6 domain name-mapping record.
    - CNAME is a Canonical Name record //alias from one domain name to another domain name. which links to the A record.
    - MX is the mail exchange record
    - TXT is the text record //verify domain ownership. (Azure)
  • Record sets ตารางให้มา Lookup

Azure DNS acts as

  • the SOA(start of Authority=บันทึกข้อมูลกี่ยวกับโดเมนหรือ DNS Zone เช่น ที่อยู่อีเมลของผู้ดูแลระบบ เวลาที่โดเมนได้รับการอัปเดตครั้งล่าสุด และ TTL=Time to Live //ระยะเวลาที่เซิร์ฟเวอร์รอระหว่างการรีเฟรช) for the domain
  • Domain lookup requests (Name Server)
  • The SOA and NS records are created automatically when you create a DNS zone by using Azure DNS.
  • Benefit Improved security / Ease of use / Private DNS domains / Alias record sets

Configure Azure DNS to host your domain

#Verify your global Azure DNS
#==================================

nslookup www.wideworldimportsXXXX.com <name server address>

nslookup www.wideworldimportsPING.com ns1-33.azure-dns.com
nslookup www.wideworldimportsPING.com ns3-33.azure-dns.org
  • AZURE จับกับ Resource จัดการ alias records เช่น A Traffic Manager profile - Load Balancer / Azure Content Delivery Network endpoints / A public IP resource / A front door profile
    - apex domain (root domain)
    - alias records ช่วย
    >> Prevents dangling DNS records
    >> Updates DNS record set automatically when IP addresses change
    >> Hosts load-balanced applications at the zone apex >> Taffic Manager.
    >> Points zone apex to Azure Content Delivery Network endpoints
    - Exercise - Create alias records for Azure DNS

Manage and control traffic flow in your Azure deployment with routes (LAB)

custom route - used to override the default Azure routing so that you can route traffic through a network virtual appliance (NVA)

  • You can't create or delete system routes, but you can override the system routes by adding custom routes to control traffic flow to the next hop.

custom route Priority

  1. User-defined routes ให้ไปผ่านจาก Virtual appliance / Virtual network gateway / Virtual network / Internet / None
  2. BGP routes - พวก Router หา Shortest Path
    1. ถ้าไม่มีแล้วไปผ่าน System routes

    virtual network peering - เอา VNET มาต่อกัน เพื่อ Share Resource

    network virtual appliance -เวลาใช้งานใน Azure สามารถ สร้างจาก IaaS VM หรือ partner image จาก Azure Marketplace มาทำ NVA

    other system routes

    • Virtual network peering and service chaining (NVA / VPN Gateway)
    • Virtual network gateway (SITE-to-SITE vpn)
    • Virtual network service endpoint (Private End Point)
    • BGP routes

    Lab

    #Network Interface เปิด IP Forwarding 
    
    NICID=$(az vm nic list \
        --resource-group [sandbox resource group name] \
        --vm-name nva \
        --query "[].{id:id}" --output tsv)
    echo $NICID
    ==========================================================
    NICNAME=$(az vm nic show \
        --resource-group [sandbox resource group name] \
        --vm-name nva \
        --nic $NICID \
        --query "{name:name}" --output tsv)
    echo $NICNAME
    ==========================================================
    az network nic update --name $NICNAME \
        --resource-group [sandbox resource group name] \
        --ip-forwarding true
    
    
    #Enable IP forwarding in the appliance
    NVAIP="$(az vm list-ip-addresses \
        --resource-group [sandbox resource group name] \
        --name nva \
        --query "[].virtualMachine.network.publicIpAddresses[*].ipAddress" \
        --output tsv)"
    echo $NVAIP
    ==========================================================
    ssh -t -o StrictHostKeyChecking=no azureuser@$NVAIP 'sudo sysctl -w net.ipv4.ip_forward=1; exit;'

    Improve application scalability and resiliency by using Azure Load Balancer

    Azure Load Balancer (Knowledge Check)

    • distribute traffic across multiple virtual machines
    • Five-tuple hash
      - Source IP
      - Source port
      - Destination IP
      - Destination port
      - Protocol type: The specified protocol type, TCP or UDP.
    • Basic / Standard (https)

    Load Balancer ใช้กับ

    • Availability set (99.95%)
    • Availability zone (99.99%)

    External / Internal Load Balancer (Knowledge Check)

    • External LB
      - Public IP Address
      - Virtual machines must be in the same virtual network.
    • Choose the distribution mode
      - 2-turple hash - Source IP affinity - IP Source + IP Desc
      - 3-turple hash IP Source + IP Desc + Protocol
      - 5-turple hash (greatest scalability and resilience)

    จากรูป Service พวกนี้ ถ้าจะ improve

    • Azure Load Balancer
    • Private Link Service - Service Running behind Azure Load Balancer, so that consumer your service privatly from VNET
      - Private Link ปกติ Azure ใช้ Public IP คุยกัน แต่รอบนี้ใช้ Private IP
    • Private Endpoint - network interface that use private ip address

    Lab: Azure - Configure Global VNet to VNet Peering - IT Infra Engineer

    Reference


    Discover more from naiwaen@DebuggingSoft

    Subscribe to get the latest posts to your email.