Bastion hosts
Bastion hosts for SSH access to instances in private subnets, the security group rules they need, and the newer alternatives.
What it is
- A bastion host is used to SSH into the private EC2 instances.
- The bastion is in the public subnet, which is then connected to all other private subnets.
- The bastion host security group must allow inbound from the internet on port 22 from a restricted CIDR, for example the public CIDR of the corporation.
- The security group of the EC2 instances must allow the security group of the bastion host, or the private IP of the bastion host.
Not in the course slides
Today, AWS offers ways to reach private instances without a bastion: Session Manager (no open ports, no SSH keys) and the EC2 Instance Connect Endpoint (SSH to private IPs with no public IP or bastion). For "least operational overhead" or "no inbound ports", pick these. Bastions still appear in exam questions.
Exam tips
- "SSH to instances in a private subnet" → bastion host in a public subnet (or Session Manager / EIC Endpoint).
- Bastion SG → port 22 from the company's public CIDR only. Private instance SG → port 22 from the bastion's security group.
Common traps
- "Open port 22 on the bastion to 0.0.0.0/0." Restrict it to known CIDRs.
- "Put the bastion in a private subnet." It must be reachable, so it's in a public subnet.
Check yourself
The lab would need two instances and a key pair, so instead:
Bastion SG: inbound TCP 22 from 203.0.113.0/24. App server SG: inbound TCP 22 from the bastion's security group. (Or replace both with Session Manager.)
AWS documentation
Internet gateway and route tables
The internet gateway that gives a VPC internet access, route tables and the local route, and what makes a subnet public.
NAT instance and NAT gateway
How NAT gives private subnets outbound internet access, the outdated NAT instance, the managed NAT gateway and its high availability, the Regional NAT gateway, and the comparison.