Here's my setup:
- I have 3 instances in us-east-1a
- instanceA is in public subnet with publicIP
- instanceB is in private subnet without publicIP
- instanceC is in public subnet with publicIP
- I put instanceC behind NLB. The NLB is on public subnets us-east-1a and us-east-1b
- The security group for instanceC is:
- Allow SSH from instanceA's public IP
- Allow SSH from instanceB's private IP
I can directly ssh to instanceC from instanceA and B without any issue. But whenever I ssh to the NLB's DNS, i can only connect from instanceA. Whenever I ssh to NLB from instanceB, there will just be a connection timed out.
I checked the network interface of the NLB, and I see that there are a pair of public and private IP per NLB's availability zone.
From instanceA, I can ssh to NLB's public IP addresses, but I can not ssh to NLB's privateIPs. From instanceB, I can ssh to NLB's private IP addresses, but I can not ssh to NLB's publicIPs
Now, i tried to ssh -vvv the NLB, and I can see that I am trying to connect to NLB's public IP. This might be the reason why I can not connect to NLB from instanceB because as I said above, instanceB can only connect to NLB's privateIPs.
I tried to modify the sg of InstanceC and allow ssh from 0.0.0.0/0 and I can successfully access the NLB from instanceB. But this is not what I want. I don't want to allow everyone to access instanceC via NLB.
I want instanceB to be able to ssh to instanceC via NLB too just like instanceA. How can I accomplish this? What should I need to modify in sg, nlb, az, etc?
Thanks!