<?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: josiah favour</title>
    <description>The latest articles on Forem by josiah favour (@josiah_favour_dc7c9013995).</description>
    <link>https://forem.com/josiah_favour_dc7c9013995</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%2F3608242%2F1b437d97-584d-4c4f-b53b-17518fc11a70.png</url>
      <title>Forem: josiah favour</title>
      <link>https://forem.com/josiah_favour_dc7c9013995</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/josiah_favour_dc7c9013995"/>
    <language>en</language>
    <item>
      <title>Building Your Own Virtual Private Cloud (VPC) on Linux – A Beginner’s Guide</title>
      <dc:creator>josiah favour</dc:creator>
      <pubDate>Wed, 12 Nov 2025 16:14:51 +0000</pubDate>
      <link>https://forem.com/josiah_favour_dc7c9013995/building-your-own-virtual-private-cloud-vpc-on-linux-a-beginners-guide-2mjh</link>
      <guid>https://forem.com/josiah_favour_dc7c9013995/building-your-own-virtual-private-cloud-vpc-on-linux-a-beginners-guide-2mjh</guid>
      <description>&lt;p&gt;Imagine you own a big farm compound. On this compound, you want to organize different areas: fields, barns, and visitor areas. You want each area to have controlled access, and some areas might connect to the outside world, while others stay private. That’s exactly what a Virtual Private Cloud (VPC) does in computing: it’s a fenced-off network on your computer where you control access, routing, and connectivity.&lt;/p&gt;

&lt;p&gt;In this guide, we’ll build a mini VPC on Linux using simple tools like network namespaces, bridges, routing tables, and iptables. By the end, you’ll understand how cloud networks work under the hood and be able to deploy isolated workloads like web servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Farm Analogy: Understanding VPCs and Subnets
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Think of a VPC as a farm.&lt;br&gt;
The VPC = The farm compound&lt;br&gt;
Subnets = Sections like:&lt;br&gt;
Crop field (public, visitors allowed)&lt;br&gt;
Barn (private, staff only)&lt;br&gt;
Greenhouse (private, controlled access)&lt;br&gt;
Bridge = Main road connecting all sections&lt;br&gt;
NAT Gateway = Farm gate for sending goods out&lt;br&gt;
Peering = Controlled paths between separate farms&lt;br&gt;
Firewall rules = Security guards controlling who can enter each section&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Creating Your First VPC (Farm Compound)
&lt;/h2&gt;

&lt;p&gt;Let’s create a farm named greenfarm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl create greenfarm --cidr 10.50.0.0/16

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Creates a bridge: br-greenfarm (main road)&lt;/li&gt;
&lt;li&gt;Sets up routing and an isolated iptables chain&lt;/li&gt;
&lt;li&gt;Saves metadata for later inspection&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Adding Subnets (Farm Sections)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Public Section (Crop Field)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl add-subnet greenfarm public --cidr 10.50.1.0/24

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Creates namespace: ns-greenfarm-public&lt;/li&gt;
&lt;li&gt;Connects it to the bridge via a veth pair&lt;/li&gt;
&lt;li&gt;Assigns IP addresses and sets default route&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Private Section (Barn)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl add-subnet greenfarm private --cidr 10.50.2.0/24

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Namespace: ns-greenfarm-private&lt;/li&gt;
&lt;li&gt;No direct internet access by default&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Deploying Simple Apps (Farm Stalls)
&lt;/h2&gt;

&lt;p&gt;Deploy a small HTTP server in each section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl deploy-app greenfarm public  --port 8080
sudo vpcctl deploy-app greenfarm private --port 8081

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Apps run inside namespaces, isolated from each other&lt;/li&gt;
&lt;li&gt;Public section can serve visitors; private section stays internal&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Enabling Internet Access (NAT Gateway)
&lt;/h2&gt;

&lt;p&gt;Allow the crop field to access the internet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IFACE=$(ip route get 1.1.1.1 | awk '{print $5; exit}')
sudo vpcctl enable-nat greenfarm --interface "$IFACE"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;NAT acts like the farm gate, letting public subnets reach the internet&lt;/li&gt;
&lt;li&gt;Private subnets remain isolated&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Connecting Farms (VPC Peering)
&lt;/h2&gt;

&lt;p&gt;Suppose you have another farm, bluefarm&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl create bluefarm --cidr 10.60.0.0/16
sudo vpcctl add-subnet bluefarm public --cidr 10.60.1.0/24
sudo vpcctl deploy-app bluefarm public --port 8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To allow only public areas to communicate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl peer greenfarm bluefarm --allow-cidrs 10.50.1.0/24,10.60.1.0/24
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Bridges are connected via veth pairs&lt;/li&gt;
&lt;li&gt;Only permitted CIDRs can communicate&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Applying Security Rules (Firewall Policies)
&lt;/h2&gt;

&lt;p&gt;Example policy JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "subnet": "10.50.1.0/24",
  "ingress": [
    {"port": 80, "protocol": "tcp", "action": "allow"},
    {"port": 22, "protocol": "tcp", "action": "deny"}
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl apply-policy greenfarm policy_examples/example_policy.json

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;iptables inside namespaces enforce the rules&lt;/li&gt;
&lt;li&gt;Ensures only allowed traffic flows&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Inspecting, Listing, and Cleaning Up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;List VPCs:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Inspect VPC:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl inspect greenfarm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Delete VPC:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vpcctl delete greenfarm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cleanup removes: namespaces, bridges, veth pairs, apps, and firewall rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using vpcctl, you can simulate a complete cloud like networking environment on Linux. Think of it as managing multiple farms with roads, gates, and security guards now applied to virtual networks. This hands on approach teaches you network isolation, routing, NAT, and firewall rules—key skills for any aspiring cloud engineer.&lt;/p&gt;

</description>
      <category>networking</category>
      <category>linux</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
