# 🔹 AWS VPC and Subnets?

* AWS VPC stands for Virtual Private Cloud.
    
* AWS provides a high-performance and low-latency network.
    
* We can type in VPC in Amazon Console to view the VPCs, subnets and gateways if needed.
    
* An AWS resource such as an EC2 instance can be launched within a VPC. We can browse the Network settings to select the appropriate VPC.
    

## 🔹 **What Is A Subnet?**

A subnet is essentially a range of IP (v4 and v6) addresses.

We can assign IP addresses to resources within our VPC. These resources can be EC2 instances, NAT gateways, NLBs etc.

A subnet must live within a single Availability Zone. A region in AWS has multiple availability zones. A VPC spans all availability zones in a region. An availability zone can have multiple subnets.

Each subnet is assigned a route table. This table is a set of rules that specify the allowed routes for outbound traffic. Each subnet can be assigned with only one route table.

A subnet can be a public, private or VPN-only subnet. The default VPC contains a public subnet.

## 🔹 **Public Subnet**

A subnet that can access the Internet is a public subnet. It is the subnet that has a route table entry that points to an internet gateway. Resources that are required to face or receive Internet traffic can be added to a public subnet.

## 🔹 **Private Subnet**

A subnet that cannot access the Internet is a private subnet. It is the subnet that does not have a route table entry that points to an internet gateway. Resources that are not required to be publicly available are within a private subnet.

## 🔹 **VPC only Subnet**

There is also a VPN-only subnet that is subnet where the traffic is routed to a Site-to-Site VPN connection through a virtual private gateway.

# 🔹 **What Is Gateway?**

A gateway essentially connects a VPC to another network. For instance, if we want to connect a VPC to the internet then we will use an Internet Gateway. The default VPC includes an internet gateway by default.

The default VPC has a public subnet in each availability zone along with an internet gateway.

VPC peering can also be used to route traffic between two private VPCs.

## 🔹 **NAT gateway**

A NAT gateway is an AWS-managed service.

It enables resources within a private subnet such as an EC2 instance to access the internet. Hence it allows resources to send outbound traffic to the internet.

# 🔹 **What Are Route Tables?**

Route tables are essentially a set of rules. These rules help us determine where to direct the network traffic from a subnet or gateway. We can assign a specific route table to a subnet.

A route table has a destination that is essentially the range of IP addresses where we want the traffic to go and a target that is the gateway or a network interface or a connection through which to send the traffic.

The route table will specify a range of destinations and target IP addresses.

A route table can also be assigned to a gateway such as an internet or virtual private gateway. The route table can help us control the traffic entering the VPC.

Demo:-

1. first create VPC , i.e public
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688358985425/74d33708-b0d5-4912-849f-ad57dc9f9e7a.png align="center")
    
    1. Create Subnet:- And select VPC which you have created..
        
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688359097170/0dcfe13d-abf9-4e4a-bb41-99435f650fc6.png align="center")
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688359245657/d2cc5b2a-672d-4fca-99e9-5552465a6952.png align="center")

1. Create Internet gateway and attached to VPC
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688359463740/86513858-84bc-45a8-a4e2-0d79b6547c2a.png align="center")
    
2. Go to route table , edit it and select internet gateway..
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688360526882/27553c12-280b-4d9c-8d39-a90dca07ca57.png align="center")
    
3. Create one ec2 instance with t2 micro , going to test whether internet is working or not..
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688360988741/73c91725-d35a-49c8-8619-a2578c560437.png align="center")

1. ec2 instance is created
    
2. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688361075580/78e091ac-670f-47fb-b452-5e2fd1d92874.png align="center")
    
    Internet is working , when we ping 8.8.8.8
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1688362667825/5a92d617-025a-4d5d-8e63-2d2e4eae7ca2.png align="center")

I hope this helps! Let me know if you have any questions.

I am Vimal kumar, Please do follow me here and support #devOps #trainwithshubham #github #devopscommunity #devops #cloud #devoparticles #docker #kubernetes #aws

@[Vimal Kumar](@vimal658)

@[Shubham Londhe](@TrainWithShubham)
