S2S(Site-to-Site) VPN Azure
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 을 거쳐가는 과정 확인 가능.