Geavanceerd
Zoeken inLabs
Zo zoek je
  • Zoek een taak of een tool (lvm, selinux, @podman); filter op niveau en op boek of cursus.
  • Met een leeg zoekvak toont een filter alleen al de labs — bijvoorbeeld alle moeilijke labs van één cursus.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Lab 9.1AZ-104, Hoofdstuk 9

Hub and spoke: two VNets, peering, an NSG and a test VM

Niveau
Moeilijk
60 min
Machines
Azure subscription, Azure CLI or Cloud Shell
Status
Nog niet begonnen

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Doel

Build a small hub-and-spoke network: a hub VNet and a spoke VNet with address spaces that do not overlap, peering in both directions, a private DNS zone, and a network security group that allows SSH only from the hub. You prove it with two small VMs and the effective security rules. Delete everything at the end; the VMs cost only a few cents.

Voordat je begint

  • Cloud Shell (Bash) or az login. Variables: RG=rg-lab-net, LOC=westeurope.
  • Plan the addresses first: hub 10.10.0.0/16 (subnet 10.10.1.0/24), spoke 10.20.0.0/16 (subnet 10.20.1.0/24).

Taken

  1. Make the resource group and the two VNets with one subnet each.
  2. Peer the VNets in both directions with allow forwarded traffic.
  3. Make the private DNS zone lab.internal, link it to both VNets with auto-registration.
  4. Make the NSG nsg-spoke with one inbound rule: allow TCP 22 only from 10.10.0.0/16, priority 100. Attach it to the spoke subnet.
  5. Create a small Ubuntu VM vm-hub in the hub (with a public IP) and vm-spoke in the spoke (no public IP).
  6. From vm-hub, SSH to vm-spoke by its DNS name vm-spoke.lab.internal.
  7. Show the effective security rules of the NIC of vm-spoke and explain which rule allowed your SSH.
  8. Delete the resource group.

Controleer je werk

az network vnet peering list -g $RG --vnet-name vnet-hub -o table
az network private-dns record-set a list -g $RG -z lab.internal -o table
az network nsg rule list -g $RG --nsg-name nsg-spoke -o table
az network nic list-effective-nsg -g $RG -n vm-spokeVMNic
  • Both peerings show PeeringState Connected.
  • The DNS zone has A records for vm-hub and vm-spoke (made by auto-registration).
  • SSH from vm-hub to vm-spoke.lab.internal works; SSH from the internet to vm-spoke is impossible (no public IP).
  • The effective rules show your rule allow-ssh-from-hub before the default rule DenyAllInBound.

Hints

Toon de hints

Oplossing

Toon de oplossing
  1. Make the group and the VNets.
    RG=rg-lab-net; LOC=westeurope
    az group create -n $RG -l $LOC
    az network vnet create -g $RG -n vnet-hub --address-prefixes 10.10.0.0/16 --subnet-name snet-hub --subnet-prefixes 10.10.1.0/24
    az network vnet create -g $RG -n vnet-spoke --address-prefixes 10.20.0.0/16 --subnet-name snet-spoke --subnet-prefixes 10.20.1.0/24
  2. Peer both ways.
    az network vnet peering create -g $RG -n hub-to-spoke --vnet-name vnet-hub --remote-vnet vnet-spoke --allow-vnet-access --allow-forwarded-traffic
    az network vnet peering create -g $RG -n spoke-to-hub --vnet-name vnet-spoke --remote-vnet vnet-hub --allow-vnet-access --allow-forwarded-traffic
  3. Private DNS with auto-registration.
    az network private-dns zone create -g $RG -n lab.internal
    az network private-dns link vnet create -g $RG -z lab.internal -n link-hub -v vnet-hub --registration-enabled true
    az network private-dns link vnet create -g $RG -z lab.internal -n link-spoke -v vnet-spoke --registration-enabled true
  4. NSG for the spoke subnet.
    az network nsg create -g $RG -n nsg-spoke
    az network nsg rule create -g $RG --nsg-name nsg-spoke -n allow-ssh-from-hub --priority 100 --direction Inbound --access Allow --protocol Tcp --source-address-prefixes 10.10.0.0/16 --destination-port-ranges 22
    az network vnet subnet update -g $RG --vnet-name vnet-spoke -n snet-spoke --network-security-group nsg-spoke
  5. Two small VMs.
    az vm create -g $RG -n vm-hub --image Ubuntu2204 --size Standard_B1s --vnet-name vnet-hub --subnet snet-hub --admin-username azureuser --generate-ssh-keys
    az vm create -g $RG -n vm-spoke --image Ubuntu2204 --size Standard_B1s --vnet-name vnet-spoke --subnet snet-spoke --public-ip-address "" --nsg "" --admin-username azureuser --generate-ssh-keys
  6. Jump through the hub.
    HUBIP=$(az vm show -d -g $RG -n vm-hub --query publicIps -o tsv)
    eval "$(ssh-agent)" && ssh-add ~/.ssh/id_rsa
    ssh -A azureuser@$HUBIP
    ssh azureuser@vm-spoke.lab.internal hostname
    vm-spoke
  7. Read the effective rules (back in Cloud Shell).
    az network nic list-effective-nsg -g $RG -n vm-spokeVMNic --query "value[].effectiveSecurityRules[].{name:name, prio:priority, access:access, src:sourceAddressPrefix}" -o table

    The rule allow-ssh-from-hub (priority 100) matches first; everything else from outside hits DenyAllInBound (65500).

  8. Clean up.
    az group delete -n $RG --yes --no-wait

Mijn notities

Nog geen notities.

Lessen voor dit lab

Commando's in dit lab