The one idea: the answer depends on who asks
Builds on22. DNS23. Records and resolution
DNS turns names into addresses. Everything else in GCP DNS is detail about who answers, and whether the answer is public or private. The same name can give different answers depending on where the question comes from:
| # | Asked by | Name | Answer |
|---|---|---|---|
| 1 | A shopper's phone | api.kade.lk | 34.120.88.10, the load balancer |
| 2 | A shopper's phone | db.kade.internal | Does not exist |
| 3 | kade-worker, inside kade-vpc | db.kade.internal | 10.10.2.5 |
Every question a VM asks goes to the same place: the metadata server at 169.254.169.254, which DHCP set as its DNS server (chapter 1.2 section 06). What the metadata server checks, and in what order, is section 04.
- Run by Google
- Your VPC
Wide by design - scroll it sideways.
Internal DNS: names you get for free
Every VM gets a DNS name automatically, with no setup. It is built from the VM's name, zone and project:
- Set by the VM and its project
Wide by design - scroll it sideways.
kade-db.asia-southeast1-b.c.kade-prod.internal → 10.10.2.5 kade-api-1.asia-southeast1-a.c.kade-prod.internal → 10.10.1.10
Other VMs in the same project and network resolve these names to internal IPs. The metadata server also adds a search domain, so from inside kade-vpc the short name kade-db usually works too. Internal load balancers get names the same way.
Why these names are not enough for Kadé:
| # | Limit | Consequence |
|---|---|---|
| 1 | Tied to the VM's name and zone | A new database VM, or one in another zone, has a different name. Everything that used the old name breaks |
| 2 | Only for VMs and internal load balancers | Cloud SQL, or anything outside Compute Engine, has no internal DNS name here |
| 3 | Only inside the project's network | Other VPCs or the office need peering or forwarding to use them (section 08) |
Cloud DNS zones: public and private
Cloud DNS is GCP's managed authoritative DNS. "Authoritative" means it is the source of truth for a domain: it gives the real answer, not a cached copy (Fundamentals ch 22). A zone is the set of records for one domain. The most important thing about a zone is who may ask it questions:
- Run by Google
- Your VPC
Wide by design - scroll it sideways.
| # | Public zone | Private zone | |
|---|---|---|---|
| 1 | Who can ask | The whole internet | Only the VPC networks you authorize |
| 2 | Used for | Your public domain, when GCP is your DNS provider | Stable, friendly names for internal services |
| 3 | Needs a registrar change | Yes: the domain's name servers must point at Cloud DNS | No: nobody outside needs to know it exists |
| 4 | Kadé's | kade-lk for kade.lk (Fundamentals ch 22) | kade-internal for kade.internal (new) |
The order the metadata server follows
When a VM asks the metadata server a question, the metadata server checks five places in a fixed order, and the first one that has an answer gives it. Each tab follows one name down the list.
Answer: 10.10.2.5 · from private zone kade-internal
Steps 1 and 2 have nothing set, so the question reaches the private zones. kade-internal matches the suffix kade.internal and answers. Internal DNS and public DNS are never asked.
Show as config
kade-worker → 169.254.169.254: db.kade.internal? 1 outbound server policy: none 2 response policies: none 3 private zones: kade-internal (kade.internal.) matches → A 10.10.2.5
Split-horizon: the same name, two answers
Run a public zone and a private zone for the same domain, and a name resolves differently depending on where the question comes from:
Name: api.kade.lk From the internet → public zone kade-lk → 34.120.88.10 (load balancer) From inside kade-vpc → private zone kade-lk-inside → a private IP, straight to the backend
Internal services use the same names the outside world uses, but their traffic goes directly inside the VPC instead of out to the internet and back in through the load balancer. It is a common pattern, and it has one trap:
Each tab is a different set of private zones. The left side shows every private zone kade-vpc can see and whether its suffix matches the name; the right side is public DNS. Use the "what if" buttons to change which name kade-worker asks for.
Answer: 10.10.1.10 · from private zone kade.lk
api.kade.lk matches the private zone kade.lk, which has the record, so kade-worker gets the private address. That part works as planned.
Show as config
Public zone kade.lk: api, www, status, shop … (20 records)
Private zone kade.lk: api → 10.10.1.10 (only the one record needed inside)
kade-worker asks for api.kade.lk → private zone → 10.10.1.10 ✔ as planned
kade-worker asks for status.kade.lk → private zone → NXDOMAIN ✘
(the private zone matched the suffix, so
public DNS is never asked)Try it: which answer do I get?
Choose who asks and which name. Switch the optional zones on to see how the answer changes. The office options only make sense once chapter 15's VPN exists.
Answer: 10.10.2.5, from the private zone kade-internal.
- kade-worker asks the metadata server, 169.254.169.254.
- Step 1: no outbound server policy. Step 2: no response policies.
- Step 3: the private zone kade-internal matches the suffix kade.internal, so it answers. Public DNS will not be asked.
Changing an answer safely: TTL
Builds on23. TTL and caching
Resolvers and apps cache answers for the record's TTL. Changing a record does not change what clients already cached; they only see the new address when their copy expires. The chart follows chapter 9's database cutover: db.kade.internal changes from 10.10.2.5 to 10.10.32.3 at time 0. Each row is something that looked the name up at a different moment.
Longest time a lookup still returns the old address: about 280 s
Each cached answer lives for 300 s from when it was looked up. Instance 2 looked up just before the change, so it keeps using the old address for 280 s. Up to five minutes of mixed traffic: some requests go to the old database, some to the new.
Show as config
db.kade.internal A 10.10.2.5 TTL 300 (cutover at 0 s) → db.kade.internal A 10.10.32.3 Worst case: an answer cached just before 0 s stays in use for 300 s.
| # | When | Step | Why |
|---|---|---|---|
| 1 | A day before | Lower db.kade.internal's TTL from 300 s to 30 s | So the old, long TTL has expired everywhere by cutover time |
| 2 | Cutover | Change the A record to 10.10.32.3, then recycle connection pools | New lookups get Cloud SQL within 30 seconds; pools reconnect |
| 3 | A day after | Raise the TTL back to 300 s | Fewer lookups, and the setting is back to normal |
Connecting GCP DNS to other DNS systems
The remaining zone and policy types all exist for one reason: joining GCP's DNS to other DNS systems, such as the office, another VPC or another cloud. If all your DNS lives in one place, you never touch them.
| # | Type | What it does | Kadé's use | Chapter |
|---|---|---|---|---|
| 1 | Forwarding zone | "For this domain, do not answer here; ask that DNS server" | VMs resolve the office's own names over the VPN | 15 |
| 2 | Peering zone | Lets one VPC use another VPC's private zones | kade-staging uses names from kade-vpc | 14 |
| 3 | Inbound server policy | Gives the VPC DNS entry points (one internal IP per subnet) that outside networks can query | Office PCs resolve db.kade.internal | 15 |
| 4 | Outbound server policy | Sends all of the VPC's questions to your own DNS servers instead | Not used: it switches off most of section 04 | - |
| 5 | Response policy | Overrides answers for chosen names: a different address, or no answer at all | Point *.googleapis.com at private API addresses | 9 |
Each tab follows one question from the asker to the answer, numbered in order. Request arrows are solid; replies come back underneath.
Answer: 172.16.1.40, from the office DNS server
The forwarding zone sends the question to the office DNS server over the VPN. It arrives from 35.199.192.0/19, Cloud DNS's special path (chapter 4), and the answer returns the same way.
Show as config
Forwarding zone: office.kade.lan → target 172.16.1.53 (office DNS server), private routing kade-worker asks nas.office.kade.lan → metadata server → forwarding zone matches → query sent over the VPN to 172.16.1.53, from 35.199.192.0/19 → 172.16.1.40
DNSSEC
Normal DNS answers are not authenticated, so an attacker in the lookup path could return a forged answer that points your domain at their server. DNSSEC adds signatures to records, so a resolver can check that an answer came from the real authoritative source and was not changed.
- Run by Google
- Allowed traffic and replies
Wide by design - scroll it sideways.
| # | Point | Detail |
|---|---|---|
| 1 | Where | Public zones only. Private zones are answered inside Google's network |
| 2 | How | Turn it on for the zone, then add the DS record Cloud DNS gives you at your domain registrar. Until the DS record is there, nothing is checked |
| 3 | Risk | Moving the domain to another DNS provider without turning DNSSEC off correctly can make the whole domain fail to resolve (chapter 13) |
| 4 | Worth it? | A good hardening step for a public domain. Many domains still do not use it |
When your public DNS is not in GCP
Chapter 13 moves kade.lk to Cloudflare. After that, Cloudflare is authoritative for the public domain, with its own records and DNSSEC, and the public zone kade-lk in Cloud DNS is deleted. The private zone kade-internal stays in Cloud DNS: public and private DNS do not have to live in the same place.
- Run by Google
- Your VPC
- Allowed traffic and replies
Wide by design - scroll it sideways.
External DNS is what makes three things concrete, all covered in chapter 13:
| # | Topic | Why DNS is the reason |
|---|---|---|
| 1 | Static load balancer IP | Cloudflare's records hold the address. If it changed, the name would point at nothing. Kadé's is static (chapter 3), so this is already safe |
| 2 | Grey cloud vs orange cloud | A per-record Cloudflare setting: return the GCP address directly (grey, DNS only), or send traffic through Cloudflare first (orange, proxied). It decides whether Cloudflare's WAF and CDN are in the path at all |
| 3 | Origin lock | Only possible for names whose traffic really comes through Cloudflare, so you must know which records are orange first |
Logs and cost
| # | Feature | What it gives |
|---|---|---|
| 1 | Query logging (a server policy setting on the VPC) | Every question VMs in kade-vpc ask, and the answer. Useful to see which names an app really looks up, or to spot a VM resolving strange domains (chapter 16) |
| 2 | Public zone logging | Questions from the internet about your public zone |
Back to Kadé
Commands in this chapter
Commands 1 to 4 are read-only. Commands 5 to 7 change the project.
Resolve a name the way the app does
- What it shows: The address a VM gets for a name, through
/etc/resolv.confand the metadata server. Run inside the VM. - What to look for: The expected address. No output means the name does not resolve from this VM.
getent hosts db.kade.internal
Ask the metadata server directly, with details
- What it shows: The full DNS answer: status, TTL and the answering server.
- What to look for:
status: NOERRORwith an answer, orNXDOMAIN(no such name). The TTL counts down on repeated queries while the answer is cached.
dig @169.254.169.254 db.kade.internalList zones and who can see them
- What it shows: Every Cloud DNS zone in the project, its domain and whether it is public or private.
- What to look for: A private zone whose domain is also a public domain (the trap in section 05).
gcloud dns managed-zones list \ --format="table(name,dnsName,visibility,privateVisibilityConfig.networks[].networkUrl.basename())"List records in a zone
- What it shows: All records in the private zone, with type, TTL and value.
- What to look for:
db.kade.internal.pointing where you expect.
gcloud dns record-sets list --zone=kade-internalCreate the private zone (changes the project)
- What it shows: A private zone for
kade.internal., visible only to kade-vpc. Note the trailing dot. - What to look for: The zone in command 3 with visibility
private.
gcloud dns managed-zones create kade-internal \ --dns-name=kade.internal. --visibility=private \ --networks=kade-vpc --description="Kadé internal names"Add the database record (changes the project)
- What it shows:
db.kade.internalpointing at kade-db, with a 5-minute TTL. - What to look for: Command 1 from any VM in kade-vpc returns
10.10.2.5.
gcloud dns record-sets create db.kade.internal. \ --zone=kade-internal --type=A --ttl=300 --rrdatas=10.10.2.5Point the name somewhere else (changes the project)
- What it shows: Chapter 9's cutover: the same name, now pointing at Cloud SQL, with the low TTL from section 07.
- What to look for: Command 2 shows the new address within one TTL. Then recycle the app's database connections.
gcloud dns record-sets update db.kade.internal. \ --zone=kade-internal --type=A --ttl=30 --rrdatas=10.10.32.3