Skip to content

Network / Task

Create a VPC and subnets

Updated · 3 min read

Create a VPC with the CLI, add subnets to it, and choose whether instances launched into each subnet get a public IPv4 address automatically.

On this page6 sections

Create your own VPC when you want to choose its address range or control which subnets reach the internet. A new VPC comes with a first subnet, so you add subnets only when you need more than one.

Before you begin

Creating VPCs and subnets doesn’t require a payment method.

Create the VPC

  1. Create the VPC. Pass --ipv4-cidr to choose the IPv4 range, or leave it out to get a random /16 from 172.16.0.0/12.

    terminal
    origin network create-vpc --project-urn <project-urn> \
      --ipv4-cidr 10.0.0.0/16
  2. Note the VPC’s URN from the output, and find its first subnet:

    terminal
    origin network list-subnets --project-urn <project-urn>
  3. Verify the VPC with get-vpc. Its ipv4Network shows the range and the subnet size.

    terminal
    origin network get-vpc --vpc-urn <vpc-urn>

The VPC has no Internet Gateway. To give it internet access, see Internet access.

Add a subnet

  1. Create the subnet. --auto-assign-public-ip is required: true gives every instance launched into the subnet a Floating IP automatically, false doesn’t.

    terminal
    origin network create-subnet --vpc-urn <vpc-urn> \
      --auto-assign-public-ip false

    The platform picks the subnet’s ranges from the VPC. If the VPC has no room left, the command is refused; see When address space runs out.

  2. Verify the subnet. Its ipv4Network, ipv4Router and ipv4DnsServers show its range, gateway and resolver.

    terminal
    origin network get-subnet --subnet-urn <subnet-urn>

An automatic public IP is only useful if the VPC has an Internet Gateway. For how auto-assigned addresses behave, see Default VPC.

Change a subnet’s auto-assign setting

  1. Set the new value with true or false:

    terminal
    origin network update-subnet-auto-assign-public-ip \
      --subnet-urn <subnet-urn> --auto-assign-public-ip true
  2. Verify that the subnet’s autoAssignPublicIp field shows the new value:

    terminal
    origin network get-subnet --subnet-urn <subnet-urn>

The change applies only to instances launched afterwards. To give a running instance a public address, associate a Floating IP with its interface; see Floating IPs.

Next steps