AWS security groups and Virtual private cloud - amazon-web-services

Can instance1 and instance2 with default security groups communicate with each other if they are in different vpc and in same region?

EC2 instances can't communicate with each other using their private IPs unless both VPCs are peered.
Once Peering is established which includes addition of route table entires for CIDR ranges of peer VPC, pointing to peering connection, then each VPC know where to route requests to when private instances from one vpc tries to talk to private ip of other vpc.

Related

VPC Peering - DNS resolves to public IP

I have configured VPC peering connection between VPC A and VPC B (they are in different accounts but in the same region), and when I try to resolve the domain name of a service (e.g. sometest.com) that is in the VPC B from an instance VPC A, it is supposed to point to a private IP but it resolves to the public IP. The route tables for both VPCs have corresponding entries for peer connection, also security groups allow traffic from/to the peered VPC, and both VPC have "Enable DNS resolution/hostnames enabled.
I'm not sure why it resolves to the public IP - what am I missing?
you need to have vpc-association-authorization established between 2 VPC's and private zones to be able to resolve private hosted zone addresses from 1 vpc in one region/account to another vpc in another region/account
you can follow this step to step guide : https://aws.amazon.com/premiumsupport/knowledge-center/route53-private-hosted-zone/

Can publicly accessible RDS instance be connected privately via VPC peering?

I have a publicly accessible RDS instance that I want to connect to from a EKS cluster in a different VPC. I set up a VPC peering, add cross routes for VPC CIDRs, add EKS VPC CIDR to RDS security group, however there's no db connection unless I add a NAT IP address from EKS cluster (I have worker nodes in private subnets) to the inbound rules of RDS security group. It looks like because RDS instance created as publicly accessible its hostname always resolved to the public IP so the connection from EKS happens from a public NAT EIP to a public RDS EIP. Is this how it should be and cannot be changed? Does it mean there's no point in VPC peering because the connection will never be private? Ideally I want the traffic between EKS and RDS be private and never leave VPCs or does AWS already routes the traffic internally despite the connection happening through EIPs?
I just needed to enable DNS settings of VPC peering connection to allow resolution to private IP https://stackoverflow.com/a/44896732/1826109

Connectivity between 2 Oracle RDS instances in AWS on 2 private subnets in 2 VPCs

Is there a way to connect one database in a private subnet in a VPC to another database in a private subnet in another VPC? Both have same master account but separate accounts each.
This could be done with VPC Peering.
A direct connection between the VPCs is established and all traffic is conducted with private IPV4 addresses. You can even do this with VPCs in different regions, where the traffic is encrypted and routed via the AWS backbone.
Peering is established when the Owner of the first VPC sends a peering request to the owner of the second VPC, and they can reside in different accounts.

What are the security group rules for Amazon RDS dbinstance and EC2 instance over the different VPCs with VPC Peering?

What security group rules should I set for my db instance and my EC2 instance for accessing DB instance from my EC2 instance?
Both are in different VPCs and I used VPC Peering between them.
I did following configuration:
I created two VPC's
One is with public subnet and another is with private subnet
Launch EC2 web instance with public VPC and MySQL db instance with private subnet
Set VPC peering between them and they both have different security groups
Created a NAT Gateway in public subnet
So, how should I set both security group rules for establishing connections between them?
You should configure:
A security group on the Amazon EC2 instance (App-SG) that permits access to the instance/application as desired
A security group on the Amazon RDS DB instance (DB-SG) that permits inbound access on port 3306 for App-SG
That is, DB-SG should specifically refer to App-SG in the inbound rules.
When connecting from the EC2 to the database, make sure you are using the DNS Name of the RDS database. This should resolve to a private IP address.
The NAT Gateway is not required for the above connection.

AWS public subnet VPC communication

I have two instances in public subnet of 2 different VPCs.
To allow communication between them, I have to add public IP of one instance to the other.
If one of the server is changed, I need to add the IP again to other servers security group.
If I just add security group of one VPC to other or even all the allowed IPs of VPC, it does not work.
So I am looking for a workaround to not add IP each time .
Facing this issue because both servers are in public subnet.
VPC peering is already present bwteen both VPCs. issue is communication between public subnets in different VPCs
There should be no need to use the public IP address of the instances. The instances should communicate with each other via their private IP address across the VPC Peering connection.
The best way to do this is:
Create a security group (SG-A) and assign it to Instance-A
Create a security group (SG-B) and assign it to Instance-B
SG-A should permit inbound connections from SG-B
SG-B should permit inbound connections from SG-A
There is no need to reference specific IP addresses. Referencing the other security group will automatically enable communication on the chosen port(s).
See: Updating Your Security Groups to Reference Peer VPC Groups - Amazon Virtual Private Cloud
A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them privately. Instances in either VPC can communicate with each other as if they are within the same network. You can create a VPC peering connection between your own VPCs, with a VPC in another AWS account, or with a VPC in a different AWS Region.
https://docs.aws.amazon.com/vpc/latest/userguide/vpc-peering.html
https://docs.aws.amazon.com/vpc/latest/peering/vpc-peering-security-groups.html