In this video, we're going to explore subnets and routing in your VPC.
A subnet is a range of IP addresses that you can use inside your
VPC.
It is a subset or a slice of your
overall VPC address range. If you recall the default
VPC in AWS was a slash 16. This
means you can partition the 65,534 available
addresses into multiple subnets. This
is called subnetting each subnet must
live within one availability Zone in AZ
as it's more commonly called. It's just
an isolated location inside a region like Eastern United
States. Multiple. AZ are
used for availability.
Route tables contain rules which AWS calls
routes. They govern where your network traffic
will go this traffic can either be from subnets or
from gateways a rule consists of a destination
and a target a destination is usually an IP
address or a range while the target is where the traffic is
being sent.
Route tables will have subnets associated with them to govern where
Network packets can be sent.
Okay. So for this video what we
plan to do is we're gonna review subnets and
Route table components inside the AWS console like with
vpcs. You will learn where to find the resources
and review some of the attributes associated with them.
After that, we will head back over to a terminal and
explore your subnet and Route terraform files. Okay,
let's get started.
Okay. So here we are back in the AWS console
and we're gonna go back up to VPC
since routing and subnets are
both a part of the VPC umbrella. So I'll just click on recently
visited here. I'm gonna go to VPC.
Okay. So the first thing we want to do is we're going
to click on subnets. We'll talk about subnets first then route tables.
So click on subnets as you see here this four subnets
that come up here. These are the four default subnets that you
will get assigned when you create your account. The reason why
this 4 is because we're in the US West two region, you can see up
here with it's as organ and there are
four availability zones a b c
and d and so this is by Design because
obviously you don't want all your workloads in one subnet because
if Amazon lost one of these availability zones then
anything you have running in that availability zone is pretty
much gone as well. So you want to spread your
workload amongst all the subnets as you possibly can.
So if we look here the biggest thing one of the
large things to take away from here is you can see the ipv4 cider
range column right here as you can
see over here in The ipv4 Cider column here that these
all for these subnets have different IP
address ranges when they're where they're also
denoted by the slash 20 slash 20 means
around 4,000 IP addresses. So Amazon when they created
this Force basically took our 65,000 plus addresses
and they carved out about 16,000 of
those here.
And as you can see, if you scroll over here to the right, you
can see that those 4,091 IP addresses and you
the availability zones I was talking about.
And the route tables are associated with this network
ACLS. We're not going to talk about that here.
But ACLS are just like what you think they're Access Control.
This is allowing deny rules, and these
are default subnet.
So let's go back over here to the top and let's go
ahead and drill down on one of these subnets to get a little bit more
details. I'll just pick this second one from the top.
I mean move this up here. So it's easier to
see.
Okay.
So here we can see now we have the top. We have
our details pane like we normally saw like
in VPC and we'll see that is in other ones we go.
You have these top tabs up here details flow
logs route table ACLS cider
reservations sharing and then tags. We're only
going to talk about the details and the route table here before
we move on to the right tables. It's only
thing really pertinent as as we get into this. So here
we have our subnet ID subnet
Dash and then the character set afterwards, which
is very common as you see we talked about the available IP
addresses.
This one I picked happens to be in the US
West to see availability Zone.
And as you can see this one, this IP address
range is the 172 31 0.0 slash
20.
And here where you can see we're Associated to this
VPC. This is the same default VPC. We learned about
earlier.
And as you see it is a route table associated with this is also the
default route table that was created for us too. So that
is about all I'll go ahead and click on
Route table actually just to show you that you see that
and then there's the routes that are associated with this route table,
but let's go ahead and go over to the
route table first to view this more. So that's really
it for subnets for right now. Let's go ahead
and click on Route tables here to your left and the pain
Go ahead and click on that.
Since we had that subnet already highlighted when we come over
here, it's already checked the route table for us. There's only
one route table. If I uncheck this you can see there's only one at the
top here. You can see that we have
a orange button up here
that this is the wizard that you can use to create your
own route table over here this actions and this
is where you can do.
You can do editing or you can do deletion of whatever route
table you have selected.
Since we are using the command line and infrastructure's
code tool called terraform to do this. We aren't
going to be using the AWS console Wizards
to do these but I wanted to show you as we go through each
of these resources that there is a way to
create them through the AWS console.
All right. So let's move this route table pane up
so we can see a little more as you can see here. We got the details card
that you're used to seeing and
then the top tabs up here. You have details
route subnet Association edges route propagation
and tags. We're only gonna Focus
here on these first three tabs the details
routes and subnet associations for this.
So let's go look on details not much going
on here except that you have the ID which is rtb -
the character set they used to seeing
You can see this is associated with the the default
VPC that Amazon created for
us. So let's go over and click over on routes.
Okay, so here's the routes and if you remember what we talked about earlier,
there's a destination and a Target and here we have two
of them. So our first destination is saying the
0.0.0.0 / 0 which basically
means anywhere any IP address?
If Network packet as destined for
any IP address.
Send it to our internet gateway and we're
gonna get into it in a Gateway in later video. So I won't go into great
detail, but here just to know that in a Gateway allows our Linux
instance to connect to the internet. The second route here
is the 1723100/16.
And if you recall that is basically the whole IP address
range of our default VPC.
So what this route is saying to send that to Target with
this basically means is that any network packet inside
an ec2 instance for example, and it's
destined for another IP address inside the
IP address range.
Then instead of routing that packet anywhere else. This local
route is just saying keep it local in between
these instances in this route table.
Obviously, that's it more efficient than trying to send
it all the way back out and come back in.
Okay, so let's click on subnet associations.
So here we have explicit subnet Association and
you can see it's empty even though we looked at the subnet it
said that it was associated with this route and that is because every
VPC must have a default route and what
it is is kind of like the fall through so if you create subnets
and you don't assign it to any route table, then they
will automatically by default use this
the default route table to to manage packets.
So by declaration these subnets weren't explicitly set.
So they just automatically get this route table. And if
you come down here scroll down to this other card you have
subnets without explicit expectation. And this is kind of like the pool of
subnets that you could apply to add dissociation.
And if you come up here, you can click either
one of these edit subnet associations, and then
this will allow you to assign subnets to this route table.
We are obviously not going to do this for the default set because when
we go to create our lab, we're gonna create our own VPC our own
route table and our own subnet and we're gonna assign that
subnet to our own route table, which you'll see
a little bit more when we get into the terraform file.
All right. Well that pretty much covers what we
wanted to talk about here in the AWS console for subnets
and Route tables. So next what we'll
do let's go jump over into the terminal and then let's look
at these files these terraform files and what they
look like and how they're going to create these resources for us.
Okay. So here we are back in the terminal and the
first file we're gonna look at is subnet and
so it is subnet dot TF.
So open that in your favorite editor.
What we're looking at here is what's going to become a staple. Every
time we open these files is the same kind of layout you
see the resource declaration. You
see what type of library or
what it we're going to use in this case. What type
of resource and this is the AWS subnet.
And then we named the resource. We name it lab subnet
public one. And the reason why we named it this resource
that is because we wanted to kind of match what the actual
name of the subnets gonna be and this is only just
for pure preference. You could yeah, I could
have name this food or Johnny if I wanted to
and it wouldn't mattered, but I'd like
to keep them consistent. So it's easy to follow.
Here on line 2 we go ahead and we set
the VPC ID. Obviously terraform doesn't
know that yet. It doesn't know until the Tariff until the
VPC is created. There's an order of operations here that
terraform works out for us. So that will be
converted and calculated time here online
three, we set a cider block. And so
this cider block here is where if
you remember the the VPC we're doing the new VPC. Is
it 10.0.0.0 slash 16 and
here we're just taking a small slice of that and
we're saying the 10.0.1 zero, so
that means any instance that we bring up the subnet
is going to get a 10.0.1 address slash
24 just means we will
only gonna do is 255 hosts that is perfectly
fine for a like a lab subnet
where obviously we're not gonna create more than
255 hosts for this in course
online for
you can see here with map public IP and launch. So this basically says
any ec2 instance that ask for a public IP
address. It's okay to go ahead and assign them one.
Here we're using availability Zone online five. We're just
setting what the availability Zone and here we're doing the string interpolation
where we're saying in this variable.
For the variable of AWS region, which happens to
be Usos 2 were appending a sneaky little a
down here in the end. Now I'm showing you this one
way in this file and another file in a later video. I'm going to show you
another way. I'm just trying to give you I give you some variety of
what you can do here, but that that is definitely
just string interpolation way of doing it.
So line seven through nine, we set our
tags and this is where we're actually naming
the subnet. So here we're giving it a key of name
and the value is a lab subnet public
one as well. Obviously as you can tell here, we're only
creating one resource in this file. So there's only one subnet and I
did that just to keep things simple for our lab. We could
have easily created BC and D as well. And in
this case you would basically have three more copies of
lines one through 10 here with different side or
blocks and obviously a different name. But like I
said for this course, this is completely fine for one.
Okay, so let's close this file and then let's go look at our route.
All right, their route file is just route.tf.
So open that up in your editor.
Okay. So here we have two resources in this file to
discuss and one of them is gonna create the route
table and the other one is going to associate that subnet that we
just created or we're looking at creating and Associated that
with this route table.
So here line two, we got the normal declaration. We're
going to use the AWS route table resource, and
we're going to name this resource lab public
CRT and CRT. Just custom route table.
Line three, we're associating it with our lab VPC
and still, you know to declare to differentiate
between that and the default.
Here's our first route if you remember route has a destination and
a Target.
Destination is the cider block
saying zero zero zero zero and if
that comes in go ahead
and send it to our Gateway and this is the Gateway ID
that is yet to be shown or created that'll
be calculated once terraform gets run.
And then here at line lines nine through 11, you can see
that we're this is our tag our name tag, and this
is where we're actually naming the route table and here we're calling it
lab public custom route table.
The sit down the line 15 here. This is the
resource route table Association. And
then this one we're just calling it lab custom
route table Association public subnet one. I
know not extremely clever, but it does
tell you what it's doing.
And here we just we basically set a subnet
ID and a route table ID and that's all you
need to do. And then once the order of operations is
a complete where the VPC gets set up the route table and then
when the subnet is created.
The this resource this Association will then
be created after that. Once the boat has the route table ID
and a subnet ID.
Okay.
We are done in this file. So feel free to close that and
get out.
Let's jump back over and let's do a recap on what we've
done in this video.
Okay. So in this video you learned about subnets and
its features like IP addressing cider ranges.
You also explored route tables in
a relationship with subnets. You will use both subnets and
Route tables to allow traffic in and
out of your Lennox server.
We also navigated to both resources inside
the AWS console and explored the default
subnets and Route tables at AWS created for us.
Finally, we looked at the terraform files that would create
your custom subnet and Route table and the association for
the lab.
In the next video, we will learn how to filter traffic
with security groups and connect your Linux server to
the internet via internet gateway.