Site-to-Site VPN to Microsoft Azure с BGP

Route-Based Site-to-Site VPN между VyOS и Microsoft Azure Virtual Network Gateway с динамической маршрутизацией через BGP over IKEv2/IPsec.

Описание сценария

Use Case

Подключение on-premises сети (или VyOS в другом облаке) к Microsoft Azure через защищенный IPsec туннель с автоматическим обменом маршрутами через BGP.

Применимость:

  • Hybrid cloud deployments (Yandex Cloud ↔ Azure, VK Cloud ↔ Azure)
  • On-premises datacenter ↔ Azure
  • Multi-cloud architectures
  • Disaster recovery scenarios
  • Cloud migration (phased approach)

Преимущества Route-Based VPN с BGP

  • Динамическая маршрутизация: Автоматический обмен маршрутами через BGP
  • Масштабируемость: Легко добавлять новые подсети без изменения IPsec config
  • Failover: Автоматическое переключение при добавлении redundant tunnels
  • Гибкость: Поддержка сложных топологий (Hub-and-Spoke, mesh)

Топология сети

┌─────────────────────────────────────────────────────────────────┐
│                     Internet / Public WAN                        │
└──────────────────────────┬──────────────────────────────────────┘
                           │
              ┌────────────┴────────────┐
              │                         │
      ┌───────▼────────┐        ┌──────▼────────────┐
      │   VyOS Router  │        │  Azure VNet GW    │
      │                │        │                   │
      │ Public IP:     │        │ Public IP:        │
      │ 198.51.100.3   │        │ 203.0.113.2       │
      │                │        │                   │
      │ VTI: 10.10.1.5 │◄──────►│ BGP: 10.0.0.4     │
      │ AS 64499       │  IPsec │ AS 65540          │
      └───────┬────────┘  BGP   └──────┬────────────┘
              │                        │
      ┌───────▼────────┐        ┌──────▼────────────┐
      │  On-Premises   │        │   Azure VNet      │
      │   Network      │        │                   │
      │ 10.10.0.0/16   │        │  10.0.0.0/16      │
      │                │        │                   │
      │ LAN: eth1      │        │  Subnet:          │
      │ 10.10.0.5      │        │  10.0.0.0/24      │
      └────────────────┘        └───────────────────┘

Параметры конфигурации

КомпонентVyOS (On-Premises)Azure
Public IP198.51.100.3203.0.113.2
Private Network10.10.0.0/1610.0.0.0/16
VTI/BGP IP10.10.1.5/3210.0.0.4/32
BGP ASN6449965540
IKE VersionIKEv2IKEv2
Pre-Shared Keych00s3-4-s3cur3-pskch00s3-4-s3cur3-psk
IPsec ModeRoute-Based (VTI)Route-Based

Конфигурация Azure

1. Создание Virtual Network Gateway

Через Azure Portal

  1. Перейдите в Virtual Network GatewaysCreate

  2. Basics:

    Resource Group: rg-azure-vpn
    Name: vng-vyos-site
    Region: East US
    Gateway type: VPN
    VPN type: Route-based
    SKU: VpnGw1 (или выше для production)
    Virtual network: vnet-azure-main (10.0.0.0/16)
  3. Gateway subnet (если не создан):

    Subnet name: GatewaySubnet (обязательное имя)
    Address range: 10.0.255.0/27
  4. Public IP:

    Public IP address name: pip-vng-vyos
    Public IP type: Basic или Standard
    Assignment: Dynamic или Static
  5. Wait for deployment (~30-45 minutes)

Через Azure CLI

# Создать Resource Group
az group create --name rg-azure-vpn --location eastus

# Создать Virtual Network
az network vnet create \
  --resource-group rg-azure-vpn \
  --name vnet-azure-main \
  --address-prefix 10.0.0.0/16 \
  --subnet-name subnet-main \
  --subnet-prefix 10.0.0.0/24

# Создать Gateway Subnet
az network vnet subnet create \
  --resource-group rg-azure-vpn \
  --vnet-name vnet-azure-main \
  --name GatewaySubnet \
  --address-prefix 10.0.255.0/27

# Создать Public IP
az network public-ip create \
  --resource-group rg-azure-vpn \
  --name pip-vng-vyos \
  --allocation-method Static \
  --sku Standard

# Создать Virtual Network Gateway
az network vnet-gateway create \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site \
  --public-ip-address pip-vng-vyos \
  --vnet vnet-azure-main \
  --gateway-type Vpn \
  --vpn-type RouteBased \
  --sku VpnGw1 \
  --bgp-asn 65540 \
  --no-wait

# Проверить статус создания
az network vnet-gateway show \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site \
  --query "provisioningState"

2. Получить Azure BGP IP и Public IP

# Получить Public IP
az network public-ip show \
  --resource-group rg-azure-vpn \
  --name pip-vng-vyos \
  --query "ipAddress" -o tsv
# Output: 203.0.113.2

# Получить BGP Peer IP
az network vnet-gateway show \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site \
  --query "bgpSettings.bgpPeeringAddress" -o tsv
# Output: 10.0.0.4

3. Создать Local Network Gateway (представляет VyOS)

Azure Portal

  1. Local Network GatewaysCreate

  2. Configuration:

    Resource Group: rg-azure-vpn
    Name: lng-vyos-onprem
    Endpoint: IP address
    IP address: 198.51.100.3 (VyOS public IP)
    Address Space: 10.10.0.0/16 (on-premises network)
  3. BGP Settings:

    Configure BGP settings: Yes
    Autonomous system number (ASN): 64499
    BGP peer IP address: 10.10.1.5

Azure CLI

az network local-gateway create \
  --resource-group rg-azure-vpn \
  --name lng-vyos-onprem \
  --gateway-ip-address 198.51.100.3 \
  --address-prefixes 10.10.0.0/16 \
  --bgp-asn 64499 \
  --bgp-peering-address 10.10.1.5

4. Создать VPN Connection

Azure Portal

  1. Virtual Network GatewayConnectionsAdd

  2. Configuration:

    Name: conn-vyos-azure
    Connection type: Site-to-site (IPsec)
    Virtual network gateway: vng-vyos-site
    Local network gateway: lng-vyos-onprem
    Shared key (PSK): ch00s3-4-s3cur3-psk
  3. BGP:

    Enable BGP: Yes
  4. IKE Protocol:

    IKE Protocol: IKEv2

Azure CLI

az network vpn-connection create \
  --resource-group rg-azure-vpn \
  --name conn-vyos-azure \
  --vnet-gateway1 vng-vyos-site \
  --local-gateway2 lng-vyos-onprem \
  --shared-key "ch00s3-4-s3cur3-psk" \
  --enable-bgp

Конфигурация VyOS

Полная рабочая конфигурация

configure

# Системные настройки
set system host-name vyos-azure-vpn
set system time-zone Europe/Moscow

# WAN интерфейс (должен иметь public IP или NAT)
set interfaces ethernet eth0 address '198.51.100.3/24'
set interfaces ethernet eth0 description 'WAN'

# LAN интерфейс (on-premises network)
set interfaces ethernet eth1 address '10.10.0.5/16'
set interfaces ethernet eth1 description 'LAN'

# ===== IPsec Configuration =====

# IKE Group (Phase 1)
set vpn ipsec ike-group AZURE lifetime '28800'
set vpn ipsec ike-group AZURE proposal 1 encryption 'aes256'
set vpn ipsec ike-group AZURE proposal 1 hash 'sha256'
set vpn ipsec ike-group AZURE proposal 1 dh-group '14'
set vpn ipsec ike-group AZURE key-exchange 'ikev2'
set vpn ipsec ike-group AZURE dead-peer-detection action 'restart'
set vpn ipsec ike-group AZURE dead-peer-detection interval '30'
set vpn ipsec ike-group AZURE dead-peer-detection timeout '120'

# ESP Group (Phase 2)
set vpn ipsec esp-group AZURE lifetime '3600'
set vpn ipsec esp-group AZURE mode 'tunnel'
set vpn ipsec esp-group AZURE proposal 1 encryption 'aes256'
set vpn ipsec esp-group AZURE proposal 1 hash 'sha256'
set vpn ipsec esp-group AZURE pfs 'dh-group14'

# VTI Interface (Virtual Tunnel Interface)
set interfaces vti vti1 address '10.10.1.5/32'
set interfaces vti vti1 description 'Azure VPN Tunnel'
set interfaces vti vti1 ip adjust-mss '1350'
set interfaces vti vti1 ip disable-forwarding

# IPsec Authentication
set vpn ipsec authentication psk azure id '198.51.100.3'
set vpn ipsec authentication psk azure id '203.0.113.2'
set vpn ipsec authentication psk azure secret 'ch00s3-4-s3cur3-psk'

# IPsec Site-to-Site Peer
set vpn ipsec site-to-site peer 203.0.113.2 description 'Azure VNet Gateway'
set vpn ipsec site-to-site peer 203.0.113.2 authentication mode 'pre-shared-secret'
set vpn ipsec site-to-site peer 203.0.113.2 authentication pre-shared-secret 'ch00s3-4-s3cur3-psk'
set vpn ipsec site-to-site peer 203.0.113.2 connection-type 'respond'
set vpn ipsec site-to-site peer 203.0.113.2 ike-group 'AZURE'
set vpn ipsec site-to-site peer 203.0.113.2 ikev2-reauth 'yes'
set vpn ipsec site-to-site peer 203.0.113.2 local-address '198.51.100.3'
set vpn ipsec site-to-site peer 203.0.113.2 vti bind 'vti1'
set vpn ipsec site-to-site peer 203.0.113.2 vti esp-group 'AZURE'

# ===== BGP Configuration =====

# BGP Router
set protocols bgp system-as '64499'
set protocols bgp parameters router-id '10.10.0.5'
set protocols bgp parameters log-neighbor-changes

# BGP Neighbor (Azure VNet Gateway)
set protocols bgp neighbor 10.0.0.4 description 'Azure VNet Gateway BGP'
set protocols bgp neighbor 10.0.0.4 remote-as '65540'
set protocols bgp neighbor 10.0.0.4 address-family ipv4-unicast
set protocols bgp neighbor 10.0.0.4 address-family ipv4-unicast soft-reconfiguration inbound
set protocols bgp neighbor 10.0.0.4 ebgp-multihop '2'
set protocols bgp neighbor 10.0.0.4 update-source 'vti1'
set protocols bgp neighbor 10.0.0.4 timers holdtime '30'
set protocols bgp neighbor 10.0.0.4 timers keepalive '10'

# Анонсировать локальную сеть в Azure
set protocols bgp address-family ipv4-unicast network '10.10.0.0/16'

# Static route для Azure BGP peer (через VTI)
set protocols static route 10.0.0.4/32 interface vti1

# ===== NAT Configuration (если требуется) =====

# Exclude VPN traffic from NAT
set nat source rule 10 outbound-interface name 'eth0'
set nat source rule 10 source address '10.10.0.0/16'
set nat source rule 10 destination address '10.0.0.0/16'
set nat source rule 10 exclude

# NAT для остального интернет трафика
set nat source rule 100 outbound-interface name 'eth0'
set nat source rule 100 source address '10.10.0.0/16'
set nat source rule 100 translation address 'masquerade'

# ===== Firewall (опционально, но рекомендуется) =====

# Allow IPsec на WAN
set firewall name WAN_LOCAL default-action 'drop'
set firewall name WAN_LOCAL rule 10 action 'accept'
set firewall name WAN_LOCAL rule 10 state established
set firewall name WAN_LOCAL rule 10 state related
set firewall name WAN_LOCAL rule 20 action 'accept'
set firewall name WAN_LOCAL rule 20 protocol 'udp'
set firewall name WAN_LOCAL rule 20 destination port '500'
set firewall name WAN_LOCAL rule 20 description 'IKE'
set firewall name WAN_LOCAL rule 21 action 'accept'
set firewall name WAN_LOCAL rule 21 protocol 'udp'
set firewall name WAN_LOCAL rule 21 destination port '4500'
set firewall name WAN_LOCAL rule 21 description 'NAT-T'
set firewall name WAN_LOCAL rule 22 action 'accept'
set firewall name WAN_LOCAL rule 22 protocol 'esp'
set firewall name WAN_LOCAL rule 22 description 'ESP'
set firewall name WAN_LOCAL rule 30 action 'accept'
set firewall name WAN_LOCAL rule 30 protocol 'icmp'

set interfaces ethernet eth0 firewall local name 'WAN_LOCAL'

commit
save

Проверка конфигурации

1. Проверка IPsec туннеля

# Проверить статус IPsec
show vpn ipsec sa

# Должен быть output:
# Connection              State    Uptime    Bytes In/Out
# peer-203.0.113.2        up       00h05m22s    0.0 B/0.0 B
#   vti1                  up       00h05m22s    0.0 B/0.0 B

# Детальная информация
show vpn ipsec sa detail

# Проверить IKE SA
show vpn ike sa

2. Проверка BGP

# Проверить BGP neighbors
show bgp summary

# Output должен показывать:
# Neighbor        V    AS    MsgRcvd    MsgSent    Up/Down    State
# 10.0.0.4        4    65540    45         47      00:21:32   Established

# Проверить полученные маршруты от Azure
show bgp neighbors 10.0.0.4 received-routes

# Проверить анонсированные маршруты в Azure
show bgp neighbors 10.0.0.4 advertised-routes

# Проверить routing table
show ip route

# Должны быть маршруты через vti1:
# B>* 10.0.0.0/16 [20/0] via 10.0.0.4, vti1, weight 1, 00:20:15

3. Проверка connectivity

# Ping Azure BGP peer через VTI
ping 10.0.0.4 source-address 10.10.1.5

# Ping Azure VM (например, 10.0.0.10)
ping 10.0.0.10 source-address 10.10.0.5

# Traceroute
traceroute 10.0.0.10

4. Проверка на Azure стороне

# Azure CLI - проверить connection status
az network vpn-connection show \
  --resource-group rg-azure-vpn \
  --name conn-vyos-azure \
  --query "connectionStatus"
# Output: Connected

# Проверить BGP peers
az network vnet-gateway list-bgp-peer-status \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site \
  --query "value[].{Peer:neighbor,AS:asn,State:state,RoutesReceived:routesReceived}"

# Проверить learned routes
az network vnet-gateway list-learned-routes \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site \
  --query "value[].{Network:network,NextHop:nextHop,Origin:origin}" -o table

Интеграция с облачными платформами

Yandex Cloud как on-premises сторона

Topology

Azure VNet (10.0.0.0/16)
        │
        │ IPsec + BGP
        │
VyOS в Yandex Cloud (10.128.0.0/24)
        │
Yandex Cloud VPC Networks

Особенности

  1. VyOS VM в Yandex Cloud:

    # Public IP от Yandex Cloud
    # Elastic IP или NAT Gateway
    
    # WAN интерфейс получает адрес из Yandex Cloud subnet
    set interfaces ethernet eth0 address '10.128.0.10/24'
    set interfaces ethernet eth0 description 'Yandex Cloud WAN'
    
    # Static route для default gateway
    set protocols static route 0.0.0.0/0 next-hop 10.128.0.1
  2. Yandex Cloud routing:

    # Добавить static route в Yandex Cloud routing table
    # Destination: 10.0.0.0/16 (Azure)
    # Next hop: 10.128.0.10 (VyOS internal IP)
    
    # Через yc CLI
    yc vpc route-table create \
      --name azure-routes \
      --network-name yc-network \
      --route destination=10.0.0.0/16,next-hop=10.128.0.10
  3. Security Groups:

    # Разрешить IPsec на VyOS VM
    # Inbound rules:
    # - UDP 500 (IKE)
    # - UDP 4500 (NAT-T)
    # - Protocol 50 (ESP)

Yandex Cloud CLI команды

# Создать VM для VyOS
yc compute instance create \
  --name vyos-azure-gw \
  --zone ru-central1-a \
  --network-interface subnet-name=default-ru-central1-a,nat-ip-version=ipv4 \
  --create-boot-disk image-folder-id=standard-images,image-family=vyos \
  --ssh-key ~/.ssh/id_rsa.pub

# Получить public IP
yc compute instance get vyos-azure-gw --format json | jq -r '.network_interfaces[0].primary_v4_address.one_to_one_nat.address'

# Создать static route для Azure network
yc vpc route-table create \
  --name route-to-azure \
  --network-name default \
  --route destination=10.0.0.0/16,next-hop=10.128.0.10

# Применить route table к subnet
yc vpc subnet update default-ru-central1-a \
  --route-table-name route-to-azure

VK Cloud как on-premises сторона

Topology

Azure VNet (10.0.0.0/16)
        │
        │ IPsec + BGP
        │
VyOS в VK Cloud (10.0.10.0/24)
        │
VK Cloud Private Networks

Особенности

  1. VyOS VM в VK Cloud:

    # Floating IP от VK Cloud
    
    # WAN интерфейс
    set interfaces ethernet eth0 address '10.0.10.10/24'
    set interfaces ethernet eth0 description 'VK Cloud WAN'
    
    # Default route
    set protocols static route 0.0.0.0/0 next-hop 10.0.10.1
  2. VK Cloud routing:

    • Добавить static route через VK Cloud portal
    • Destination: 10.0.0.0/16
    • Next hop: 10.0.10.10 (VyOS IP)
  3. Security Groups:

    • Разрешить UDP 500, 4500 и ESP protocol

Troubleshooting

Проблема: IPsec туннель не поднимается

Симптомы:

show vpn ipsec sa
# Connection state: down

Решение:

  1. Проверить network connectivity:
ping 203.0.113.2
# Должен отвечать Azure gateway
  1. Проверить firewall rules:
# Убедиться что разрешены UDP 500, 4500, ESP
show firewall name WAN_LOCAL

# Проверить Azure NSG (Network Security Group)
az network nsg rule list \
  --resource-group rg-azure-vpn \
  --nsg-name nsg-vnet-main \
  --query "[].{Name:name,Port:destinationPortRange,Protocol:protocol}" -o table
  1. Проверить Pre-Shared Key:
# VyOS
show vpn ipsec authentication psk

# Azure - через portal или CLI
az network vpn-connection shared-key show \
  --resource-group rg-azure-vpn \
  --connection-name conn-vyos-azure
  1. Проверить logs:
# VyOS
show log vpn ipsec

# Включить debug (временно)
set vpn ipsec logging log-modes ike
set vpn ipsec logging log-modes esp
set vpn ipsec logging log-level 2
commit

# После troubleshooting отключить
delete vpn ipsec logging
commit

Проблема: BGP session не устанавливается

Симптомы:

show bgp summary
# Neighbor state: Idle или Active

Решение:

  1. Проверить IPsec туннель (должен быть UP):
show vpn ipsec sa
  1. Проверить static route для BGP peer:
show ip route 10.0.0.4
# Должен быть route через vti1
  1. Проверить BGP configuration:
show configuration commands | grep bgp

# Убедиться в правильности:
# - remote-as (Azure = 65540)
# - neighbor IP (10.0.0.4)
# - update-source vti1
# - ebgp-multihop 2
  1. Ping Azure BGP peer:
ping 10.0.0.4 interface vti1
  1. Проверить BGP на Azure:
az network vnet-gateway list-bgp-peer-status \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site

Проблема: BGP established, но нет маршрутов

Симптомы:

show bgp neighbors 10.0.0.4 received-routes
# Empty или мало маршрутов

Решение:

  1. Проверить advertised routes:
show bgp neighbors 10.0.0.4 advertised-routes
  1. Проверить route-map/prefix-list (если настроены):
show policy

# Убедиться что нет фильтров блокирующих routes
  1. Проверить Azure routes:
az network vnet-gateway list-learned-routes \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site \
  --query "value[].{Network:network,NextHop:nextHop,Origin:origin}" -o table
  1. Проверить BGP network statements:
show configuration commands | grep "protocols bgp.*network"

# Убедиться что анонсируются нужные сети

Проблема: Высокая latency или packet loss

Решение:

  1. Проверить MTU:
# VyOS - должен быть 1350 или меньше на VTI
show interfaces vti vti1

# Если нужно изменить
set interfaces vti vti1 mtu 1350
set interfaces vti vti1 ip adjust-mss 1310
commit
  1. Проверить throughput:
# iperf3 test через tunnel
# На Azure VM
iperf3 -s

# На VyOS LAN client
iperf3 -c 10.0.0.10 -t 60
  1. Проверить Azure Gateway SKU:
az network vnet-gateway show \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site \
  --query "sku.name"

# Upgrade to higher SKU if needed (VpnGw2, VpnGw3)
az network vnet-gateway update \
  --resource-group rg-azure-vpn \
  --name vng-vyos-site \
  --sku VpnGw2

Best Practices

Security

  1. Strong Pre-Shared Key:

    # Generate strong PSK
    openssl rand -base64 32
  2. Certificate authentication (alternative to PSK):

    # Более безопасно, но сложнее в настройке
    # Azure поддерживает certificate-based auth
  3. Firewall rules:

    # Минимальный доступ через VPN
    set firewall name VPN_IN default-action 'drop'
    set firewall name VPN_IN rule 10 action 'accept'
    set firewall name VPN_IN rule 10 state established
    set firewall name VPN_IN rule 10 state related
    # Добавить только необходимые правила

Performance

  1. MTU optimization:

    # VTI MTU должен учитывать IPsec overhead
    # Ethernet MTU (1500) - IPsec overhead (~80) = 1420
    # Рекомендуется: 1350-1400
    set interfaces vti vti1 mtu 1400
    set interfaces vti vti1 ip adjust-mss 1360
  2. BGP timers:

    # Faster failover detection
    set protocols bgp neighbor 10.0.0.4 timers holdtime '30'
    set protocols bgp neighbor 10.0.0.4 timers keepalive '10'
  3. Azure Gateway SKU:

    • VpnGw1: До 650 Mbps, 30 tunnels
    • VpnGw2: До 1 Gbps, 30 tunnels
    • VpnGw3: До 1.25 Gbps, 30 tunnels

Monitoring

  1. VyOS monitoring:

    # Проверять статус регулярно
    show vpn ipsec sa
    show bgp summary
    
    # Logs
    show log vpn
    
    # Traffic stats
    show interfaces vti vti1
  2. Azure monitoring:

    # Azure Monitor metrics
    # - VPN Gateway bandwidth
    # - Tunnel ingress/egress bytes
    # - BGP peer status
    
    # Alerts на disconnect
    az monitor metrics alert create \
      --name vpn-disconnect-alert \
      --resource-group rg-azure-vpn \
      --scopes $(az network vpn-connection show -g rg-azure-vpn -n conn-vyos-azure --query id -o tsv) \
      --condition "avg tunnel_connectivity_status < 1" \
      --window-size 5m \
      --evaluation-frequency 1m
  3. Automated testing:

    # Ping test script
    #!/bin/bash
    while true; do
      ping -c 1 10.0.0.10 > /dev/null
      if [ $? -ne 0 ]; then
        echo "$(date): VPN connectivity lost!" | mail -s "VPN Alert" admin@example.com
      fi
      sleep 60
    done

High Availability

Для production рекомендуется использовать redundant setup:

Дополнительные ресурсы


Tested on: VyOS 1.4 (Sagitta LTS), VyOS 1.5 (Circinus), Azure VPN Gateway (VpnGw1, VpnGw2) Last updated: 2025-10-14