![[AWS] Bastion Host 구성하기](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FzPTmm%2FbtrythOe0g0%2FKWdwmTkoRIFRyn17WfTCBK%2Fimg.png)
✔︎ 실습에 앞서
[AWS] Bastion Host의 개념
✔︎ Bastion Host 란? Bastion Host란 침입 차단 소프트웨어가 설치되어 내부, 외부 네트워크 사이에서 일종의 방화벽, 게이트 역할을 수행하는 호스트를 뜻한다. Bastion Host는 접근 제어와 응용 시스템,
nice-engineer.tistory.com
Bastion Host를 이용해 보안성이 강화된 웹 서버를 구성해보자
결과 구성도는 다음과 같다.

Bastion Host는 Public Subnet에 속하며, 공인 IP를 할당 받는다.
Private Host는 공인 IP를 할당받지 못하며, Bastion Host에서의 트래픽만 받을 수 있게 보안 그룹이 설정되어 있다.
✔︎ Bastion Host 실습 순서
Bastion Host 실습 순서는 다음과 같다.
1. VPC, Subnet 및 라우팅 테이블 설정
2. NAT gateway 설정
3. 보안 그룹 2개 설정
4. EC2 2개 생성
5. Bastion을 통한 Private EC2 접속 시도
1. VPC, Subnet 및 라우팅 테이블 설정
실습은 VPC 마법사를 이용해 VPC를 구성한다.

VPC CIDR : 10.0.0.0/16
Public Subnet
CIDR : 10.0.10.0/24
Private Subnet
CIDR : 10.0.128.0/24
2. NAT gateway 설정

NAT-sg를 생성해 Private Subnet의 주소인 10.0.128.0/24를 Source에 입력한다.
NAT-sg는 10.0.128.0/24 에서 접속하는 모든 Port의 Traffic을 허용한다.

Private Subnet에서 0.0.0.0/0 을 목적지로 하는 (인터넷 통신용) 패킷은 앞에서 생성해준 NAT gateway로 보낸다.
Target에는 NAT gateway의 ID를 입력한다.

3. 보안 그룹 2개 설정
Bastion Host 용 보안 그룹

VPC에는 앞서 만들었던 VPC를 지정해주어야 한다.
Private Host 용 보안 그룹

4. EC2 2개 생성
Bastion Host

Private Host

private host는 웹 페이지 접속 여부로 테스트 할 것이기 때문에 셸 스크립트를 이용해 apache를 세팅해준다.

5. Bastion을 통한 Private EC2 접속 시도
Bastion Host ec2를 생성할 때 받은 키페어를 사용해 Private Host에 접속한다.
vi 에디터를 이용해 Bastion Host의 key를 복사해 사용한다.
[ec2-user@ip-10-0-10-46 ~]$ ls -a
. .. .bash_logout .bash_profile .bashrc .ssh
[ec2-user@ip-10-0-10-46 ~]$ cd .ssh
[ec2-user@ip-10-0-10-46 .ssh]$ vi key
[ec2-user@ip-10-0-10-46 .ssh]$ chmod 400 key
[ec2-user@ip-10-0-10-46 .ssh]$ cd ..
[ec2-user@ip-10-0-10-46 ~]$ ssh -i .ssh/key ec2-user@10.0.128.208
The authenticity of host '10.0.128.208 (10.0.128.208)' can't be established.
ECDSA key fingerprint is SHA256:A658agXzsHqvO28/rO3wd+fFJg4Q1+0m5ZrlbU+de3g.
ECDSA key fingerprint is MD5:41:39:bd:60:d7:a0:13:aa:26:aa:44:b9:67:be:ca:a6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.128.208' (ECDSA) to the list of known hosts.
__| __|_ )
_| ( / Amazon Linux 2 AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-2/
[ec2-user@ip-10-0-128-208 ~]$ curl 10.0.128.208
✔︎ ping 테스트

Bastion Host → Private Host로 ping 테스트
[ec2-user@ip-10-0-10-46 ~]$ ping 10.0.128.208
PING 10.0.128.208 (10.0.128.208) 56(84) bytes of data.
64 bytes from 10.0.128.208: icmp_seq=1 ttl=255 time=0.414 ms
64 bytes from 10.0.128.208: icmp_seq=2 ttl=255 time=0.472 ms
64 bytes from 10.0.128.208: icmp_seq=3 ttl=255 time=0.468 ms
64 bytes from 10.0.128.208: icmp_seq=4 ttl=255 time=0.435 ms
64 bytes from 10.0.128.208: icmp_seq=5 ttl=255 time=0.487 ms
64 bytes from 10.0.128.208: icmp_seq=6 ttl=255 time=0.505 ms
64 bytes from 10.0.128.208: icmp_seq=7 ttl=255 time=0.521 ms
64 bytes from 10.0.128.208: icmp_seq=8 ttl=255 time=0.480 ms
64 bytes from 10.0.128.208: icmp_seq=9 ttl=255 time=0.564 ms
64 bytes from 10.0.128.208: icmp_seq=10 ttl=255 time=0.560 ms
64 bytes from 10.0.128.208: icmp_seq=11 ttl=255 time=0.453 ms
64 bytes from 10.0.128.208: icmp_seq=12 ttl=255 time=0.431 ms
64 bytes from 10.0.128.208: icmp_seq=13 ttl=255 time=0.467 ms
64 bytes from 10.0.128.208: icmp_seq=14 ttl=255 time=0.432 ms
^C
--- 10.0.128.208 ping statistics ---
14 packets transmitted, 14 received, 0% packet loss, time 13303ms
rtt min/avg/max/mdev = 0.414/0.477/0.564/0.052 ms

Private Host → 외부 IP로 ping 테스트
[ec2-user@ip-10-0-128-208 ~]$ ping www.google.com
PING www.google.com (142.251.46.228) 56(84) bytes of data.
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=1 ttl=107 time=1.95 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=2 ttl=107 time=1.60 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=3 ttl=107 time=1.68 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=4 ttl=107 time=1.62 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=5 ttl=107 time=2.31 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=6 ttl=107 time=1.56 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=7 ttl=107 time=1.65 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=8 ttl=107 time=1.69 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=9 ttl=107 time=1.68 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=10 ttl=107 time=1.56 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=11 ttl=107 time=1.68 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=12 ttl=107 time=1.59 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=13 ttl=107 time=1.58 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=14 ttl=107 time=1.58 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=15 ttl=107 time=1.66 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=16 ttl=107 time=1.59 ms
64 bytes from sfo03s27-in-f4.1e100.net (142.251.46.228): icmp_seq=17 ttl=107 time=1.57 ms
^C
--- www.google.com ping statistics ---
17 packets transmitted, 17 received, 0% packet loss, time 16028ms
rtt min/avg/max/mdev = 1.568/1.684/2.310/0.180 ms

'Public Cloud > AWS' 카테고리의 다른 글
[AWS] S3를 이용한 CloudFront 실습 (0) | 2022.04.06 |
---|---|
[AWS] Auto Scaling 실습 (0) | 2022.04.05 |
[AWS] Bastion Host의 개념 (0) | 2022.04.04 |
[AWS] ELB를 생성해 EC2 인스턴스 로드밸런싱하기 (0) | 2022.04.01 |
[AWS] nginx, Phusion Passenger 설치 및 서비스 구현 (0) | 2022.04.01 |
영차영차 성장 블로그
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!