<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Sehiconcept</title>
    <description>The latest articles on Forem by Sehiconcept (@sehiconcept).</description>
    <link>https://forem.com/sehiconcept</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3606317%2Fd0b51e95-b1af-4a04-a42a-b0085f9fd2d9.png</url>
      <title>Forem: Sehiconcept</title>
      <link>https://forem.com/sehiconcept</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sehiconcept"/>
    <language>en</language>
    <item>
      <title>🌐 How I Built a Cloud VPC from Scratch Using Just Linux (No Cloud!)</title>
      <dc:creator>Sehiconcept</dc:creator>
      <pubDate>Tue, 11 Nov 2025 19:27:59 +0000</pubDate>
      <link>https://forem.com/sehiconcept/how-i-built-a-cloud-vpc-from-scratch-using-just-linux-no-cloud-22pj</link>
      <guid>https://forem.com/sehiconcept/how-i-built-a-cloud-vpc-from-scratch-using-just-linux-no-cloud-22pj</guid>
      <description>&lt;p&gt;A beginner’s guide to understanding AWS VPCs by building one with ip, iptables, and network namespaces&lt;/p&gt;

&lt;p&gt;By Osasehi Iyamu - DevOps Intern, HNG Stage 4&lt;/p&gt;

&lt;p&gt;🔍 What Is a VPC?&lt;/p&gt;

&lt;p&gt;If you’ve used AWS or Azure, you’ve probably heard of a VPC - Virtual Private Cloud.&lt;/p&gt;

&lt;p&gt;It’s like a private network in the cloud where you can run servers, connect subnets, control traffic with firewalls, and give some machines internet access while keeping others isolated.&lt;/p&gt;

&lt;p&gt;But how does it actually work under the hood?&lt;/p&gt;

&lt;p&gt;I set out to find out - and built my own Linux-based VPC using only native Linux tools, no Docker, no cloud, no magic.&lt;/p&gt;

&lt;p&gt;Here’s how I did it - and how you can too.&lt;/p&gt;

&lt;p&gt;🛠️ What I Built&lt;/p&gt;

&lt;p&gt;I created a CLI tool called vpcctl that lets you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Create multiple isolated VPCs
&lt;/li&gt;
&lt;li&gt;✅ Add public and private subnets
&lt;/li&gt;
&lt;li&gt;✅ Enable NAT so public subnets can reach the internet
&lt;/li&gt;
&lt;li&gt;✅ Block traffic with firewall rules (like AWS Security Groups)
&lt;/li&gt;
&lt;li&gt;✅ Connect VPCs with peering (optional)
&lt;/li&gt;
&lt;li&gt;✅ Clean up everything cleanly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All using only:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ip netns (network namespaces)&lt;/li&gt;
&lt;li&gt;veth pairs&lt;/li&gt;
&lt;li&gt;Linux bridges&lt;/li&gt;
&lt;li&gt;iptables&lt;/li&gt;
&lt;li&gt;bash&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No third-party tools. Just pure Linux networking.&lt;/p&gt;

&lt;p&gt;🏗️ Architecture: How It Works&lt;/p&gt;

&lt;p&gt;Here’s what happens when you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt; ./vpcctl create &lt;span class="nt"&gt;--name&lt;/span&gt; prod &lt;span class="nt"&gt;--internet-interface&lt;/span&gt; eth0

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A Linux bridge (br-prod) is created → acts as the VPC router  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Two network namespaces are created:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;prod-pub → public subnet (10.10.1.0/24)&lt;/li&gt;
&lt;li&gt;prod-priv → private subnet (10.10.2.0/24)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;veth pairs connect each namespace to the bridge  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IP addresses and routes are assigned  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NAT (MASQUERADE) is enabled on eth0 → lets prod-pub access the internet  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Firewall rules are applied from firewall.json:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="nl"&gt;"vpc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"prod"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"subnet_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"public"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"ingress"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"port"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"protocol"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tcp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"allow"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"port"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"protocol"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tcp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"deny"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;

 &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, prod-pub can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Reach the internet (&lt;code&gt;curl ifconfig.me&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;✅ Be reached on port 8000 (e.g., a web server)&lt;/li&gt;
&lt;li&gt;❌ Be blocked on port 22 (SSH)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And prod-priv:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Can reach prod-pub (same VPC)&lt;/li&gt;
&lt;li&gt;❌ Cannot reach the internet&lt;/li&gt;
&lt;li&gt;❌ Cannot reach any other VPC (like &lt;code&gt;dev&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🧪 Testing It Out&lt;/p&gt;

&lt;p&gt;✅ 1. Deploy a Web Server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#Start a simple server in the public subnet&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;ip netns &lt;span class="nb"&gt;exec &lt;/span&gt;prod-pub python3 &lt;span class="nt"&gt;-m&lt;/span&gt; http.server 8000 &lt;span class="nt"&gt;--bind&lt;/span&gt; 0.0.0.0&lt;span class="sb"&gt;``&lt;/span&gt;

✅ 2. Access It from Private Subnet &lt;span class="o"&gt;(&lt;/span&gt;Same VPC&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
bash&lt;br&gt;
sudo ip netns exec prod-priv curl -s &lt;a href="http://10.10.1.2:8000" rel="noopener noreferrer"&gt;http://10.10.1.2:8000&lt;/a&gt; | head -1&lt;/p&gt;

&lt;h1&gt;
  
  
  Output: Directory listing for /...
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✅ Works! Subnets inside the same VPC can talk.

❌ 3. Block SSH (Firewall Test)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
bash&lt;br&gt;
sudo ip netns exec prod-priv nc -zv 10.10.1.2 22&lt;/p&gt;

&lt;h1&gt;
  
  
  Output: nc: connect to 10.10.1.2 port 22 (tcp) failed: Connection timed out
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✅Firewall blocked it!

❌ 4. Try from Another VPC (Isolation)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
bash&lt;br&gt;
sudo ./vpcctl create --name dev --internet-interface eth0&lt;br&gt;
sudo ip netns exec dev-pub curl -s &lt;a href="http://10.10.1.2:8000" rel="noopener noreferrer"&gt;http://10.10.1.2:8000&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Output: (no response - timeout)
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✅ Isolation works! Different VPCs can’t talk - unless you peer them.

✅ 5. Internet Access from Public Subnet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
bash&lt;br&gt;
sudo ip netns exec prod-pub curl -s ifconfig.me&lt;/p&gt;

&lt;h1&gt;
  
  
  Output: 102.89.85.251 (your public IP!)
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✅ NAT is working!

 ✅ 6. Cleanup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
bash&lt;br&gt;
sudo ./vpcctl delete --name prod&lt;br&gt;
sudo ./vpcctl delete --name dev&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

✅ All namespaces, bridges, iptables rules - one. No leftovers.

 🧠 Why This Matters
This isn’t just a fun project - it’s real DevOps knowledge.
- AWS VPCs use exactly these same primitives under the hood.
- Kubernetes CNI plugins? Same idea.
- Understanding this makes you a better cloud engineer.

You don’t need to know Terraform to understand networking.  
You just need to understand Linux.

📁 GitHub Repo
Check out the full code: https://github.com/Sehiconcept/hng-stage4-devops-vpc
Includes:
- vpcctl - the CLI tool
- firewall.json - security group rules
- README.md - usage guide

💡 Final Thoughts
Stage 4 of HNG’s DevOps track forced me to think like a cloud provider.

I didn’t just learn commands - I learned how the internet is built, one namespace, one bridge, one iptables rule at a time.

If you’re a junior DevOps engineer don’t skip the basics.  



Build your own VPC.  
You’ll be amazed at what you learn.

🙌 Thanks to HNG for this incredible challenge.  
👋 You got this, cool keeds!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>devops</category>
      <category>linux</category>
      <category>vpc</category>
      <category>hng</category>
    </item>
  </channel>
</rss>
