Site-to-Site VPN
An IPSec tunnel between your on-premises network and a VPC, running over the public internet, encrypted end to end. AWS terminates it on a Virtual Private Gateway (VGW); you describe your side with a Customer Gateway (CGW). It is the fast, cheap way to connect a data centre to AWS — set up in minutes, no waiting weeks for a cross-connect.
Một đường hầm IPSec nối mạng on-premises của bạn với một VPC, chạy trên internet công cộng, mã hoá từ đầu đến cuối. Phía AWS kết thúc tunnel tại Virtual Private Gateway (VGW); phía bạn khai báo bằng Customer Gateway (CGW). Đây là cách nối data center với AWS nhanh và rẻ — dựng trong vài phút, khỏi đợi hàng tuần để kéo đường vật lý.
The page answers a handful of reflexes: which gateway is which, static vs BGP routing, why on-prem cannot borrow the VPC's NAT Gateway for the internet, and how it scales to many sites (CloudHub) or many VPCs (Transit Gateway).
Trang này trả lời vài phản xạ hay gặp: gateway nào là gateway nào, static hay BGP, tại sao on-prem không mượn được NAT Gateway của VPC để ra internet, và cách mở rộng ra nhiều site (CloudHub) hay nhiều VPC (Transit Gateway).
Site-to-Site VPN is the right answer when… / reach for something else when…Khi nào chọn Site-to-Site VPN… / khi nào dùng thứ khác…
Use Site-to-Site VPNDùng Site-to-Site VPN
- You need on-prem ↔ VPC connectivity now, over the internet you already have. Minutes to stand up, cheap, encrypted.Cần nối on-prem ↔ VPC ngay, dùng luôn đường internet sẵn có. Dựng trong vài phút, rẻ, có mã hoá.
- You want a backup / failover path for a Direct Connect link that is being provisioned or might drop.Cần một đường dự phòng / failover cho Direct Connect đang chờ kéo hoặc có thể rớt.
- The traffic must be encrypted in transit and going over a public path is acceptable.Traffic bắt buộc mã hoá khi truyền và đi qua đường public là chấp nhận được.
- You have several branch offices that should reach AWS and each other cheaply → CloudHub.Có nhiều chi nhánh cần nối tới AWS và nối lẫn nhau với chi phí thấp → CloudHub.
Reach for something elseChuyển sang thứ khác
- You need consistent low latency, high steady bandwidth, or traffic that never touches the internet → Direct Connect.Cần độ trễ thấp ổn định, băng thông cao đều, hoặc traffic không đụng internet → Direct Connect.
- A private line and encryption at once → VPN over Direct Connect, not one or the other.Vừa đường riêng vừa mã hoá → VPN chạy trên Direct Connect, không phải chọn một trong hai.
- Many VPCs, any-to-any, plus on-prem → Transit Gateway (a VPN attaches straight to it).Nhiều VPC, any-to-any, kèm on-prem → Transit Gateway (VPN gắn thẳng vào nó).
- Remote individual users on laptops → AWS Client VPN (OpenVPN), a different service.Từng người dùng lẻ trên laptop → AWS Client VPN (OpenVPN), một service khác.
- Expose one service, not a whole network → PrivateLink.Chỉ mở một service chứ không mở cả mạng → PrivateLink.
The two gateways — VGW on AWS, CGW for on-premHai gateway — VGW ở AWS, CGW cho on-prem
Set up your on-prem end (a software or hardware VPN appliance reachable on a public IP), then two AWS objects: a Virtual Private Gateway attached to the VPC, and a Customer Gateway that points at the appliance's public IP. AWS then builds the connection as two IPSec tunnels for redundancy. Dựng đầu on-prem (một thiết bị VPN phần mềm hoặc phần cứng truy cập được qua IP public), rồi hai object phía AWS: một Virtual Private Gateway gắn vào VPC, và một Customer Gateway trỏ tới IP public của thiết bị. AWS dựng kết nối thành hai tunnel IPSec để dự phòng.
Read it left to right: your appliance is the only thing you run, the CGW is just AWS's note of its public IP, and the VGW is the AWS end bolted to the VPC. Everything in the middle is two encrypted tunnels over the internet. That "over the internet" is the whole reason Direct Connect exists as the alternative.
Đọc từ trái sang phải: thiết bị của bạn là thứ duy nhất bạn phải vận hành, CGW chỉ là chỗ AWS ghi lại IP public của nó, còn VGW là đầu phía AWS bắt vào VPC. Toàn bộ ở giữa là hai tunnel mã hoá chạy trên internet. Chính chỗ "chạy trên internet" là lý do Direct Connect tồn tại như một lựa chọn thay thế.
Route propagation — static vs BGPRoute propagation — static và BGP
The tunnel carries packets; something still has to teach both sides which CIDR is on the other end. Either you write those routes by hand (static), or the two gateways trade them automatically over BGP using their ASNs. ASN = Autonomous System Number, the identifier BGP uses to name each network. Tunnel chỉ chở gói tin; vẫn cần thứ gì đó dạy cho cả hai phía biết dải CIDR nào nằm ở đầu bên kia. Hoặc bạn tự gõ route (static), hoặc hai gateway tự trao đổi route qua BGP bằng ASN của chúng. ASN = Autonomous System Number, con số BGP dùng để đặt tên cho mỗi mạng.
Static is two lines of routing you own; BGP is two ASNs and then hands-off. But both share one trap in red: the VPC route table won't show VGW routes unless route propagation is switched on for it. That single checkbox is the classic "the tunnel is UP but nothing routes".
Static là hai dòng route do bạn tự quản; BGP là hai ASN rồi khỏi đụng tay. Nhưng cả hai chung một cái bẫy tô đỏ: route table của VPC sẽ không hiện route của VGW nếu chưa bật route propagation cho nó. Đúng một ô tick đó là nguyên nhân kinh điển của "tunnel UP rồi mà không route được gì".
64512) and one on the CGW (your side). Think of it as the licence plate of your network — without it the two gateways can't name each other to trade routes.
Một ASN — Autonomous System Number — là con số đặt tên cho một mạng do một tổ chức quản lý trong BGP: mạng on-prem của bạn là một Autonomous System, AWS là một cái khác. BGP là cách hai bên quảng bá cho nhau biết mình sở hữu dải IP nào, nên mỗi bên cần một con số để được nhận diện. Vì thế bật BGP nghĩa là đặt một ASN cho mỗi phía: một cho VGW (phía AWS, mặc định 64512) và một cho CGW (phía bạn). Cứ coi nó như biển số của mạng bạn — không có nó thì hai gateway không gọi tên nhau để trao đổi route được.
64512–65534 (16-bit) or 4200000000–4294967294 (32-bit). The 65000, 65010… you see in these diagrams are just private ASNs picked per site — any value in that range works, as long as the two ends of a BGP session don't clash.
Trên internet công cộng, ASN do IANA/các RIR cấp. Với VPN riêng thì dùng private ASN: 64512–65534 (16-bit) hoặc 4200000000–4294967294 (32-bit). Mấy số 65000, 65010… trong các diagram chỉ là private ASN đặt tuỳ cho từng site — giá trị nào trong dải đó cũng được, miễn hai đầu của một phiên BGP không trùng nhau.
VPN and internet access — the NAT Gateway trapVPN và truy cập internet — cái bẫy NAT Gateway
A tempting design: on-prem hosts reach the internet through AWS, using the VPC's NAT Gateway. It does not work. A NAT Gateway only translates traffic that originates inside the VPC, so packets arriving over the VPN via the VGW are dropped. Two things that do work: a self-managed NAT instance, or routing the traffic back out through on-prem's own NAT. Một thiết kế nghe hấp dẫn: host on-prem ra internet xuyên qua AWS, dùng NAT Gateway của VPC. Không chạy được. NAT Gateway chỉ dịch traffic khởi phát bên trong VPC, nên gói tin đi vào qua VPN qua VGW sẽ bị bỏ. Hai cách chạy được: một NAT instance tự quản, hoặc định tuyến traffic quay ra bằng NAT của chính on-prem.
Same chain three times; only the box in the middle changes. The NAT Gateway is the one that fails, and it fails silently — the tunnel is healthy, the route looks right, and packets just die at the NAT. Remember it as a property of the NAT Gateway, not of the VPN.
Cùng một chuỗi lặp ba lần; chỉ cái hộp ở giữa đổi. NAT Gateway là cái hỏng, và nó hỏng âm thầm — tunnel vẫn khoẻ, route nhìn vẫn đúng, gói tin chỉ lặng lẽ chết ở NAT. Hãy nhớ đây là tính chất của NAT Gateway, không phải của VPN.
VPN CloudHub — one VGW as a hub for many sitesVPN CloudHub — một VGW làm hub cho nhiều site
Attach up to 10 Customer Gateways to a single VGW and you get a low-cost hub-and-spoke: every site has a VPN to the hub, and — because they all share the hub and BGP-advertise their routes — the sites can reach each other through it. It rides the public internet, and it makes a natural failover link between offices. Gắn tối đa 10 Customer Gateway vào một VGW là bạn có một mô hình hub-and-spoke chi phí thấp: mỗi site có một VPN tới hub, và — vì tất cả dùng chung hub rồi quảng bá route qua BGP — các site nói chuyện được với nhau qua hub. Nó chạy trên internet công cộng, và là đường failover tự nhiên giữa các văn phòng.
The hub is just a VGW with more than one CGW attached. Give each site a distinct ASN, let BGP advertise their prefixes, and New York can reach Miami without a direct tunnel between them — the hub relays it. Cheap enough to be the office-to-office backup you leave running.
Hub thực ra chỉ là một VGW gắn nhiều hơn một CGW. Cho mỗi site một ASN riêng, để BGP quảng bá prefix, thế là New York với tới Miami mà không cần tunnel trực tiếp giữa hai bên — hub trung chuyển hộ. Rẻ tới mức cứ để chạy làm đường backup văn phòng-với-văn phòng.
Scaling past one VPC — multiple VPCs & Shared ServicesVượt qua giới hạn một VPC — nhiều VPC & Shared Services
A VGW attaches to exactly one VPC. For several VPCs the slide-level answer is a separate VPN connection per VPC (AWS's own recommendation), or a Direct Connect Gateway so one DX reaches many VPCs. The scalable modern answer is Transit Gateway: attach the VPN once to the TGW and every VPC behind it is reachable. Một VGW gắn vào đúng một VPC. Muốn nhiều VPC thì cách cơ bản là mỗi VPC một VPN riêng (chính AWS khuyến nghị), hoặc dùng Direct Connect Gateway để một DX với tới nhiều VPC. Cách hiện đại và dễ mở rộng là Transit Gateway: gắn VPN một lần vào TGW là mọi VPC phía sau đều tới được.
Shared Services VPC — VPN to one VPC, peering to the restShared Services VPC — VPN tới một VPC, peering tới phần còn lại
A cheaper pattern than a VPN per VPC: run one VPN from on-prem to a Shared Services VPC (replicated services, DBs, or application proxies), then peer the other VPCs to it. Those VPCs reach the shared services directly over peering and need no VPN of their own to on-prem. Một mô hình rẻ hơn so với mỗi VPC một VPN: chạy một VPN từ on-prem tới một Shared Services VPC (dịch vụ nhân bản, DB, hoặc proxy ứng dụng), rồi peer các VPC khác vào nó. Các VPC đó truy cập dịch vụ chung thẳng qua peering, không cần VPN riêng tới on-prem.
One tunnel, one VGW, one bill — everything else hangs off peering. The catch is the usual peering catch: it is not transitive, so the shared VPC is where on-prem and the spoke VPCs actually meet; the spokes don't reach on-prem through it unless you route for that deliberately.
Một tunnel, một VGW, một hoá đơn — mọi thứ còn lại treo vào peering. Điểm cần nhớ vẫn là cái bẫy quen thuộc của peering: nó không bắc cầu, nên Shared Services VPC là nơi on-prem và các VPC spoke thực sự gặp nhau; các spoke không tự nhiên tới được on-prem qua nó trừ khi bạn cố ý định tuyến cho việc đó.
Things that catch you outNhững chỗ dễ sập bẫy
- Tunnel is UP but nothing routes. Almost always route propagation is off on the VPC route table, or the on-prem side has no static route back. The VPN being "up" only means IKE/IPSec negotiated — it says nothing about routing. Tunnel UP mà không route được gì. Gần như luôn là route propagation chưa bật trên route table của VPC, hoặc phía on-prem thiếu static route đường về. Tunnel "up" chỉ nghĩa là IKE/IPSec đã thoả thuận xong — không nói gì về định tuyến.
- The appliance has no public IP. A Site-to-Site VPN terminates on a public, static IP on your side. Behind carrier-grade NAT with no public address, it cannot work as drawn. Thiết bị không có IP public. Site-to-Site VPN kết thúc trên một IP public tĩnh ở phía bạn. Nếu nằm sau NAT của nhà mạng mà không có địa chỉ public thì không dựng được như hình.
- Expecting the NAT Gateway to serve on-prem. It never will — it only NATs traffic that started inside the VPC. Use a NAT instance or on-prem NAT. Trông đợi NAT Gateway phục vụ on-prem. Không bao giờ — nó chỉ NAT traffic khởi phát trong VPC. Dùng NAT instance hoặc NAT on-prem.
- Confusing "encrypted" with "private". A VPN encrypts but runs over the internet; Direct Connect is private but unencrypted. If a question demands both, the answer is VPN over Direct Connect. Nhầm "mã hoá" với "riêng tư". VPN mã hoá nhưng đi qua internet; Direct Connect riêng tư nhưng không mã hoá. Đề đòi cả hai thì đáp án là VPN chạy trên Direct Connect.
- One VGW, many VPCs. A VGW is bound to a single VPC. Reaching several means a VPN each, a Direct Connect Gateway, or moving to Transit Gateway. Một VGW cho nhiều VPC. VGW gắn vào đúng một VPC. Muốn nhiều thì mỗi cái một VPN, dùng Direct Connect Gateway, hoặc chuyển sang Transit Gateway.
- Site-to-Site is not Client VPN. Site-to-Site connects networks (data centre ↔ VPC). Getting a single laptop onto the VPC is AWS Client VPN over OpenVPN — a separate service with its own endpoint. Site-to-Site không phải Client VPN. Site-to-Site nối mạng với mạng (data center ↔ VPC). Đưa một laptop lẻ vào VPC là việc của AWS Client VPN qua OpenVPN — một service riêng, có endpoint riêng.
Exam reflexesPhản xạ khi thi
| The question says…Đề nói… | AnswerĐáp án |
|---|---|
| "Connect a data centre to a VPC, encrypted, set up quickly / cheaply""Nối data center với VPC, mã hoá, dựng nhanh / rẻ" | Site-to-Site VPN (VGW + CGW, two IPSec tunnels)Site-to-Site VPN (VGW + CGW, hai tunnel IPSec) |
| "VPN is up but instances still can't be reached""VPN đã up mà vẫn không tới được instance" | Enable route propagation on the VPC route table; check static routes / BGP ASNsBật route propagation trên route table của VPC; soát static route / ASN của BGP |
| "On-prem hosts must reach the internet through AWS""Host on-prem phải ra internet qua AWS" | NAT instance (or on-prem NAT). Not a NAT GatewayNAT instance (hoặc NAT on-prem). Không phải NAT Gateway |
| "Several branch offices, connect to AWS and each other, low cost""Nhiều chi nhánh, nối tới AWS và nối lẫn nhau, chi phí thấp" | VPN CloudHub — up to 10 CGW per VGW, hub-and-spokeVPN CloudHub — tối đa 10 CGW mỗi VGW, hub-and-spoke |
| "Need a private line and encryption""Cần đường riêng và mã hoá" | Site-to-Site VPN over Direct ConnectSite-to-Site VPN chạy trên Direct Connect |
| "Backup / failover for a Direct Connect link""Dự phòng / failover cho một đường Direct Connect" | Site-to-Site VPN as the secondary pathSite-to-Site VPN làm đường thứ hai |
| "Speed up a VPN for a worldwide network""Tăng tốc VPN cho mạng toàn cầu" | Accelerated Site-to-Site VPN (Global Accelerator)Accelerated Site-to-Site VPN (Global Accelerator) |
| "Connect on-prem to many VPCs""Nối on-prem tới nhiều VPC" | Transit Gateway (or a VPN per VPC / DX Gateway)Transit Gateway (hoặc mỗi VPC một VPN / DX Gateway) |
| "Individual remote users / laptops into the VPC""Từng người dùng / laptop lẻ vào VPC" | AWS Client VPN — not Site-to-SiteAWS Client VPN — không phải Site-to-Site |