惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
大猫的无限游戏
大猫的无限游戏
S
Securelist
The Hacker News
The Hacker News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs
Jina AI
Jina AI
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
Webroot Blog
Webroot Blog
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
量子位
S
Schneier on Security
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
O
OpenAI News
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
博客园 - 叶小钗
L
LINUX DO - 最新话题
V
Visual Studio Blog
U
Unit 42
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security Affairs
AWS News Blog
AWS News Blog
S
Secure Thoughts
腾讯CDC
Cloudbric
Cloudbric
H
Help Net Security
The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 【当耐特】
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
D
DataBreaches.Net
A
About on SuperTechFans
G
GRAHAM CLULEY
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Martin Fowler
Martin Fowler
Vercel News
Vercel News
Cisco Talos Blog
Cisco Talos Blog
NISL@THU
NISL@THU
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
AWS vs GCP ตอนที่ 4: ต่อเครื่องออกอินเตอร์เน็ตโดยไม่เปิด Public IP
Perajit · 2026-05-18 · via DEV Community
Cover image for AWS vs GCP ตอนที่ 4: ต่อเครื่องออกอินเตอร์เน็ตโดยไม่เปิด Public IP

Perajit

หนึ่งในเคสพื้นฐานที่สุดเวลาใช้ server บน cloud ก็คือ
“อยากให้เครื่องออกอินเตอร์เน็ตได้ แต่ไม่อยากเปิด public IP”

บทความนี้จะสรุปเปรียบเทียบวิธีมาตรฐานที่ AWS และ GCP ใช้แก้ปัญหานี้ แบบภาพรวม

จุดประสงค์ของบทความคือเพื่อเห็นภาพรวมคร่าวๆ และจะละรายละเอียดส่วนที่คิดว่าไม่จำเป็นต้องลงรายละเอียด


เป้าหมาย

ต้องการให้ server สื่อสารกับอินเตอร์เน็ตได้ (HTTP/HTTPS) แต่ไม่ต้องการเปิด public IP


แนวคิดหลัก

Inbound Traffic

ในเคสนี้เราจะใช้ Load Balancer เป็นทางเข้าสำหรับรับ traffic จากภายนอก
ซึ่งจริงๆ มี instance เครื่องเดียวก็ต่อกับ LB ก็ได้ แต่โดยปกติจะใช้เป็น instance group (และมี auto-scaling / auto-healing)

หมายความว่าเราจะต้องเตรียมส่วนหลักๆ ตามนี้

  • Load Balancer: สำหรับเป็นทางเข้า
  • Instance Group: คือกลุ่มเครื่องปลายทางที่ต้องการใช้งาน
  • Network Security: อนุญาต traffic จาก Load Balancer ไปที่กลุ่มเครื่องปลายทาง

Outbound Traffic

มีส่วนที่สำคัญ 2 ส่วน คือ

  • Internet Gateway: ประตูทางออกไปอินเตอร์เน็ต
  • NAT Gateway: เนื่องจาก private IP ไม่สามารถคุยกับอินเตอร์เน็ตได้โดยตรง จึงจำเป็นต้องมีตัวกลาง คือ Network Address Translation (NAT) ทำหน้าที่แปลง private IP เป็น public IP ก่อนออกอินเตอร์เน็ต

เปรียบเทียบความต่างในแต่ละส่วน

1) Network Architecture

AWS:

ต้องสร้าง Subnet แบ่งเป็น 2 วงในแต่ละ AZ (กรณีทำ HA จะต้องมีอย่างน้อย 2 AZ) และต้องจัดการ Route แยกกัน:

  • Public Subnet: เอาไว้วางสิ่งที่ต้องคุยกับอินเตอร์เน็ตโดยตรง เช่น NAT Gateway (กรณีที่เลือกแบบ Zonal) และ Application Load Balancer (ALB)
  • Private Subnet: เอาไว้วางสิ่งที่ต้องการให้เป็น private เช่น EC2
GCP:

สร้าง Subnet เดียวได้เลย ไม่มีคอนเซปท์ของ Public/Private Subnet

2) Internet Gateway

AWS:

ต้องสร้าง Internet Gateway (IGW) แล้วผูกกับ VPC เอง

GCP:

ไม่จำเป็นต้องสร้าง Internet Gateway เอง เพราะ GCP มี Default Internet Gateway ให้ใช้อัตโนมัติอยู่แล้ว

3) NAT Gateway

AWS:

ต้องสร้าง NAT Gateway ซึ่งสามารถเลือกได้ทั้งแบบ Regional (ใช้งานข้ามหลาย AZ ใน VPC) หรือ Zonal (ผูกกับ Subnet) โดยถ้าเลือก Zonal จะต้องวางไว้ที่ Public Subnet

GCP:

ต้องสร้าง Cloud NAT โดยตั้งค่าให้ใช้กับ Subnet ที่มีเครื่องปลายทาง

4) เส้นทางไปยังทางออก (Routing)

AWS:

ต้องกำหนด Route Table เองทั้งหมด

  • Public Subnet: 0.0.0.0/0 -> IGW
  • Private Subnet: 0.0.0.0/0 -> NAT Gateway (ถ้าเลือกแบบ Zonal จะต้องสร้าง Route Table แยกกันแต่ละ AZ เพราะชี้ไปที่ NAT Gateway คนละตัว แต่สำหรับแบบ Regional สามารถใช้ Route Table เดียวกันแชร์กันทุก AZ เพราะใช้ NAT Gateway ตัวเดียวกัน)
GCP:

ไม่จำเป็นต้องตั้งค่าอะไร

  • VPC มีเส้นทางออกอินเตอร์เน็ตให้ใน Default Route อยู่แล้ว: 0.0.0.0/0 -> Default Internet Gateway
  • เมื่อสร้าง Cloud NAT gateway ผูกกับ Subnet แล้ว traffic จาก VM จะวิ่งออกอินเตอร์เน็ตได้โดยใช้ Default Route ของ VPC ได้โดยไม่ต้องมี public IP

5) Network Security

AWS:
  • หลักการ: ใช้ Security Group เป็นหลัก
  • สำหรับขาเข้า: ต้องอนุญาต traffic 2 ขา:
    • Internet -> ALB: ตั้งค่า Security Group สำหรับ ALB อนุญาต traffic จากอินเตอร์เน็ต
    • ALB -> EC2: ตั้งค่า Security Group สำหรับ EC2 อนุญาต traffic จาก ALB
  • สำหรับขาออก: ไม่ต้องตั้งค่าอะไร เพราะ traffic ขาออกสามารถวิ่งผ่านได้โดย default อยู่แล้ว
GCP:
  • หลักการ: ใช้ Firewall Rules / Policy แล้วใช้ Tags เลือกเครื่องเป้าหมาย
  • สำหรับขาเข้า: ต้องตั้งค่าแค่ขาเดียว อนุญาต traffic จาก LB เข้ามาหาเครื่อง
    • Internet -> LB: ไม่ต้องตั้งค่าอะไร เพราะ LB อยู่ที่ Google Front End (นอก VPC) รับ traffic จากอินเตอร์เน็ตได้อยู่แล้ว
    • LB -> VM: สร้าง Firewall Rule อนุญาต LB / Health Check (130.211.0.0/22 กับ 35.191.0.0/16) ให้วิ่งเข้าเครื่องเป้าหมายได้
  • สำหรับขาออก: ไม่ต้องตั้งค่าอะไร เพราะ traffic ขาออกสามารถวิ่งผ่านได้โดย default อยู่แล้ว

6) Instance Group

AWS:

ใช้ Auto Scaling Group (ASG)

GCP:

ใช้ Managed Instance Group (MIG)

7) Load Balancer

AWS:
  • ใช้ Application Load Balancer (ALB)
  • กลุ่มเครื่องปลายทางคือ Target Group (มีได้หลาย Target Group)
  • ต้องสร้าง Target Group และตั้งค่า Health Check ของแต่ละกลุ่ม แล้วตั้งค่าให้ Listener ชี้ไปที่ Target Group
  • ต้องผูก ASG เข้ากับ Target Group (ASG ใช้สำหรับสเกลจำนวน ต้องเชื่อมเข้ากับ Target Group ของ ALB เพื่อใช้เป็นปลายทาง)
GCP:
  • ใช้ Global External Application Load Balancer
  • กลุ่มเครื่องปลายทางคือ Backend Service (มีได้หลาย Backend Service)
  • ต้องผูก Instance Group เข้ากับ Backend Service
  • การตั้งค่า Health Check ใน Backend Service:
    • สามารถสร้าง Health Check ใหม่ในขั้นตอนการตั้งค่า Backend Service ได้เลย
    • หรือจะสร้าง Health Check แยกไว้ก่อนแล้วค่อยเลือกมาผูกกับ Backend Service ทีหลังก็ได้
  • ใช้ Routing Rules ซึ่งเป็น URL Map กำหนดเส้นทางว่าจะไปที่ Backend Service ไหน

8) Health Check

AWS:
  • ผูกอยู่กับ Target Group ของ ALB เป็นหลัก
  • โดย default แล้ว ASG จะใช้ EC2 status เป็น Health Check ซึ่งเช็คแค่ว่าเปิดเครื่องติดรึเปล่า
  • ถ้าผูก ASG กับ Target Group จะสามารถเลือกให้ใช้ ELB Health Check ได้ (Health Check ของ Target Group)
GCP:
  • สามารถสร้างแยกไว้ก่อนแล้วเอาไปผูกกับ LB หรือ MIG ทีหลังได้
  • ผูกกับ LB สำหรับการกระจายโหลด (เช็คว่าจะส่ง traffic ไปให้เครื่องได้รึเปล่า)
  • ผูกกับ MIG สำหรับจัดการ auto scaling / auto healing (เช็คว่าเครื่องยังทำงานได้อยู่รึเปล่า)

ภาพรวมการไหลของ traffic (logical)

Flow AWS GCP
Inbound Internet -> Internet Gateway -> ALB -> Private EC2 Internet -> Global External LB -> Private VM
Outbound Private EC2 -> NAT Gateway -> Internet Gateway -> Internet Private VM -> Cloud NAT -> Internet Gateway -> Internet

เปรียบเทียบขั้นตอนคร่าวๆ

สำหรับ AWS:

1) เตรียม Network

  • สร้าง VPC
  • ในแต่ละ AZ ที่ต้องการ สร้าง Subnet 2 วง สำหรับ Public Subnet และ Private Subnet

2) จัดการทางออก

  • สร้าง Internet Gateway (IGW) ผูกกับ VPC
  • สร้าง NAT Gateway:
    • เลือก Regional หรือถ้าเลือก Zonal ให้ตั้งค่าให้อยู่ใน Public Subnet ที่สร้างไว้
    • เลือก Connectivity Type เป็น public
  • ตั้งค่า Route Table สำหรับ Public Subnet:
    • สร้าง Route: 0.0.0.0/0 -> IGW
  • ตั้งค่า Route Table สำหรับ Private Subnet:
    • สร้าง Route: 0.0.0.0/0 -> NAT Gateway

3) จัดการ Network Security

  • สร้าง Security Group สำหรับ ALB:
    • สร้าง Inbound Rule (HTTP): Type: HTTP, Source: 0.0.0.0/0
    • สร้าง Inbound Rule (HTTPS): Type: HTTPS, Source: 0.0.0.0/0
  • สร้าง Security Group สำหรับ EC2:
    • สร้าง Inbound Rule (จาก ALB): Type: Custom TCP, Port: พอร์ตที่รันแอปพลิเคชั่น, Source: Security Group ของ ALB

4) จัดการ Load Balancer & Health Check:

  • สร้าง Internet-facing ALB
    • วางใน Public Subnet
    • สร้าง Target Group และตั้งค่า Health Check
    • Listener: เลือก Target Group

5) จัดการกลุ่มเครื่อง:

  • สร้าง Launch Template
  • สร้าง ASG:
    • เลือก Launch Template ที่สร้างไว้ และผูกเข้ากับ Target Group (ระบบจะสร้าง EC2 ขึ้นมาให้ใน Private Subnet โดยอัตโนมัติ)
    • วางใน Private Subnet เพื่อให้เครื่องอยู่ในวง private
    • เลือกผูกกับ existing load balancer แล้วเลือก Target Group
    • เลือก Turn on Elastic Load Balancing health checks เพื่อให้ ASG ใช้ Health Check เดียวกับ ALB

สำหรับ GCP:

1) เตรียม Network

  • สร้าง VPC (custom mode) และ Subnet 1 วง

2) จัดการ Network Security

  • สร้าง Firewall Rules
    • ระบุ Target Tag ตรงกับของ MIG (เตรียม Tag ไว้ก่อน)
    • อนุญาต source IP range 130.211.0.0/22 กับ 35.191.0.0/16
    • เลือก TCP พอร์ต 80

3) จัดการทางออก:

  • สร้าง Cloud NAT Gateway และ Cloud Router

4) จัดการ Health Check:

  • สร้างเตรียมไว้สำหรับผูกกับ MIG และ Load Balancer

5) จัดการกลุ่มเครื่อง

  • สร้าง Instance Template (อย่าลืมปิด public IP)
    • ตั้งค่า Network Tags ตามที่เซ็ตไว้ใน Firewall Rules
  • สร้าง MIG (stateless)
    • เลือก Instance Template ที่สร้างไว้
    • เลือก Health Check ที่สร้างไว้

6) จัดการ Load Balancer:

  • จอง Static IP สำหรับ LB
  • สร้าง Load Balancer
    • เลือก Global External Application Load Balancer
    • ตั้งค่า Frontend:
    • กำหนด static IP ตามช่วงที่เตรียมไว้
    • เพิ่ม frontend IP/port สำหรับช่องทางที่ต้องการ
    • ตั้งค่า Backend:
    • เลือก Health Check ที่สร้างไว้
    • สร้าง Backend Service ผูกกับ MIG ที่สร้างไว้