Cloud/Azure

S2S(Site-to-Site) VPN Azure

좌니홍 2023. 4. 10. 10:00

Libreswan(Internet Key Exchange Daemon for Linux) 활용해 Azure S2S VPN 맺는 방법을 알아보고자 합니다.

Azure 측에서 Site-to-Site VPN 을 어떻게 맺는지 쉽게 연습해볼 수 있습니다.

 

 

Architecture 는 아래와 같이 구성되어 있습니다.

 

 

Prerequisite

 

  • VNet
  • 2 개의 VNet 생성, 서로 격리된 네트워크
  • 좌측 VNet 대역 (On-Prem) 192.168.0.0/16
  • 우측 VNet 대역 (Azure) 10.0.0.0/16

 

  • Subnet
  • 우선 VNet VM Subnet 생성
  • 좌측 VM Subnet 대역 192.168.0.0/24
  • 우측 VM Subnet 대역 10.0.0.0/24

 

  • VM
  • 3 개의 VM 생성
  • 좌측 Libreswan(CentOS 7.9) 생성 Windows Server 2019 VM 생성
  • 우측 Windows Server 2019 VM 생성

 

 

LibreSwan 설정 (On-Prem)

  • LibreSwan VM Virtual Network Gateway Site2Site VPN 맺는 시나리오를 가지고 있습니다.
  • LibreSwan VM 통해 Traffic 통과가 되어야하기 때문에 IP Forwarding 설정을 해줘야 합니다.
  • LibreSwan VM -> Networking -> Select Network Interface -> IP configurations -> IP forwarding "Enabled"

 

 

  • SSH 접근해 아래의 명령어를 입력합니다.

 

sudo su -

yum install -y libreswan

 

  • vi 편집기로 /etc/sysctl.conf 파일을 열어 vi 명령어 아래의 내용들을 추가해준 , 저장합니다.

 

vi /etc/sysctl.conf

 

net.ipv4.ip_forward=1

net.ipv4.conf.all.accept_redirects = 0

net.ipv4.conf.all.send_redirects = 0

net.ipv4.conf.default.send_redirects = 0

net.ipv4.conf.eth0.send_redirects = 0

net.ipv4.conf.default.accept_redirects = 0

net.ipv4.conf.eth0.accept_redirects = 0

net.ipv4.conf.all.rp_filter = 0

net.ipv4.conf.default.rp_filter = 0

net.ipv4.conf.eth0.rp_filter = 0

 

 

 

  • 설정 확인 , network 재시작

sysctl -p

systemctl restart network

 

 

 

  • vi 편집기로 아래의 내용 확인

vi /etc/ipsec.conf

 

config setup

include /etc/ipsec.d/*.conf

 

 

 

Virtual Network Gateway 생성 (Azure)

  • LibreSwan VPN 맺을 , 필요한 Virtual Network Gateway 생성합니다.
  • Virtual Network Gateway 위치할 Subnet 우선 생성합니다.
  • Home -> Virtual networks -> AzureVNET -> Subnets -> Select "+ Gateway subnet"

 

 

  • GatewaySubnet 생성

 

  • Virtual Network Gateway 생성
  • Home 에서 virtual network gateways 검색 , 선택

 

  • VPN, Route-based, AzureVNET 선택 생성

 

 

Local Network Gateway 생성 (Azure)

  • LibreSwan VPN 맺을 , 필요한 Local Network Gateway 생성합니다.
  • Local Network Gateway VPN 장비와 IP 매핑하고 On-Prem Private Address Spaces 지정합니다. 
  • Home 에서 Local network gateways 검색 , 선택

 

 

  • IP address(On-Prem VPN 장비 Public IP) Address Space(On-Prem Network 대역) 입력 생성

 

 

Azure 에서 VPN 연결 구성

  • VPN 연결 구성은 Virtual Network Gateway 에서 구성 시작을 합니다.
  • Virtual Network Gateway -> Connections -> Add

 

 

  • 아래와 같이 Connection 설정을 합니다.

Connection Type = Site-to-Site (IPsec)

Virtual network gateway = VNetworkGateway

Local network gateway = LNetworkGateway

PSK = **원하는 키 값 지정

IKE Protocol = IKEv2

 

 

 

LibreSwan 에서 VPN 연결 구성

  • vi 편집기로 아래의 파일 생성

 

(1) vi /etc/ipsec.d/azure.conf

 

conn azureTunnel

    authby=secret

    auto=start

    ike=aes256-sha1;dh2,3des-sha1;dh2,aes256-sha256;dh2

    ikelifetime=3600s

    salifetime=3600s

    ikev2=yes

    phase2alg=aes_gcm256-null,aes256-sha1,3des-sha1,aes256-sha256

    left=192.168.0.4                  **상황에 맞게 수정 [Private IP of Libreswan]

    leftid=20.83.178.192            **상황에 맞게 수정 [Public IP of Libreswan]

    leftsubnets=192.168.0.0/24    **상황에 맞게 수정 [Address Spaces of On-Prem]

    right=20.115.116.197           **상황에 맞게 수정 [Public IP of Virtual Network Gateway]

    rightsubnets=10.0.0.0/16      **상황에 맞게 수정 [Address Spaces of Azure]

    type=tunnel

 

 

 

(2) vi /etc/ipsec.d/azure.secrets

 

20.83.178.192 20.115.116.197 : PSK "wlstka1234"

[LibreSwan Public IP] [Virtual Network Gateway Public IP] : PSK "[ Pre Shared Key ]"

 

 

  • IPsec service 기동 

systemctl start ipsec

systemctl enable ipsec

 

  • Check IPsec 상태

Libreswan 에서 진행.

systemctl status ipsec

journalctl -e -u ipsec

 

 

Azure VNetworkGateway 상태를 확인합니다.

 

 

 

 

SwanVNET SwanSubnet UDR(User Defined Route) 구성

  • SwanVNET 측의 SwanSubnet 있는 NIC 들은 10.0.0.0/24 으로 패킷을 보낼 어디로 보내야 모르는 상황입니다.
  • 따라서, 10.0.0.0/24 보내려면 LibreSwan(192.168.0.4) 거쳐서 가라는 UDR 추가해 줍니다.
  • Routing Table 먼저 생성하고, Table Subnet 연결시켜주는 작업을 거칩니다.

 

  • Routing Table 생성
  • Home 에서 Routing tables 검색 , 선택 -> Create

 

 

 

 

  • 완성된 Routing Table -> Routes -> Add

 

 

 

 

  • SwanVNET -> Subnets -> SwanSubnet 방금 생성한 "LibreSwanRT" Route table 추가합니다.

 

 

 

 

  • 반면, AzureVNET 측에서는 따로 UDR 구성해주지 않아도 됩니다.
  • AzureVM NIC -> Effective routes 탭에 보면,
  • On-Prem 측으로 가는(192.168.0.0/24) 요청이 들어오면 Virtual network gateway(20.115.116.197) 보내라는 Routing 이미 잡혀 있습니다.

 

 

 

Windows Server 세팅 

  • ICMP 프로토콜(Ping) 활용하여 On-Prem Windows Server Azure Windows Server 통신이 원활하게 이루어지는 확인하기 , ICMP 열어주어야 합니다. NSG Windows 서버 ICMP OPEN
  • VM NSG ICMP 아래와 같이 열어줍니다.

 

 

  • Windows Server 따로 관리자 권한으로 Powershell 열어 아래의 명령어까지 입력해줘야 정상적인 ICMP 통신을 있습니다.

 

netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol="icmpv4:8,any" dir=in action=allow

 

 

 

 

 

VM 에서 통신 테스트

  • On-Prem VM
  • On-Prem VM(192.168.0.5) 에서 Azure VM(10.0.0.4) 으로 Ping Test
  • tracert 활용해 10.0.0.4 패킷을 보낼 , LibreSwan 거쳐가는 과정 확인 가능.

 

  • Azure VM
  • Azure VM(10.0.0.4) 에서 On-Prem VM(192.168.0.5) 으로 Ping Test
  • tracert 활용해 192.168.0.5 패킷을 보낼 , LibreSwan 거쳐가는 과정 확인 가능.