Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

JINIers

[Qwiklabs] Configuring Private Google Access and Cloud NAT 본문

GCP/Qwiklabs

[Qwiklabs] Configuring Private Google Access and Cloud NAT

JINIers 2022. 3. 3. 16:04

비공개 google 액세스 및 cloud nat 구성(VPC + NAT)

 

[목표]

  • 외부 ip 주소가 없는 vm 인스턴스 구성
  • 외부 ip 주소가 없는 vm에 연결한 bastion host 생성
  • 서브넷에서 비공개 google 액세스를 활성화
  • cloud nat 게이트웨이 구성
  • google api 및 서비스의 공개 ip 주소 및 기타 인터넷 연결에 대한 액세스 확인
  • cloud nat 로깅으로 nat 연결 기록

 


1. vm 인스턴스 만들기

[vpc 네트워크 및 방화벽 규칙 만들기]

vpc network create
- name : privatenet
- subnet creation mode : custom

- Name : privatenet-us
- Region : us-central1
- IP address range : 10.130.0.0/20


[firewall 만들기]

gcloud compute firewall-rules create privatenet-allow-ssh --direction=INGRESS --priority=1000 --network=privatenet --action=ALLOW --rules=tcp:22 --source-ranges=0.0.0.0/0

[공개 ip 주소가 없는 vm 인스턴스 만들기]

Name : vm-internal
Region : us-central1
Zone : us-central1-c
Machine type : 1vCPU (3.75 GB memory, n1-standard-1)            // 기존에 있는거 안건드리고 그냥 넘어가면 댐

Network interfaces > 
Network : privatenet
Subnetwork : privatenet-us
External IP : None


[bastion host 만들기]

gcloud compute instances create vm-bastion --zone=us-central1-c --machine-type=e2-micro --network-interface=network-tier=PREMIUM,subnet=privatenet-us --metadata=enable-oslogin=true --maintenance-policy=MIGRATE --create-disk=auto-delete=yes,boot=yes,device-name=vm-bastion,image=projects/debian-cloud/global/images/debian-10-buster-v20220118,mode=rw,size=10,type=projects/qwiklabs-gcp-03-4e14f4b1285e/zones/us-central1-c/diskTypes/pd-balanced --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any


[vm-bastion에 대한 SSH 및 vm-internal에 대한 액세스 확인]

bastion ssh >

ping test

ping -c 2 www.google.com



gcloud compute ssh vm-internal --zone=us-central1-c --internal-ip
y
y


엔터, 엔터

ping -c 2 www.google.com

 

→ 핑 안나감

exit

2. 비공개  google 액세스 활성화

[Cloud storage 버킷 만들기]

cloud storage > browser > create bucket

name : bastion-test-song
Default storage class : Multi-Regional

[버킷에 이미지 파일 복사]

gsutil cp gs://cloud-training/gcpnet/private/access.png gs://bastion-test-song

access.png가 버킷에 있는지 확인


[vm 인스턴스에서 이미지에 액세스]

bastion ssh > 

gsutil cp gs://bastion-test-song/*.png .

gcloud compute ssh vm-internal --zone=us-central1-c --internal-ip

gsutil cp gs://bastion-test-song/*.png .


→ 작동 안함 


[비공개 google 액세스 활성화]

vpc network > vpc network > privatenet-us > edit > Private Google Access : On > save

bastion ssh >

gcloud compute ssh vm-internal --zone=us-central1-c --internal-ip
gsutil cp gs://bastion-test-song/*.png .

3. cloud nat 게이트웨이 구성

[vm 인스턴스 업데이트 시도]

bastion ssh > 

sudo apt-get update
gcloud compute ssh vm-internal --zone=us-central1-c --internal-ip
sudo apt-get update

[cloud nat 게이트웨이 구성]

network service > cloud NAT > get started > 
조건
Gateway name nat-config
VPC network privatenet
Region us-central1

  • router  create new router
     - name nat-router


[cloud nat 게이트웨이 확인]

bastion ssh >

gcloud compute ssh vm-internal --zone=us-central1-c --internal-ip
sudo apt-get update

4. google nat logging으로 로그 구성 및 보기

[로깅 활성화]

nat-config 클릭 > edit > Advanced configurations : Translation and errors 변경 > save

[stackdriver의 nat 로깅]

nat-config 클릭 > logs > cloud logging 링크 클릭

[로그생성]

gcloud compute ssh vm-internal --zone=us-central1-c --internal-ip

sudo apt-get update




[로그 보기]

로그로그

 

작동 안함 → 설정 → 작동함 순으로 되는 걸 확인할 수 있음

Comments