Hi, maybe a stupid question but if I have one VPC, and instances are using Ipv6, I have both internet gateway and egress internet gateway. To reach internet as I understand, I need to use internet gateway, but when i want to reach internet but with my instance not being accessed for incoming connection I need to use egress internet gateway. So i just need to set routing table and thats it, but how does the incoming connection know wich one to gateway to use?
For example I have opened port on instance for http, how exactly is it choosed to route through igw and allow or eigw and block?
Related discussions:
Internet Gateway usually allows two way traffic (in & out) : https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html
>An internet gateway enables resources in your public subnets (such as EC2 instances) to connect to the internet if the resource has a public IPv4 address or an IPv6 address. Similarly, resources on the internet can initiate a connection to resources in your subnet using the public IPv4 address or IPv6 address. For example, an internet gateway enables you to connect to an EC2 instance in AWS using your local computer.
The “egress only gateway” is only outbound (the key word being ONLY)
https://docs.aws.amazon.com/vpc/latest/userguide/egress-only-internet-gateway.html
>An egress-only internet gateway is a horizontally scaled, redundant, and highly available VPC component that allows outbound communication over IPv6 from instances in your VPC to the internet, and prevents the internet from initiating an IPv6 connection with your instances.
I dont see why you would have both on the same VPC…
If you want traffic in / out - use internet gateway.
If you do not want traffic into your VPC from internet BUT you want to say send out some traffic from your app or pull down software updates etc - then you can use the “egress” only.
​
A very bad analogy follows :
Internet gateway - allows people to come in and out of your house. Strangers can come in. Family folks already in the house can go out.
Egress only gateway - only your family / house hold people can go out - strangers are not allowed in.
Thank you for your reply, I can have 2 subnets in my VPC, one for public and one for private usage. For example I can have private IPV4 assigned to my ec2 and ipv6 inside my private subnet. Now I can send all outgoing traffic to internet through EIGW or IGW (because I have IPV6)- it’s ok, but how it works for requests initiated from internet? Theoretically instance should be accessible by IPV6, so how it knows to send traffic through IGW and allow connection to my EC2 or EIGW and deny? Correct me if Im wrong.
I found that question a bit confusing but will try to reply.
In general all incoming traffic is Internet -> Internet Gateway -> Public Subnet -> Private subnet.
Usually all traffic goes out via the same route it came in - you dont generally get to send out traffic via another route and expect it to reach.
dont know if that answers - a bit hard to do this over comments on reddit
Ok, I have IPV6 instance, I can ssh to it by IPV6 address because ssh goes over Internet Gateway to my instance. If I setup Egress Internet Gateway I will be unable to SSH into my EC2, yes? How does it know that traffic should be know blocked? I have two gateways. I dont specify that. I only setup outbound traffic in routing table.
Imagine:
- Setup ec2 with IPV6
- i setup the route in routing table to internet gateway
- It can be accesible from outside because there is internet gateway and I can also access internet
- I want rather this instance to be not accessible from outside but able to access internet resources so i setup EIGW and routing table to it
- I can send requests but nobody can access my ports - for example
How now VPC knows that traffic to my IPV6 instance should be blocked? I still have my internet gateway. I have only setup routing table for outbound (EIGW).
I have set up a EIGW but I still have global IPV6 address which theoretically is still accessible?
Imagine IPV4 and NAT GATEWAY, I can access but I have a private IP, so my instance isn’t for example pingable from outside, with IPV6 I have something similar to NAT gateway, but still have IPV6 global address which should be routable.
Okay, but the routing table isn’t only for outbound traffic? Can for example internet gateway receive traffic to my ec2, forward, and my ec2 can respond through EIGW? Maybe I understand routing table wrong? If route table doesn’t have an entry for IP it can’t both send traffic and receive or only cant send?
If your EC2 is on a subnet that can receive Internet traffic, then it’s using IGW.
You can just route your outbound traffic from the EC2 through the same IGW, why do you need another EIGW?
If say you have 2 different EC2, one that is accessible from Internet, and one does not, then you would put them in 2 different subnet.
So, I specify to which gateway send traffic with route table, but how specify which gateway will be used for initiating connection from outside for specific IP or subnet? When I set 0.0.0.0/0 to specific internet gateway all traffic will go to internet through it, excluding my subnets. But how traffic on port 80 to my IPV6 instance will know which gateway to use?
Ok, i have attached ec2 to EIGW, but it has global IP, why cant be accessed? I route traffic to EIGW but this is for outband, why it knows to block incoming traffic to my ec2? How it is specified? I set up traffic for outband, to internet, so how this know to block connection from outside? My outband traffic is EIGW, so how it knows that incoming connection initiated from internet should be routed to EIGW and be blocked? I know that responds to my requests arent blocked, but how are blocked requests initiated from internet?
My apologies but that is still confusing as to what you are trying to ask. Let me try to break it down and see how to answer it best.
Q) How does it know that traffic should be know blocked? (it being Egress only gateway).
A) From : https://en.wikipedia.org/wiki/IP_header
>An IP header is header information at the beginning of an Internet Protocol (IP) packet. An IP packet is the smallest message entity exchanged via the Internet Protocol across an IP network. IP packets consist of a header for addressing and routing, and a payload for user data. The header contains information about IP version, source IP address, destination IP address, time-to-live, etc.
The egress only gateway will allow traffic out when its source IP is the one inside the vpc. It also maintains some state to figure out when the return data is received from that destination IP on the same protocol. If source is an IP on internet and there was no previous packet sent out - then that can be rejected.
Q) How now VPC knows that traffic to my IPV6 instance should be blocked? I still have my internet gateway. I have only setup routing table for outbound (EIGW). I have set up a EIGW but I still have global IPV6 address which theoretically is still accessible?
I still do not understand why you would have both an internet gateway to allow traffic in and out AND a separate egress only gateway. If you setup an internet gateway - your public vpc resources are accessible directly.
I think you are overcomplicating the scenario. What exactly ARE you trying to setup?
And what has all this got to do with AWS Certifications in the first place? There is no way AWS is asking you anything about these scenarios and as I tried to explain in the first reply - there is a simple either or scenario. You either want traffic in &out (use IGW) or you want only traffic going out (Egress Only GW)