{GCP VPC} VPC フローログを使用する

 

https://cloud.google.com/vpc/docs/using-flow-logs?hl=ja#gcloud


VPC フローログには、VM インスタンスによって送受信されたネットワーク フローのサンプルが記録されます。
これには GKE ノードとして使用されるインスタンスも含まれます。
これらのログは、ネットワーク モニタリング、フォレンジック、リアルタイム セキュリティ分析、および費用の最適化に使用できます。

 

-- 1. 前作業

gcloud init
gcloud auth list

gcloud --version

gcloud projects create project01-9999999 \
--name="project01"

gcloud config list
gcloud config set project project01-9999999
gcloud config set compute/region asia-northeast1 --quiet
gcloud config set compute/zone asia-northeast1-a --quiet

gcloud beta billing accounts list
gcloud beta billing projects link project01-9999999 --billing-account=111111-111111-111111

gcloud services enable compute.googleapis.com --project project01-9999999

gcloud components update

 


-- 2. VPC作成


gcloud compute networks create vpc01 \
--subnet-mode=custom \
--mtu=1460 \
--bgp-routing-mode=regional


gcloud compute networks list


-- 3. VPC フローログを有効化したサブネットの作成


gcloud compute networks subnets create subnet01 \
--range=10.0.1.0/24 \
--stack-type=IPV4_ONLY \
--network=vpc01 \
--region=asia-northeast1 \
--enable-flow-logs \
--logging-aggregation-interval=interval-1-min \
--logging-flow-sampling=0.5 \
--logging-metadata=include-all

 

gcloud compute networks subnets list

gcloud compute networks subnets list \
--network=vpc01 \
--format="csv(name,region,logConfig.enable)"

 

-- 4. ファイアウォールルール作成

gcloud compute firewall-rules create fw01 \
--network vpc01 \
--allow tcp:22,tcp:3389,icmp

 

gcloud compute firewall-rules list

 

-- 5. vmインスタンス作成


gcloud compute instances create vm01 \
--machine-type=e2-micro \
--image-project=centos-cloud \
--image=centos-7-v20221004 \
--provisioning-model=SPOT \
--instance-termination-action=DELETE \
--network=vpc01 \
--subnet=subnet01 \
--zone=asia-northeast1-a

gcloud compute instances list

 

-- 6. 動作確認


gcloud compute ssh vm01


コンソールから
ログ エクスプローラを使用して、VPC フローログを表示

 

 

-- 7. クリーンアップ

gcloud projects list

gcloud projects delete project01-9999999