NAT 생성 및 public subnet(test-2SVPN-VPC-B-Public-2a-1)에 attach
3.2. Instance 구성
3.2.1. VPC-A Instance
Instance Name : test-2SVPN-VPC-A-Public-2a-1
Instance Type : Amazon Linux2, t2.micro
Subnet : test-2SVPN-VPC-A-Public-2a-subnet
Security Group Name : test-2SVPN-VPC-A-Public-sg
Open Port : SSH, tcp 50, tcp 51, udp 500, udp 4500, tcp 4500, icmp를 test-2SVPN-VPC-B-Public-sg의 보안그룹에 대해 모두 열어준다. (SSH의 경우, 내 현재 ip도 추가한다.)
3.2.2. VPC-B Instance
Public Instance
Instance Name : test-2SVPN-VPC-B-Public-2a-1
Instance Type : Amazon Linux, t2.micro
Subnet : test-2SVPN-VPC-B-Public-2a-subnet
Security Group Name : test-2SVPN-VPC-B-Public-sg
Open Port : SSH, tcp 50, tcp 51, udp 500, udp 4500, tcp 4500, ICMP를 “test-2SVPN-VPC-A-Public-2a-1”인스턴스의 private ip와 “test-2SVPN-VPC-B-Private-2a-1“인스턴스의 private ip에 대해 열어둔다. (SSH의 경우, 내 현재 ip도 추가한다.)
Private Instance
Instance Name : test-2SVPN-VPC-B-Private-2a-1
Instance Type : Amazon Linux2, t2.micro
Subnet : test-2SVPN-VPC-B-Private-2a-1
Security Group Name : test-2SVPN-VPC-B-Private-sg
Open Port : SSH, tcp 50, tcp 51, udp 500, udp 4500, tcp 4500, ICMP를 “test-2SVPN-VPC-A-Public-2a-1“인스턴스의 private ip에 대해 열어둔다, “test-2SVPN-VPC-B-Public-sg”에 대해 SSH를 열어둔다.
3.3. VPN 설정
3.3.1. Customer Gateway 생성
다음과 같이 Public Instance IP와 NAT Gateway IP에 대해 Customer Gateway를 생성한다.
이름 : test-2SVPN-VPC-B-CGW-Public, test-2SVPN-VPC-B-CGW-NAT
라우팅 : 정적
IP 주소 : 각각 할당받은 public ip 또는 eip
Certificate ARN : Default
3.3.2. Virtual Private Gateway생성 및 라우팅 전파
다음과 같이 Virtual Private Gateway를 생성한다.
이름 : test-2SVPN-VPC-A-vgw
ASN : Amazon 기본 ASN
다음과 같이 생성한 Virtual Private Gateway를 VPC-A에 Attach한다.
Attach 적용 후, Routing Table에 서브넷에 속한 인스턴스에 대해 Routing Propagation을 적용한다.
3.3.3. Site to Site VPN Connection 생성 및 VPN 설정 다운로드
VPN Connection이 완전히 생성될때까지 5분정도 소요됩니다.
사용가능한 상태가 되기 전까지 3.4를 수행하는 것을 권장합니다.
다음과 같이 2개의 Customer Gateway에 대해 VPN Connection을 생성한다.
이름 : test-2SVPN-public-to-public, test-2SVPN-public-to-private
Target Gateway Type : Virtual Private Gateway
가상 프라이빗 게이트웨이 : 생성한 게이트웨이 선택
고객 게이트웨이 : 기존
Customer Gateway ID : test-2SVPN-CG, test-2SVPN-NAT
라우팅 옵션 : 정적
정적 IP 접두사 : Customer측 VPC CIDR(이 Hands on LAB을 따라 하였으면 20.0.0.0/16 입력)
작성 후 , sudo service network restart를 이용하여 sysctl.conf를 적용시킨다.
3.4.3. OpenSwan 설치 및 환경 변수 세팅
환경 변수는 [3.4.1. 구성 다운로드 섹션]의 다운로드 받은 구성 정보가 필요합니다.
진행하기 전 필히 구성 정보를 다운로드 받아주세요.
다음과 같이 Openswan을 설치한다.
OpenSwan을 설치하고 난 후, 다음과 같이 /etc/ipsec.conf 파일과 /etc/ipsec.d 디렉토리가 생성되어 있을 것이다.
다운로드 받은 VPN 구성파일을 열어보면 2개의 터널에 대해 정보가 명시가 되어있다.
IPSec Tunnel #1
================================================================================
#1: Internet Key Exchange Configuration
Configure the IKE SA as follows:
Please note, these sample configurations are for the minimum requirement of AES128, SHA1, and DH Group 2.
Category "VPN" connections in the GovCloud region have a minimum requirement of AES128, SHA2, and DH Group 14.
You will need to modify these sample configuration files to take advantage of AES256, SHA256, or other DH groups like 2, 14-18, 22, 23, and 24.
Higher parameters are only available for VPNs of category "VPN," and not for "VPN-Classic".
The address of the external interface for your customer gateway must be a static address.
Your customer gateway may reside behind a device performing network address translation (NAT).
To ensure that NAT traversal (NAT-T) can function, you must adjust your firewall !rules to unblock UDP port 4500. If not behind NAT, we recommend disabling NAT-T.
- IKE version : IKEv1
- Authentication Method : Pre-Shared Key
- Pre-Shared Key : <YOUR PSK>
- Authentication Algorithm : sha1
- Encryption Algorithm : aes-128-cbc
- Lifetime : 28800 seconds
- Phase 1 Negotiation Mode : main
- Diffie-Hellman : Group 2
-- 중략 --
The Customer Gateway inside IP address should be configured on your tunnel
interface.
Outside IP Addresses:
- Customer Gateway : 52.79.125.78
- Virtual Private Gateway : 13.125.105.72
Inside IP Addresses
- Customer Gateway : 169.254.49.50/30
- Virtual Private Gateway : 169.254.49.49/30
-- 중략 --
IPSec Tunnel #2
================================================================================
#1: Internet Key Exchange Configuration
Configure the IKE SA as follows:
Please note, these sample configurations are for the minimum requirement of AES128, SHA1, and DH Group 2.
Category "VPN" connections in the GovCloud region have a minimum requirement of AES128, SHA2, and DH Group 14.
You will need to modify these sample configuration files to take advantage of AES256, SHA256, or other DH groups like 2, 14-18, 22, 23, and 24.
Higher parameters are only available for VPNs of category "VPN," and not for "VPN-Classic".
The address of the external interface for your customer gateway must be a static address.
Your customer gateway may reside behind a device performing network address translation (NAT).
To ensure that NAT traversal (NAT-T) can function, you must adjust your firewall !rules to unblock UDP port 4500. If not behind NAT, we recommend disabling NAT-T.
- IKE version : IKEv1
- Authentication Method : Pre-Shared Key
- Pre-Shared Key : <YOUR PSK>
- Authentication Algorithm : sha1
- Encryption Algorithm : aes-128-cbc
- Lifetime : 28800 seconds
- Phase 1 Negotiation Mode : main
- Diffie-Hellman : Group 2
-- 중략 --
The Customer Gateway inside IP address should be configured on your tunnel
interface.
Outside IP Addresses:
- Customer Gateway : 52.79.125.78
- Virtual Private Gateway : 52.78.178.100
Inside IP Addresses
- Customer Gateway : 169.254.101.166/30
- Virtual Private Gateway : 169.254.101.165/30
위 텍스트에서 필요한 부분은 각 터널에 대한 Pre-Shared Key와 각 Tunnel의 Outside IP Address이다. 이 정보를 ipsec.d/ 디렉토리 안에 명시 할 것이다.
VPN Connection에 대해 기본적으로 2개의 터널이 제공됩니다. 단일 터널로 실행했을 때는 문제가 없었으나, 2개의 터널을 모두 사용할 때 터널 status는 모두 on임에도 불구하고 ping이 제대로 되지 않던 문제가 있었다.
해당 문제에 대한 로그는 다음과 같다.
"2SVPN2" #4: cannot install eroute -- it is in use for "2SVPN1" #3
"2SVPN1" #4: cannot install eroute -- it is in use for "2SVPN2" #3 "2SVPN1" #4: deleting state (STATE_QUICK_I1) and NOT sending notification "2SVPN1" #4: ERROR: netlink response for Del SAesp.b5b1185b@15.164.153.107included errno 3: No such process "2SVPN1" #1: next payload type of ISAKMP Hash Payload has an unknown value: 31 (0x1f) "2SVPN1" #1: malformed payload in packet
이미 먼저 연결이 성립된 customer gateway가 사용중이었고, 사용중이므로, 다른 연결 요청에 대해서는 응답을 하지 않게 된다. 키가 다르면 응답을 하지 않기 때문에 서버는 인증 요청이 잘못되어 에러가 난것으로 최종 간주하였다.
이를 해결하기 위해 구글링 한 결과, overlapip라는 다중 터널 구성시, 같은 customer ip를 사용할 수 있도록 하는 설정이 있었다. 이를 설정해주니 2중 터널 구성이 정상적으로 작동하였다.
_sudo service network restart, sudo service ipsec restart_를 터미널에 입력하여 ipsec서비스를 실행시킨다.
실행 시키고 난뒤, sudo service ipsec status를 입력하여 다음과 같은 메시지가 출력되면 제대로 VPN Tunnel이 설정 된 것이다.
"2SVPN2" #2: STATE_MAIN_I2: sent MI2, expecting MR2
"2SVPN2" #2: STATE_MAIN_I3: sent MI3, expecting MR3
"2SVPN1" #1: Peer ID is ID_IPV4_ADDR: '15.164.153.107'
"2SVPN1" #1: STATE_MAIN_I4: ISAKMP SA established {auth=PRESHARED_KEY cipher=aes_128 integ=sha group=MODP1024}
"2SVPN1" #3: initiating Quick Mode PSK+ENCRYPT+TUNNEL+PFS+UP+OVERLAPIP+IKEV1_ALLOW+IKEV2_ALLOW+SAREF_T...MODP1024}
"2SVPN2" #2: Peer ID is ID_IPV4_ADDR: '15.164.186.29'
"2SVPN2" #2: STATE_MAIN_I4: ISAKMP SA established {auth=PRESHARED_KEY cipher=aes_128 integ=sha group=MODP1024}
"2SVPN2" #4: initiating Quick Mode PSK+ENCRYPT+TUNNEL+PFS+UP+OVERLAPIP+IKEV1_ALLOW+IKEV2_ALLOW+SAREF_T...MODP1024}
"2SVPN1" #3: STATE_QUICK_I2: sent QI2, IPsec SA established tunnel mode {ESP/NAT=>0x5f303410 <0x8d8726...D=active}
"2SVPN2" #4: STATE_QUICK_I2: sent QI2, IPsec SA established tunnel mode {ESP/NAT=>0x03158d89 <0x8f026e...D=active}
3.5. Ping, SSH 테스트
Virtual Private Gateway는 단일 연결만 지원하기 때문에 Virtual Private Gateway를 통해 2쌍 이상의 연결을 할 수 없습니다. 하나의 연결이 성립된 상태에서 다른 VPN Connection을 요청할 경우, 기존 VPN Connection이 disconnect됩니다. 동시다발적으로 연결을 원할 경우, Transit Gateway를 사용해야한다.
필자는 VPC-A public === VPC-B public VPN연결이 성립된 상태에서
VPC-A public === VPC-B private 연결을 추가 요청하니 전자의 연결이 끊기고 후자의 연결이 성립되었다.
먼저 환경 변수 세팅(ip address, key 등등)이 제대로 되어있는지 확인해주시면 감사드려요!
예전에 환경 변수를 잘못 세팅하니 서로 패킷을 주고받지 못하여, 패킷트레이서를 보면서 저 문제를 해결하였던 기억이 있습니다!
만약 그래도 해결이 되지 않으신다면,
괜찮으시다면 로그 일부분이 아닌 풀 로그를 정중하게 요청드립니다...!
댓글이나 maladroit1@likelion.org로 캡쳐본을 보내주시면 함께 고민해보겠습니다 :)