A powerful CLI tool to create and manage Virtual Private Clouds (VPCs) on Linux using native networking primitives like network namespaces, veth pairs, bridges, and iptables.
VPC (Bridge) → Connects Multiple Subnets
│
├── Subnet 1 (Namespace) → veth pair → Bridge
├── Subnet 2 (Namespace) → veth pair → Bridge
└── NAT Gateway → Internet Access for Public Subnets
Each VPC is implemented as a Linux bridge, and each subnet is a network namespace connected via veth pairs.
- Linux OS with root access (or WSL2 on Windows)
- Python 3.6+
- iproute2 (
ipcommand) - iptables
WSL2 Note: This tool works on WSL2. You may see ICMP redirect messages during ping tests - these are normal and don't affect functionality.
Check requirements:
sudo python3 tests/check_requirements.pygit clone <your-repo-url>
cd vpc-cli
chmod +x vpcctl.py cleanup.sh tests/*.shsudo python3 vpcctl.py create-vpc <vpc-name> <cidr-block>Example:
sudo python3 vpcctl.py create-vpc prod-vpc 10.0.0.0/16sudo python3 vpcctl.py add-subnet <vpc-name> <subnet-name> <subnet-cidr> [--type public|private]Examples:
sudo python3 vpcctl.py add-subnet prod-vpc web-subnet 10.0.1.0/24 --type public
sudo python3 vpcctl.py add-subnet prod-vpc db-subnet 10.0.2.0/24 --type privatesudo python3 vpcctl.py enable-nat <vpc-name> [--interface eth0]Example:
sudo python3 vpcctl.py enable-nat prod-vpc --interface eth0sudo python3 vpcctl.py list-vpcssudo python3 vpcctl.py show-vpc <vpc-name>sudo python3 vpcctl.py create-peering <vpc1-name> <vpc2-name>
sudo python3 vpcctl.py delete-peering <vpc1-name> <vpc2-name>Create a firewall rules JSON file:
{
"subnet": "10.0.1.0/24",
"ingress": [
{"port": 80, "protocol": "tcp", "action": "allow"},
{"port": 443, "protocol": "tcp", "action": "allow"},
{"port": 22, "protocol": "tcp", "action": "deny"}
]
}Apply rules:
sudo python3 vpcctl.py apply-firewall <vpc-name> <rules-file.json>sudo python3 vpcctl.py exec <vpc-name> <subnet-name> "<command>"Examples:
sudo python3 vpcctl.py exec prod-vpc web-subnet "ip addr"
sudo python3 vpcctl.py exec prod-vpc web-subnet "ping -c 3 8.8.8.8"
sudo python3 vpcctl.py exec prod-vpc web-subnet "python3 -m http.server 8080"sudo python3 vpcctl.py delete-vpc <vpc-name>Run the quick demo:
sudo ./tests/demo.shDeploy a web server in a VPC:
sudo ./tests/demo_app.shThis demonstrates:
- Web server deployment (Python HTTP server on port 8080)
- Ping and curl tests to verify the server
- Internet access via NAT gateway
- Complete VPC networking setup
Run comprehensive tests:
sudo ./tests/test_vpc.shThis will test:
- VPC creation
- Subnet creation (public and private)
- NAT gateway
- Inter-subnet communication
- VPC isolation
- VPC peering
- Firewall rules
- Web server deployment and curl tests
- Internet connectivity
Clean up all VPCs and resources:
sudo ./cleanup.shvpc-cli/
├── vpcctl.py # Main CLI entry point
├── core/
│ ├── vpc.py # VPC management
│ ├── subnets.py # Subnet management
│ ├── peering.py # VPC peering
│ └── firewall.py # Firewall rules
├── utils/
│ └── network_utils.py # Low-level networking
├── tests/
│ ├── test_vpc.sh # Comprehensive tests
│ ├── demo.sh # Quick demo
│ ├── demo_app.sh # Web server deployment demo
│ └── check_requirements.py
├── config/
│ └── firewall_rules.json
├── cleanup.sh
└── README.md
- Creates a Linux bridge (acts as VPC router)
- Brings up the bridge interface
- Saves VPC configuration to
/tmp/vpc_config/
- Creates a network namespace (isolated network)
- Creates a veth pair (virtual ethernet cable)
- Connects one end to the bridge
- Moves other end into the namespace
- Assigns IP addresses
- Sets up routing
- Enables IP forwarding on host
- Adds MASQUERADE rule for outbound traffic
- Adds FORWARD rules for bi-directional traffic
- Creates veth pair between VPC bridges
- Adds static routes for cross-VPC communication
- Enables selective inter-VPC connectivity
- Applies iptables rules within namespaces
- Controls ingress/egress traffic
- Port and protocol-based filtering
sudo python3 vpcctl.py exec vpc-test public-subnet "ping -c 3 10.0.2.2"sudo python3 vpcctl.py exec vpc-test public-subnet "ping -c 3 8.8.8.8"
sudo python3 vpcctl.py exec vpc-test private-subnet "ping -c 3 8.8.8.8"sudo python3 vpcctl.py create-vpc vpc1 10.0.0.0/16
sudo python3 vpcctl.py create-vpc vpc2 10.1.0.0/16
sudo python3 vpcctl.py exec vpc1 subnet1 "ping -c 3 10.1.1.2"sudo python3 vpcctl.py create-peering vpc1 vpc2
sudo python3 vpcctl.py exec vpc1 subnet1 "ping -c 3 10.1.1.2"sudo python3 vpcctl.py list-vpcsip link show | grep br-ip netns listsudo ip netns exec ns-<vpc>-<subnet> ip routesudo iptables -t nat -L -n -v
sudo iptables -L FORWARD -n -vsudo python3 vpcctl.py -v <command>