AWS: What does 0.0.0.0/0 and ::/0 mean? - amazon-web-services

In security group, every inbound port I add, two rules are added, one for 0.0.0.0/0, the other ::/0. What do they each mean?

The default route in Internet Protocol Version 4 (IPv4) is designated
as the zero-address 0.0.0.0/0 in CIDR notation, often called the
quad-zero route. The subnet mask is given as /0, which effectively
specifies all networks, and is the shortest match possible.
The other would be for IPv6
Source Default Route
AWS Documentation
Security Groups for Your VPC
A security group acts as a virtual firewall for your instance to
control inbound and outbound traffic. When you launch an instance in a
VPC, you can assign the instance to up to five security groups.
Security groups act at the instance level, not the subnet level.
Therefore, each instance in a subnet in your VPC could be assigned to
a different set of security groups. If you don't specify a particular
group at launch time, the instance is automatically assigned to the
default security group for the VPC.
For each security group, you add rules that control the inbound
traffic to instances, and a separate set of rules that control the
outbound traffic.
Default Security Group for Your VPC
Your VPC automatically comes with a default security group. Each EC2
instance that you launch in your VPC is automatically associated with
the default security group if you don't specify a different security
group when you launch the instance.
The following table describes the default rules for a default security
group.
Inbound
Source The security group ID (sg-xxxxxxxx)
Protocol All
Port Range All
Comments Allow inbound traffic from instances assigned to the same security group.
Outbound
Destination 0.0.0.0/0
Protocol All
Port Range All
Comments Allow all outbound IPv4 traffic.
Destination ::/0
Protocol All
Port Range All
Comments Allow all outbound IPv6 traffic. This rule is added by default if you create a VPC with an IPv6 CIDR block or if you associate an IPv6 CIDR block with your existing VPC.
Recommended Network ACL Rules for Your VPC

0.0.0.0/0,::/0 - Means source can be any ip address, means from any system request is accepted, 0.0.0.0/0 represents ipv4 and ::/0 represents ipv6. To know CIDR (Classless Inter-Domain Routing) representation see this video - https://www.youtube.com/watch?v=1xsmbe5s6j0

0.0.0.0/0 refers to all IPv4 addresses and ::/0 refers All IPv6 addresses.

0.0.0.0 means that any IP either from a local system or from anywhere on the internet can access.
It is everything else other than what is already specified in routing table.
When we add /0 is for the IPv4 whereas ::/0 is for IPv6 is known as CIDR
Coming back to your AWS part, when you define 0.0.0.0/0 or ::/0 that means all the IPv4 and IPv6 ranges respectively can access your AWS service(s).
Ranges for IPv4 is from 0.0.0.0 to 255.255.255.255 where as IPv6 have 2^128 addresses.

An IP address is built by 32 bits, the slash tells you how many bits are used to identify the network section, the rest of the bits are used for the host. For example, 255.0.0.0/8 tells you 8 bits are for the network and 24 are for the host, so you migth have 16777214 possible IPs comming from that 255 network.
In case of the notation 0.0.0.0/0, it means you dont use any identifier for the network, therefore you have the whole 32 bits for the IP, meanining ALL possible IPs, which means all requests are allowed.

Related

How to whitelist IPv6 in AWS Security Group?

My public IP is in IPv6 format.
I want to whitelist it in the security group inbound rule.I added it as usual like this :
But it doesn't work for some reason. I tried converting it to IPv4 and added that but still cannot access. What am I doing wrong please help.
Is your VPC setup to use IPv6 and does the subnet your instance resides in have an IPv6 range attached to it?
You will also need to ensure your VPC has a route in the route table of your instance to allow ::/0 outbound for the internet (over an internet gateway as your instance is public).
Assuming all of these exist use DIG against the hostname you are connecting to, to validate it has an AAAA record to allow the domain to resolve for IPv6 addresses.
Here is some more information about setting up IPv6 for your VPC.
For IPV6 to be whitelisted and accessed anywhere for specific port just enter ::/0 in the source field.
for exmple:
for opening Porte 80
port: 80 Source:0.0.0.0/0 (for ipv4)
port: 80 Source: ::/0 (for ipv6)

Confused about SSH into private EC2 instance from a public EC2 instance

I have two separate NACLs, one for my public subnet and one for my private subnet. I am able to SSH into my public EC2 instance but not able to SSH into the private one without adding an outbound rule for my private NACL that allows ALL TCP to be open. What I'm confused about is why SSH fails if I only specify port 22 to be open on my private NACL outbound and inbound rule.
NACLs are stateless and need both inbound and outbound rules to allow a specific type of communication.For example ,if you want to access an ec2 instance on using ssh (tcp port 22) ,then in the inbound direction you will need to allow tcp port 22 and for the outbound direction ,since the destination port can be anything in the range 1024-65535 (depending on the client os),you will need to have such kind of rule for the ssh access.
Inbound
Rule # Type Protocol Port Range Source Allow/Deny
101 SSH TCP 22 (CLIENT IP or 0.0.0.0/0) Allow
Outbound
Rule # Type Protocol Port Range Destination Allow/Deny
101 Custom TCP TCP 1024-65535 (CLIENT IP or 0.0.0.0/0) Allow
ref:https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html#custom-network-acl
Now specifically to your setup,rules need to be created depending on how you are trying to access your ec2 instance in the private subnet.If you are using a bastion host to connect to your ec2 instance in private subnet ,then you will need to allow that ip/port in the outbound nacl rule .If you are using VPN then the rules will need to be changed accordingly.Perhaps more details about the nacl rule in your public and private subnet and how you are accessing the instances should help us provide more details on the problem.
As a general rule, you should never modify NACLs. They can be used for specific purposes (such as creating a DMZ), but there is rarely a need to change them from their default "Allow All" settings.
Instead, you should be using Security Groups to manage network permissions.
The typical configuration for your scenario would be:
On the Public (Bastion) instance, add a Security Group (Bastion-SG) that permits Inbound connections on port 22 (SSH) from your IP address (it is a good idea to restrict such access to the smallest possible range of IP addresses to prevent unauthorized access)
On the Private instance, add a Security Group (Private-SG) that permits Inbound connections on port 22 from Bastion-SG
This way, the Private-SG specifically references Bastion-SG, which will allow connections from the Bastion. Access attempts from any other location will be denied.
Security Groups are stateful, which means that return traffic will be permitted. This works well with SSH, which could use a range of different port numbers for return traffic.

How do I make my security group accessible only to my IP address?

I have an EC2 instance for running RServer. I've set up my security group, but AWS sent me a warning saying that my EC2 instance is accessible to anyone in the world.
This is my setup.
I have a VPC with IPv4 CIDR 10.0.0.0/16.
I have two subnets, each in a different availability zone. They are both associated with the VPC.
They both have these same rules.
They are both connected with the same internet gateway, which is also attached to the VPC.
For route tables, they both have 10.0.0.0/16 with target local.
They also have a connection with another route table. Each of them connects with a different route table.
The first connects with route table A, which has two routes. It has 10.0.0.0/16 local active Propagated: No and 0.0.0.0/0 active Propagated: No. The second route is connected with the same internet gateway as the VPC.
The second subnet connects with route table B, which has the same routes as route table A.
I also have a security group. It is associated with the VPC. It has three inbound rules. The first one is type: SSH, Protocol: TCP, Port Range: 22 and source as my personal ip address followed by /32.
The second one is for RStudio Server and is type: Custom TCP Rule, Protocol: TCP, Port Range: 0.0.0.0/0 and the third one is also for RStudio Server and is type: Custom TCP Rule, Protocol: TCP, Port Range: ::/0.
I also have a network ACL which has default settings. It allows all inbound and outbound traffic.
I think you have typo for the RStudio IP range, which is 0.0.0.0/0, why don't restrict to limited IPs rather than global accessible? Even if it's TCP, you still need to limit the IP range
The pictures you have provided are for Network Access Control Lists (NACLs), not Security Groups. In general, you should never change the NACL configuration unless you really understand networking.
Rather, you should configure your Security Group to only permit inbound access from your IP address on the desired ports.

AWS EC2: What is difference between 0.0.0.0/0 Vs ::/0

Part of EC2 setup, in the configuration of Security Group, I am trying to add the rule for HTTP/HTTPS for allowing internet traffic. Isn't enough to add CIDR notation 0.0.0.0/0? Do we need both 0.0.0.0/0, ::/0?
:: is a shorthand for the IPv6 address of 0:0:0:0:0:0:0:0. You need it allow IPv6 communication. For more information see Getting Started with IPv6 for Amazon VPC
.

AWS network ACL: why do I need to allow outbound port 80 to be able to browse Internet?

I am very new to AWS and networking. I have been playing with network ACL. I realized that if I don't allow outbound port 443 (HTTPS) on the network ACL, I wouldn't be able to use a browser to go to https://www.google.com from within the EC2 instance in the subnet associated with this ACL.
Likewise, if I don't allow outbound port 80, I wouldn't be able to go to http://www.cnn.com.
This confused me. When I allow port 80 outbound on the ACL, am I allowing the EC2 to talk to port 80 on the CNN server, from an ephemeral port on my EC2, or am I allowing the EC2 to initiate a connection from port 80 on the EC2?
use the security groups at instance level to have security at instance level.And unlike security group, ACL is stateless and works at subnet level i.e if you want your instances to communicate over port 80(http) then you have add an inbound and outbound rule allowing port 80.
You don't have to add any rules. The default network ACL is configured to allow all traffic to flow in and out of the subnets to which it is associated. Each network ACL also includes a rule whose rule number is an asterisk. This rule ensures that if a packet doesn't match any of the other numbered rules, it's denied. You can't modify or remove this rule.
Rules allow all IPv6 traffic to flow in and out of your subnet. We also add rules whose rule numbers are an asterisk (Catch All) that ensures that a packet is denied if it doesn't match any of the other defined numbered rules.
A network ACL has separate inbound and outbound rules (Stateless), and each rule can either allow or deny traffic.
Out Bound Rules allow outbound traffic from the subnet to the Internet. In other words it is matching the traffic flow with the defined rules in the ACLs list and apply it (ALLOW/DENY).
If you have private instances that should not be accessible by public users in the internet it is best practice from security point of view to place these instances in a private subnet and use NAT instance in a public subnet and make all traffic flow goes through this NAT instance to make patch updates and get the public access.
For more information, Check Amazon Docs