/엔지니어/클라우드/AWS VPC 네트워크 설계 — 서브넷·라우팅·보안
클라우드중급awsvpc서브넷

AWS VPC 네트워크 설계 — 서브넷·라우팅·보안그룹

VPC 생성, 퍼블릭·프라이빗 서브넷 설계, 인터넷 게이트웨이, NAT Gateway, 라우팅 테이블, 보안 그룹과 NACL로 AWS 네트워크를 구성하는 방법을 설명합니다.

VPC 기본 개념

구성 요소역할
VPC격리된 가상 네트워크 (CIDR 블록 정의)
서브넷VPC 내 IP 범위 분할 (퍼블릭 / 프라이빗)
인터넷 게이트웨이(IGW)퍼블릭 서브넷의 인터넷 출구
NAT Gateway프라이빗 서브넷이 인터넷 아웃바운드만 가능
라우팅 테이블트래픽 경로 규칙
보안 그룹(SG)인스턴스 레벨 상태형 방화벽
NACL서브넷 레벨 비상태형 방화벽

VPC 생성

Bash
# VPC 생성 (CIDR: 10.0.0.0/16)
aws ec2 create-vpc   --cidr-block 10.0.0.0/16   --tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=my-vpc}]'

# DNS 호스트네임 활성화
aws ec2 modify-vpc-attribute   --vpc-id vpc-xxxxxxxx   --enable-dns-hostnames

서브넷 설계 (2-AZ 패턴)

Bash
# 퍼블릭 서브넷 (로드밸런서, NAT GW)
aws ec2 create-subnet   --vpc-id vpc-xxxxxxxx   --cidr-block 10.0.1.0/24   --availability-zone ap-northeast-2a   --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=public-2a}]'

aws ec2 create-subnet   --vpc-id vpc-xxxxxxxx   --cidr-block 10.0.2.0/24   --availability-zone ap-northeast-2c   --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=public-2c}]'

# 프라이빗 서브넷 (앱 서버, DB)
aws ec2 create-subnet   --vpc-id vpc-xxxxxxxx   --cidr-block 10.0.11.0/24   --availability-zone ap-northeast-2a   --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=private-2a}]'

aws ec2 create-subnet   --vpc-id vpc-xxxxxxxx   --cidr-block 10.0.12.0/24   --availability-zone ap-northeast-2c   --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=private-2c}]'

인터넷 게이트웨이 + NAT Gateway

Bash
# 인터넷 게이트웨이 생성 및 연결
aws ec2 create-internet-gateway
aws ec2 attach-internet-gateway   --vpc-id vpc-xxxxxxxx   --internet-gateway-id igw-xxxxxxxx

# Elastic IP 할당 (NAT GW용)
aws ec2 allocate-address --domain vpc

# NAT Gateway 생성 (퍼블릭 서브넷에 위치)
aws ec2 create-nat-gateway   --subnet-id subnet-public-2a   --allocation-id eipalloc-xxxxxxxx   --tag-specifications 'ResourceType=natgateway,Tags=[{Key=Name,Value=nat-gw}]'

라우팅 테이블 설정

Bash
# 퍼블릭 라우팅 테이블 (→ IGW)
aws ec2 create-route-table --vpc-id vpc-xxxxxxxx
aws ec2 create-route   --route-table-id rtb-public   --destination-cidr-block 0.0.0.0/0   --gateway-id igw-xxxxxxxx

# 퍼블릭 서브넷 연결
aws ec2 associate-route-table --subnet-id subnet-public-2a --route-table-id rtb-public
aws ec2 associate-route-table --subnet-id subnet-public-2c --route-table-id rtb-public

# 프라이빗 라우팅 테이블 (→ NAT GW)
aws ec2 create-route-table --vpc-id vpc-xxxxxxxx
aws ec2 create-route   --route-table-id rtb-private   --destination-cidr-block 0.0.0.0/0   --nat-gateway-id nat-xxxxxxxx

aws ec2 associate-route-table --subnet-id subnet-private-2a --route-table-id rtb-private
aws ec2 associate-route-table --subnet-id subnet-private-2c --route-table-id rtb-private

보안 그룹 설계

Bash
# ALB 보안 그룹 (인터넷 → ALB)
aws ec2 create-security-group   --group-name sg-alb   --description "ALB Security Group"   --vpc-id vpc-xxxxxxxx

aws ec2 authorize-security-group-ingress   --group-id sg-alb-id   --protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress   --group-id sg-alb-id   --protocol tcp --port 443 --cidr 0.0.0.0/0

# 앱 서버 보안 그룹 (ALB → 앱)
aws ec2 create-security-group   --group-name sg-app   --description "App Server SG"   --vpc-id vpc-xxxxxxxx

# ALB SG에서만 3000 포트 허용
aws ec2 authorize-security-group-ingress   --group-id sg-app-id   --protocol tcp --port 3000   --source-group sg-alb-id

# DB 보안 그룹 (앱 → DB)
aws ec2 create-security-group   --group-name sg-db   --description "Database SG"   --vpc-id vpc-xxxxxxxx

aws ec2 authorize-security-group-ingress   --group-id sg-db-id   --protocol tcp --port 5432   --source-group sg-app-id

VPC Flow Logs (네트워크 감사)

Bash
aws ec2 create-flow-logs   --resource-type VPC   --resource-ids vpc-xxxxxxxx   --traffic-type ALL   --log-destination-type cloud-watch-logs   --log-group-name /aws/vpc/flowlogs   --deliver-logs-permission-arn arn:aws:iam::ACCOUNT:role/FlowLogsRole
#aws#vpc#서브넷#보안그룹#네트워크#nat
편집 안내 · Editorial Note

이 가이드는 AI 도구를 활용해 초안을 구성하고 사람이 명령어·문맥을 검토해 발행했습니다. 운영체제와 도구 버전에 따라 결과가 달라질 수 있으므로 적용 전 공식 문서를 함께 확인하세요. 오류를 발견하시면 이메일로 제보해 주세요.

질문 & 답변 (Q&A)

이 가이드에 대해 궁금한 점을 질문해보세요. 확인 후 답변드립니다.