Associate Cloud Engineer ยท Operating VMs and developer environments
Reaching a VM that has no external IP
gcloud compute ssh, IAP TCP forwarding for VMs without external IP, serial console, RDP for Windows, gcloud compute instances list with filters and formats.
Key points
- Use IAP TCP forwarding: gcloud compute ssh VM --tunnel-through-iap.
- It needs a firewall rule allowing 35.235.240.0/20 on tcp:22 (or tcp:3389 for RDP) and the IAP-Secured Tunnel User role.
- The serial console (serial-port-enable metadata, gcloud compute connect-to-serial-port) works even when networking or sshd is broken.
Source: https://docs.cloud.google.com/iap/docs/using-tcp-forwarding
Practice questions
Which source IP range must a firewall rule allow so IAP can forward SSH to a VM?
- 10.0.0.0/8
- 35.235.240.0/20
- 130.211.0.0/22
- 0.0.0.0/0 only
Show answer
Answer: B. 35.235.240.0/20
IAP TCP forwarding connects from 35.235.240.0/20. The other ranges are not used by IAP.
Which items are needed to SSH through IAP to a VM with only an internal IP?
- IAP-Secured Tunnel User role for the user
- Ingress firewall rule allowing 35.235.240.0/20 on tcp:22
- An external IP on the VM
- A Cloud NAT gateway in the region
- The serial-port-enable metadata key
Show answer
Answer: A. IAP-Secured Tunnel User role for the user, B. Ingress firewall rule allowing 35.235.240.0/20 on tcp:22
You need the tunnel IAM role and a firewall rule for the IAP range; the flag makes gcloud use the tunnel. A Cloud NAT gateway or external IP is not required.
True or false: --tunnel-through-iap works only for VMs that have no external IP address.
Show answer
Answer: False
False. The flag forces an IAP tunnel and works even when the VM has an external IP.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
