DEV Community

Cover image for From Empty VPC to Working Network: Subnet, Gateway, Route Table and Firewalls
Rahimah Sulayman
Rahimah Sulayman

Posted on Edited on

From Empty VPC to Working Network: Subnet, Gateway, Route Table and Firewalls

Introduction: A hands-on walkthrough of building out an empty AWS VPC: create a subnet, attach an internet gateway, add a route, then lock things down with a security group and a network ACL.

In the previous article, I toured the default VPC and then created my own, called test. It came out as an empty shell: no subnets, no internet gateway, one route table.

This time I start filling it in. I'll create a subnet, attach an internet gateway, build a route table with a route to the internet, then add the two firewall layers: a security group and a network ACL. By the end, you'll know what each piece does and the order they go in.

Step 1: Create a subnet

A subnet is a slice of your VPC's IP range, living in one Availability Zone. Resources like EC2 instances are launched into subnets, never directly into the VPC.

For reference, here's what the default VPC gives you: three subnets, one per AZ, all in the 172.31.x.x range.

My VPC is empty, so I'll build mine by hand. Open VPC > Subnets and click Create subnet.
Subnets list showing the three default subnets, with details of one selected
Then:

  1. Select the VPC (test).
  2. Set the Subnet name to subnet1.
  3. Pick an Availability Zone. I chose eun1-az1 (eu-north-1a).
  4. Confirm the IPv4 VPC CIDR block, which is 192.168.0.0/16.
  5. Enter an IPv4 subnet CIDR block.

Testing the CIDR rule

Before entering a valid range, I tested the rule on purpose by typing 10.0.0.0/24. The console rejected it with "CIDR Address is not within CIDR Address from VPC."

Create subnet form showing the CIDR error for 10.0.0.0/24

That's the rule in action: a subnet's range must sit inside its VPC's range. My VPC is 192.168.0.0/16, so 10.0.0.0/24 can't live there. With 192.168.10.0/24, which does fit, the error clears and the console shows 256 IPs.

Click Create subnet and AWS confirms with a green banner.
Create subnet form with the corrected CIDR 192.168.10.0/24

Subnet created successfully, listed as available in the test VPC

Open the subnet and look at the details:

  • Available IPv4 addresses: 251. A /24 has 256 addresses, and AWS reserves 5 in every subnet.
  • Default subnet: No.
  • Auto-assign public IPv4 address: No. This is the key difference from the default subnets. Nothing launched here gets a public IP.

Details of subnet1 showing 251 available addresses and the Route table tab

The Route table tab shows a single route: 192.168.0.0/16 → local. Traffic can move around inside the VPC, and that's all.

The same setting can be changed later under Actions > Edit subnet settings, where you'll find the auto-assign public IPv4 address checkbox, left off for now.

Edit subnet settings page with auto-assign public IPv4 unchecked

Coming from Azure? Subnets work the same way, including the 5 reserved addresses. The one difference is that an AWS subnet is pinned to a single Availability Zone, while an Azure subnet isn't.

Step 2: Create and attach an internet gateway

A subnet can't reach the internet on its own. It needs an internet gateway (IGW), the door between your VPC and the internet.

Under Internet gateways, you'll see the default VPC's gateway, already Attached. My VPC doesn't have one yet.

Internet gateways list showing the default VPC's gateway in the Attached state

Click Create internet gateway, set the Name tag to test-gw, and create it.

Create internet gateway form with the name test-gw

new igw

The new gateway's state is Detached, and its VPC ID is empty. Creating a gateway doesn't connect it to anything.

Click Attach to a VPC (the button in the green banner), choose the test VPC and click Attach internet gateway.

Attach to VPC page with the test VPC selected

The state flips to Attached, and the VPC ID now points to test.
I selected the test vpc and clicked Attach Internet Gateway.

The test-gw internet gateway now attached to the test VPC
The state has now flipped to Attached.

attached

Here's the catch: go back to subnet1 and open its Route table tab. It's still just the local route. The subnets list now shows 4 subnets (3 default + 1 mine), but nothing about the internet has changed for subnet1.

Subnets list with 4 subnets, and subnet1's route table still showing only the local route

Attaching a gateway gives the VPC a door, but a route is what tells traffic to use it.

Coming from Azure? There's no gateway to create or attach. Azure VNets already have a default route to the internet, so outbound access works without one.

Step 3: Build a route table with a route to the internet

Open Route tables. The only one in the test VPC is the main route table (Main: Yes) that AWS created automatically. It has no explicit subnet associations, so any subnet that isn't linked to something else uses it.

Route tables list showing the main route table for the test VPC

I'd rather not edit the main table. A good habit is to leave it alone and create a custom route table for each purpose. Click Create route table, name it test-rt and pick the test VPC.

create new route table

new rtb

It's created with Main: No and just the local route.

The new test-rt route table with only the local route

Now add the route. Click Edit routes > Add route, then:

  1. Destination: 0.0.0.0/0 (meaning "everywhere else").
  2. Target: Internet Gateway, then select test-gw.
  3. Click Save changes.

Edit routes page adding 0.0.0.0/0 with the internet gateway as target

The route table now has two active routes: 0.0.0.0/0 → the internet gateway, and 192.168.0.0/16 → local.

test-rt route table updated with two routes

One thing to notice: Explicit subnet associations is still empty. test-rt exists and has a route to the internet, but no subnet is using it yet. Until a subnet is associated with it, subnet1 stays private. I'll deal with that in the next article.

network associations

Coming from Azure? An AWS route table is the equivalent of an Azure route table with user-defined routes (UDRs).

Step 4: Create a security group

Now the firewalls. A security group acts as a firewall at the resource level (an instance, for example), and it's stateful: if a request is allowed in, the reply is allowed out automatically.

Under Security groups, you'll see one default group per VPC. Mine lists two, one for the default VPC and one for test.

Security groups list showing one default group per VPC

Click Create security group and fill in:

  • Name: tutorial-sg
  • Description: for tutorial purposes
  • VPC: test

creating sg

Security groups start with no inbound rules, so nothing can reach your resources until you allow it. For the outbound rules, I set HTTPS (443) to Anywhere-IPv4 (0.0.0.0/0). The console warns that a 0.0.0.0/0 destination allows traffic to any address, and it recommends being more restrictive where you can.

Once it's created, the details show 0 inbound rules and 1 outbound rule.

tutorial-sg created with zero inbound permission entries

Step 5: Create a network ACL

A network ACL (NACL) is the second layer of firewall, working at the subnet level. Unlike a security group, it's stateless, so return traffic needs its own rule.

Under Network ACLs, there are two default ones: one for the default VPC (3 subnets) and one for test, already associated with subnet1. Each default NACL has 2 inbound and 2 outbound rules.

Click Create network ACL, name it tutorial-acl and select the test VPC.

Create network ACL form with the name tutorial-acl

creating NACL

In the list, the new one shows Default: No, no associated subnets and 1 inbound rule.

Network ACLs list now showing tutorial-acl as a non-default NACL

Open it. That one inbound rule is the catch-all * that denies all traffic.

tutorial-acl inbound rules with a single deny-all rule

This is the opposite of the default NACL, which allows everything. A custom NACL denies everything until you allow it, in both directions.

Let's add an allow rule. Click Edit inbound rules > Add new rule.

edit
I set:

  • Rule number: 100
  • Type: SSH (22), which fills in TCP and port 22
  • Source: 0.0.0.0/0
  • Allow/Deny: Allow

Edit inbound rules with rule 100 allowing SSH from anywhere

After saving, the NACL has two inbound rules: 100 allows SSH, and * denies the rest. Rules are evaluated from the lowest number up, so the allow is checked first.

tutorial-acl inbound rules updated with the SSH allow rule

Because NACLs are stateless, this isn't the whole story. The replies to SSH leave through the outbound rules, which are still deny-all on a new NACL. A working setup needs a matching outbound rule for the return traffic.

Associate it with the subnet

Creating the NACL doesn't apply it to anything. Open Actions and choose Edit subnet associations.

The Actions menu on the NACL with Edit subnet associations

Select subnet1 and save. The console shows subnet1 is currently tied to the default NACL, and a subnet can only use one NACL at a time, so this swaps it.

Edit subnet associations with subnet1 selected

The NACL's Associated with field now shows subnet1, and the Subnet associations tab lists it.

tutorial-acl associated with subnet1

Coming from Azure? Network Security Groups (NSGs) cover both roles, and they're stateful. Stateless filtering at the subnet level, as in a NACL, has no direct equivalent.

My test VPC now has a subnet, a gateway, a route to the internet, a security group and a NACL. One thing is still missing: test-rt isn't associated with subnet1, so the subnet isn't public yet.

subnet association

The tab now lists subnet1 under Explicit subnet associations (1), and Subnets without explicit associations drops to 0, meaning no subnet in the VPC is relying on the main route table any more.

subnet1 is now a public subnet, because its route table sends 0.0.0.0/0 to an internet gateway. One more thing is needed before an instance in it is reachable: a public IP. The subnet's auto-assign setting is still off, so an instance needs a public IPv4 address assigned at launch (or an Elastic IP).

Summary

  • A subnet's CIDR must sit inside the VPC's CIDR, and AWS reserves 5 addresses in each subnet.
  • A new subnet doesn't get public IPs by default. The auto-assign setting is off.
  • Creating an internet gateway isn't enough. It has to be attached to the VPC, and a route must point to it.
  • Use a custom route table instead of editing the main one, and remember that associating it with a subnet is a separate step.
  • A security group starts with no inbound rules (stateful, resource level).
  • A custom NACL starts as deny-all in both directions (stateless, subnet level), and it takes effect only once you associate it with a subnet.

Top comments (1)

Collapse
 
rahimah_dev profile image
Rahimah Sulayman •

Where do you start when a new subnet can't reach the internet: the route table, the NACL or the security group?