IPV4 traffic not working with AWS egress only internet gateway - amazon-web-services

I have assigned an egress only internet gateway to my private subnet. Now I can connect with IPV6 websites but not with IPV4 addresses.
Do I need NAT gateways to access IPV4 address from my EC2 machine? (Only outgoing traffic)

You need either a NAT Gateway, or simply an Internet Gateway. But if you are only interested in outgoing, then a NAT Gateway is the way to go.
Egress only internet gateways are for IPv6 only. As mentioned in the documentation for them.

Yes, you need a NAT Gateway to access IPv4 websites from your EC2 instance in private subnet.
To make the instance in private subnet to access both IPv4 and IPv6 websites, we need:
NAT Gateway (Only IPv4 outgoing traffic)
Egress Only Internet Gateway (Only IPv6 outgoing traffic)
Don't forget to assign an IPv6 address to the instance in private subnet otherwise the instance cannot access IPv6 websites.
*A public IPv4 address is not needed for the instance in private subnet. We can access IPv4 websites without it.
Moreover, with the commands below, we can check if the connections to IPv4 and IPv6 websites are available from the instance in private subnet.
For IPv4 websites:
ping -4 google.com
For IPv6 websites:
ping -6 google.com

Related

I cannot connect by ipv6 from aws ec2 after all the essential steps (I learned from the internet)

After referencing many of the websites teaching me how to use ipv6 from AWS EC2 instances, I find it not working. Why?
From AWS EC2 Console,
it seems that my only instance has its ipv6 address.
And I've opened the ICMP IPV6, together with other necessary ipv6 ports, with source identified both 0.0.0.0/0, ::/0.
I've configured the VPC and subnet associated with that instance so they have ipv6 CIDR, and will automatically dispatch ipv6 addresses.
I've also configured that the router associated with the subnet, to have both 0.0.0.0/0, ::/0 paired with igw-xxx (Internet gateway? I guess)
After all these operations, I still can't find any correct records when in shell, typing
ip -6 addr which I believe there should be some v6 address not starting with fe80:, but actually not.
Is there anything else I should do?
Egress Only Internet Gateway(EOIG) is needed to access IPv6 websites from the EC2 instances in private subnet.
In addition, NAT Gateway(NATG) is needed to access IPv4 websites from the EC2 instances in private subnet.
EOIG (Only IPv6 outgoing traffic)
NATG (Only IPv4 outgoing traffic)
You can find EOIG on the left pane which NAT Gateway also is. Then, make one EOIG then set it to the route table associated with private subnet.

DNS resolution in aws from EC2

If spinned up an EC2 instance in a vpc, I removed all outbound rules for security group of EC2, when I ping any public domain like google.com, Facebook.Com from server, still its getting the ip address of domain(similarly pinging Google.com {ipaddress} with 32 bytes of data). From where does instance gets ip address of domain and on which port? even though I blocked all outbound rules of security group?
AWS security groups and network ACLs don't filter traffic to or from:
AWS reserved IPv4 addresses (these are the first four IPv4 addresses of the subnet, including the Amazon DNS server address for the VPC)
link-local addresses (169.254.0.0/16)
The Amazon-supplied VPC DNS server is at the VPC subnet CIDR base +2 address (e.g. 10.0.0.2 if your VPC subnet CIDR is 10.0.0.0).
See Internetwork traffic privacy in Amazon VPC.

NAT instance and NACL configurations

I have
two public subnet which has one NAT EC2 instance and one bastion host
one private subnet which has one EC2 instance
I am able to ping google.com from my bastion host but I am unable to do so from my private EC2 instnace.I have checked all steps mentioned here:-
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-internet-connectivity/
I think the problem is with my NACL.
INBOUND RULES OF THE NACL ATTACHED TO THE PRIVATE SUBNET
OUTBOUND RULES OF NACL ATTACHED TO THE PRIVATE SUBNET
Pinging google.com works in case I detach the NACLS from private subnet. Please verify these NACLS
NOTE: - 10.100.3.0/24 and 10.100.0.0/24 are the CIDRs of my public subnet
Your outbound NACL rules are blocking all traffic except those destined to have a final destination of 2 private IP ranges.
Whilst the NAT might be in these subnets, the target is not, you should allow any IP ranges you want to be able to speak out to.
The NACL is stateless. That means you have to open the respective protocol and ports for outgoing requests and you also need inbound rules for the return traffic of outgoing requests. To allow a response to outgoing ping requests, it must allow inbound ICMP traffic. If you want to send HTTP/S requests, you must allow inbound traffic on the ephemeral ports on TCP.
You can learn more about Network ACLs and ephemeral ports here.

AWS: Why does an Internet Gateway perform NAT?

An Internet gateway serves two purposes: to provide a target in your VPC route tables for Internet-routable traffic, and to perform network address translation (NAT) for instances that have been assigned public IPv4 addresses.
Source: https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Internet_Gateway.html
If the instances mentioned above have public IPv4 addresses, why does the Internet Gateway need to perform Network Address Translation? It would be great to have an example of a network flow that would be broken for a scenario with
VPC subnet with Internet Gateway attached
instances in that VPC subnet with IP addresses (Elastic IPs in AWS VPC parlance) in the public IP address space
hosts on the Internet unable to send packets to these instances without the Internet Gateway performing NAT
Despite of EC2 ( or to be specific: ENI associated with that EC2) instance having associated with public IP address. It is not aware about it!
This is from the same URL which was shared in original link.
" Your instance is only aware of the private (internal) IP address space defined within the VPC and subnet"
This means all network traffic which is going out/coming in to ENI is via private IP address.
If you look at the diagram on the same page, you will see a router.
This router
Does routing within VPC across all its subnets
Does routing to Internet gateway
EC2/ENI will interact with this router.
After router directs traffic to Internet Gateway (IGW):
IGW have mapping of (public ip - private ip ) of EC2 instances within that VPC.
Steps of EC2 sending traffic to Internet
EC2 with private 10.0.1.1 IP sends request to google.com (curl google.com) or tried to access public aws construct like s3
Let's assume that this is public subnet. So Router associated with this subnet will forward this traffic to default route (0.0.0.0/0) to IGW
IGW looks up its internal table (private ip: public ip). Does NAT translation using that table.
I would have liked to describe your scenario but I did not understand why IGW will not perform NAT.
The instance side of an ENI only has a private address. Public addresses are done by associating an Elastic IP or assigning a public address. Mapping of these public addresses comes from the NAT functionality of the Internet Gateway.
Your instance is only aware of the private (internal) IP address space defined within the VPC and subnet. The Internet gateway logically provides the one-to-one NAT on behalf of your instance, so that when traffic leaves your VPC subnet and goes to the Internet, the reply address field is set to the public IPv4 address or Elastic IP address of your instance, and not its private IP address. Conversely, traffic that's destined for the public IPv4 address or Elastic IP address of your instance has its destination address translated into the instance's private IPv4 address before the traffic is delivered to the VPC.
Quote from the same documentation linked in the question.
The flow for inbound traffic is Public Address -> Internet Gateway -> Private Address.
If the hosts are in a subnet without a route table that has a default route defined through the IGW, then the instance will not be able to return traffic.

Can an AWS private IP address server connect to a public IP address server that is in the same VPC?

I have an AWS implementation that has several server instances within the same VPC. Some of the server's only use the private IP addresses -- MongoDB server for instance. Some of the servers have 443 public facing IP addresses. Can a server that is using its private IP address connect to another servers public IP address? Also, is the reverse true -- Public IP Server talking to a private IP Server? Again, all of the servers are in the same VPC.
Can a server that is using its private IP address connect to another
servers public IP address?
Yes.
Make sure the security group of the server with public IP accepts inbound traffic from the VPC NAT
Make sure the internet traffic from the private subnet is correctly routed through the VPC NAT
Also, is the reverse true -- Public IP Server talking to a private IP
Server? Again, all of the servers are in the same VPC.
Yes.
Make sure the routing table of the subnet running the public IP server has an entry to route the private server traffic internally
If you had used VPC creation wizard, the route table entries to route the VPC traffic internally are added automatically.
In order for an instance without a public IP address (an Elastic IP address or an automatically assigned public IP address) assigned to it to communicate with public IP addresses, an instance must be inside of a subnet where the route table points the default route to a NAT gateway or NAT instance (generally - you could probably have a route to a specific IP and assign the destination as a NAT gateway or instance). There is no automatic NAT involved. It must be explicit.
A server with a public IP address assigned to it can communicate with a server without a public IP address so long as they're in the same VPC. The traffic will take place entirely within the private IP space. The server with the public IP address can connect to other server using its private address.