외부 고객사나 파트너사가 우리의 서비스에 접근할 때, 보안을 위해 방화벽에 특정 IP 주소를 허용해야 하는 경우가 종종 있습니다. 하지만 AWS ALB는 고정 IP를 제공하지 않아 요구사항을 충족하기 어렵습니다. NLB를 사용하여 고정 IP를 할당하는 방법을 정리합니다

전체적인 구조는 다음과 같습니다 Route 53 -> NLB -> Target Group -> ALB

1. Elastic IP 생성

Elastic IP를 생성합니다.

2. 대상 그룹 (Target Group) 설정

  • 대상 유형(Target type)을 Application Load Balancer로 선택합니다.
  • 프로토콜은 TCP, 포트는 80443을 설정합니다.
  • 트래픽을 전달할 ALB를 선택합니다.

3. NLB (Network Load Balancer) 생성

  • 리스너 설정: TCP:80TLS:443 리스너를 추가하고, 위에서 생성한 대상 그룹으로 트래픽을 전달하도록 설정합니다.

  • 네트워크 매핑: NLB를 배치할 VPC와 서브넷을 선택하고, 각 서브넷에 탄력적 IP를 할당합니다.

4. 확인 및 테스트

nslookup을 사용하여 nlb 정보를 조회합니다.

nslookup your-api-nlb-d5799358257e8422.elb.ap-northeast-2.amazonaws.com
Server:		168.126.63.1
Address:	168.126.63.1#53

Non-authoritative answer:
Name:	your-api-nlb-d5799358257e8422.elb.ap-northeast-2.amazonaws.com
Address: 00.00.238.205
Name:	your-api-nlb-d5799358257e8422.elb.ap-northeast-2.amazonaws.com
Address: 00.00.204.175

조회된 고정 IP 중 하나를 로컬에서 테스트 해보기 위해서 /etc/hosts 에 설정

sudo vi /etc/hosts
...
00.00.204.175 your-domain.com

80(http) 포트에 대한 테스트

curl -vvv http://your-domain.com
*   Trying 00.00.204.175:80...
* Connected to your-domain.com (00.00.204.175) port 80 (#0)
> GET / HTTP/1.1
> Host: your-domain.com
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: awselb/2.0
< Date: Tue, 26 Sep 2023 06:49:00 GMT
< Content-Type: text/html
< Content-Length: 134
< Connection: keep-alive
< Location: https://your-domain.com:443/
<
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
</body>
</html>

443(https) 포트에 대한 테스트

curl -vvv https://your-domain.com
*   Trying 00.00.204.175:443...
* Connected to your-domain.com (00.00.204.175) port 443 (#0)
* ALPN: offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
*  CAfile: /etc/ssl/cert.pem
*  CApath: none
* (304) (IN), TLS handshake, Server hello (2):
* (304) (IN), TLS handshake, Unknown (8):
* (304) (IN), TLS handshake, Certificate (11):
* (304) (IN), TLS handshake, CERT verify (15):
* (304) (IN), TLS handshake, Finished (20):
* (304) (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / AEAD-AES128-GCM-SHA256
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=your-domain.com
*  start date: Feb  7 00:00:00 2023 GMT
*  expire date: Jan  4 23:59:59 2024 GMT
*  subjectAltName: host "your-domain.com" matched cert's "your-domain.com"
*  issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M02
*  SSL certificate verify ok.
* using HTTP/2
* h2h3 [:method: GET]
* h2h3 [:path: /]
* h2h3 [:scheme: https]
* h2h3 [:authority: your-domain.com]
* h2h3 [user-agent: curl/7.88.1]
* h2h3 [accept: */*]
* Using Stream ID: 1 (easy handle 0x127810a00)
> GET / HTTP/2
> Host: your-domain.com
> user-agent: curl/7.88.1
> accept: */*
>
< HTTP/2 200
< date: Tue, 26 Sep 2023 06:49:06 GMT
< content-type: text/html

5. Route 53 설정

value/route traffic to 항목을 nlb로 수정하여 nlb 적용을 마무리합니다

nslookup your-domain.com
Server:		168.126.63.1
Address:	168.126.63.1#53

Non-authoritative answer:
Name:	your-domain.com
Address: 13.124.123.75
Name:	your-domain.com
Address: 3.34.110.12

route53 수정전 your-domain.com 에 대한 정보 확인시 기존 alb 내용을 확인할 수 있습니다.

nslookup your-domain.com
Server:		168.126.63.1
Address:	168.126.63.1#53

Non-authoritative answer:
Name:	your-domain.com
Address: 00.00.238.205
Name:	your-domain.com
Address: 00.00.204.175

route53 수정후 위에서 설정한 nlb와 연결된 elastic ip 정보를 확인할 수 있습니다.

참고 자료