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.

A Site-to-Site VPN topology. On the left, a corporate data centre holds a VPN appliance with a public IP. A Customer Gateway object describes that appliance to AWS. Two IPSec tunnels — Site-to-Site VPN tunnel 1 and tunnel 2, for redundancy — cross the public internet to a Virtual Private Gateway attached to the VPC on the right. Inside the VPC a private subnet holds an EC2 instance. The traffic is IPSec-encrypted, rides the public internet, needs the appliance to have a public IP, and can optionally be accelerated worldwide with AWS Global Accelerator. on-prem appliance ↔ VPC — two IPSec tunnels over the public internet Corporate DC VPN appliance public IP Customer GW (CGW) public internet tunnel 1 · IPSec tunnel 2 · IPSec VPC VGW Virtual Private GW private subnet EC2 two tunnels = redundancy · the on-prem appliance must have a public, static IP IPSec-encrypted, but it rides the public internet — that is the Direct Connect trade-off worldwide networks: accelerate with AWS Global Accelerator

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ế.

VGW vs CGW — don't mix them upVGW và CGW — đừng lẫn lộn VGW = Virtual Private Gateway = the AWS side, attached to your VPC. CGW = Customer Gateway = the AWS-side resource that represents your on-prem appliance (its public IP, and its ASN if you use BGP). The physical box in your data centre is the customer gateway device; the CGW is how AWS knows about it. Exam questions swap these two names to see if you flinch. VGW = Virtual Private Gateway = phía AWS, gắn vào VPC của bạn. CGW = Customer Gateway = tài nguyên phía AWS đại diện cho thiết bị on-prem của bạn (IP public, và ASN nếu dùng BGP). Cái hộp vật lý trong data center là thiết bị customer gateway; còn CGW là cách AWS biết tới nó. Đề thi hay tráo hai cái tên này để xem bạn có lung lay không.

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.

Route propagation in Site-to-Site VPN. Along the top, a corporate data centre on 10.3.0.0/20 connects through a Customer Gateway with a custom ASN, across the Site-to-Site VPN, to a Virtual Private Gateway with a custom ASN, into a VPC on 10.0.0.0/24. Below are two panels. Static routing: create a static route in the data centre for the VPC CIDR through the CGW, and a static route in AWS for the on-prem CIDR through the VGW, maintained by hand. Dynamic routing with BGP: the CGW and VGW exchange routes automatically once each has an ASN, with no manual route table edits. A note at the bottom warns that route propagation must be enabled on the VPC route table or the learned routes never appear. Corporate DC 10.3.0.0/20 its route table CGW custom ASN Site-to-Site VPN VGW custom ASN VPC 10.0.0.0/24 its route table Static routing on-prem: 10.0.0.0/24 → via CGW AWS: 10.3.0.0/20 → via VGW you maintain both sides by hand fine for a few fixed CIDRs no ASN needed Dynamic routing — BGP CGW & VGW exchange routes for you just set each side's ASN (eBGP) no manual route table edits tracks CIDR changes on either end scales — the usual choice either way: enable ROUTE PROPAGATION on the VPC route table, or the routes the VGW learns never appear and the VPC can't reply

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ì".

What an ASN is (and why BGP needs one)ASN là gì (và tại sao BGP cần nó) An ASN — Autonomous System Number — is the number that names a network under one administration in BGP: your on-prem network is one Autonomous System, AWS is another. BGP is how two of them advertise to each other which IP ranges they own, so each side needs a number to be identified by. That is why enabling BGP means setting an ASN on each side: one on the VGW (AWS side, default 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.
Which numbers to useDùng số nào On the public internet, ASNs are assigned by IANA/the RIRs. For a private VPN you use a private ASN: 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.

Three internet-access designs for Site-to-Site VPN. Row one, marked NOT OKAY: on-prem to CGW to VGW to a NAT Gateway to an Internet Gateway to google.com, but the NAT Gateway is crossed out with a red X because it will not serve VPN traffic. Row two, marked OKAY: the same chain but with a self-managed NAT instance in place of the NAT Gateway, which forwards the traffic to the Internet Gateway and out to google.com. Row three, marked OKAY: a private subnet sends internet-bound traffic through the VGW, back over the VPN to the CGW and an on-premises NAT, which reaches google.com. The takeaway is that a NAT Gateway only serves traffic that originates inside the VPC. NOT OKAY — a NAT Gateway won't serve traffic that came in over the VPN on-prem CGW VGW NAT Gateway IGW google.com dropped at the NAT GW OKAY — a self-managed NAT instance (you own the rules) on-prem CGW VGW NAT instance IGW google.com it forwards it — works OKAY — send it back out through on-prem's own NAT private subnet VGW CGW on-prem NAT google.com exits at the on-prem edge the rule under all three: a NAT Gateway only serves traffic that originated INSIDE the VPC — VPN traffic did not, so it needs another exit the "(or Direct Connect)" version of these pictures behaves identically

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.

AWS VPN CloudHub. A single Virtual Private Gateway in your VPC sits on the left as a hub. Three Site-to-Site VPN spokes fan out to three customer networks on the right: New York with a Customer Gateway ASN 65010, Los Angeles with ASN 65011, and Miami with ASN 65012. Because the spokes share the hub, the sites can also reach one another through it. Notes state up to ten customer gateways per VGW, that it is a hub-and-spoke model over the public internet, low cost, and usable as a primary or failover link between on-premises locations. one VGW hub, many customer gateways — sites talk through the hub VGW (hub) in your VPC up to 10 CGW / VGW S2S VPN S2S VPN S2S VPN Customer Network — New York CGW · ASN 65010 Customer Network — Los Angeles CGW · ASN 65011 Customer Network — Miami CGW · ASN 65012 hub-and-spoke over the public internet · low cost · sites reach each other via the hub great as a primary or failover link between on-premises locations

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.

A few VPCsVài VPC One VPN connection per VPC, each with its own VGW. Simple, and what AWS recommends for VPN-based customers.Mỗi VPC một VPN, mỗi cái một VGW riêng. Đơn giản, và là điều AWS khuyến nghị cho khách dùng VPN.
One DX, many VPCsMột DX, nhiều VPC A Direct Connect Gateway lets a single Direct Connect (or VPN over it) reach VPCs in many Regions.Một Direct Connect Gateway cho phép một Direct Connect (hoặc VPN chạy trên nó) với tới VPC ở nhiều Region.
Many VPCs, any-to-anyNhiều VPC, any-to-any Attach the VPN to a Transit Gateway once; it fans out to every attached VPC and on-prem together.Gắn VPN vào Transit Gateway một lần; nó toả ra mọi VPC đã gắn và cả on-prem.

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.

A Shared Services VPC pattern. At the bottom, a corporate data centre with a Customer Gateway connects by a single Site-to-Site VPN to a VGW on a Shared Services VPC in the middle, which holds replicated services and application proxies. Three VPCs — A, B and C — sit across the top, each connected to the Shared Services VPC by VPC peering. The three VPCs reach the shared services directly over peering and do not need their own VPN connections to on-premises. one VPN to the shared VPC · the others reach it by peering VPC A VPC B VPC C VPC peering Shared Services VPC replicated services application proxies VGW Site-to-Site VPN CGW Corporate DC

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