This topic describes how to create a virtual private cloud (VPC) with an IPv4 CIDR block and associate an elastic IP address (EIP) with an Elastic Compute Service (ECS) instance in the VPC to access the Internet.
Example
A company is migrating its business to the cloud and plans to enable IPv4 services hosted in its VPC to access the Internet. The structure is illustrated in the following figure:
Before you deploy cloud resources in a VPC, you must plan the CIDR blocks. For more information, see Plan networks.
Procedure
You can create a VPC with an IPv4 CIDR block in the Resource Orchestration Service (ROS) console or in the VPC console.
Option 1: ROS console
Click Create Stack to go to the ROS console. You are automatically redirected to the Create Stack page.
Set the parameters based on the instructions and click Create.
If the status on the Stack Information changes from Creating to Created, the VPC is created.
Click the Output tab to view information about the VPC, EIP, and ECS instances.
Option 2: VPC console (manually)
Step 1: Create a VPC and vSwitches
Log on to the VPC console.
In the top navigation bar, select the region where the VPC is deployed.
The VPC and the cloud resources that you want to deploy must belong to the same region. China (Qingdao) is selected in this example.
On the VPCs page, click Create VPC.
On the Create VPC page, set the following parameters and click OK.
Only parameters that are closely related to this topic are listed below, while others are kept at their default values. For more information about parameters, see Create and manage a VPC.
VPC:
IPv4 CIDR Block: Select Manually enter an IPv4 CIDR block or IPv4 CIDR block allocated by IPAM.
Enter an IPv4 CIDR Block: Enter a primary IPv4 CIDR block for the VPC. You can refer to Suggestions on CIDR Block Configurations. After a VPC is created, modification of the IPv4 CIDR block is not allowed. But you can Add a secondary CIDR block.
NoteIn scenarios where multiple VPCs are used or in hybrid cloud scenarios where data centers and VPCs are used, we recommend that you use subsets of standard RFC CIDR blocks as VPC CIDR blocks with subnet masks no more than 16 bits in length. Make sure that the CIDR blocks do not overlap between VPCs and between VPCs and data centers.
IPv6 CIDR Block: Do Not Assign is chosen in this case, as this topic is a quick guide on how to set up a VPC with an IPv4 CIDR block.
vSwitch:
Zone: The supported cloud resources vary based on the zone and the created time. The instances provided in this topic are for reference only. The actual instances on the buy page shall prevail.
IPv4 CIDR Block: Configure the IPv4 CIDR blocks based on Suggestions on CIDR Block Configuration. After a vSwitch is created, you cannot modify its CIDR block.
NoteIf a vSwitch is required to communicate with vSwitches in other VPCs or with data centers, make sure that the CIDR block of the vSwitch does not overlap with the destination CIDR blocks.
If you need to create multiple vSwitches for the VPC, click Add below the vSwitch section and set the parameters.
Step 2: Create an ECS instance in the VPC
In the left-side navigation pane, click vSwitch. In the top navigation bar, select the region where the vSwitch is deployed. In this example, China (Qingdao) is selected.
On the vSwitch page, find the vSwitch that you want to manage, and choose in the Actions column.
On the Custom Launch tab, set the following parameters based on Create an instance by using the wizard:
Region and Zone: Select a region and a zone.
Public IP Address: Clear the check box.
Security Group: Use the default security group.
Click Create Order and complete the payment. Log on to the ECS console. You can view the ECS instance on the Instances page.
Step 3: Create an EIP and associate the EIP with the ECS instance
An EIP is a public IP address that you can purchase and use as an independent resource. You can associate an EIP with an ECS instance in a VPC to enable the ECS instance to access the Internet.
- Log on to the Elastic IP Address console .
In the top navigation bar, select the region where you want to create the EIP. In this example, China (Qingdao) is selected.
On the Elastic IP Addresses page, click Create EIP. Configure EIP and complete purchase.
On the Elastic IP Addresses page, find the EIP and click Associate with Resource in the Actions column. Set the following parameters and click OK.
Instance Type: Select ECS Instance.
Select an instance to associate: Select the ECS instance that you created in Step 2.
Test the network connectivity
Log on to the ECS instance. For more information, see Connection methods.
Run the
ping
command to test the connectivity between the ECS instance and the Internet.The test result shows that the ECS instance can communicate with the Internet.