Help Center> Virtual Private Cloud> User Guide> VPC Peering Connection> Creating a VPC Peering Connection with Another VPC in Your Account
Updated on 2024-06-13 GMT+08:00

Creating a VPC Peering Connection with Another VPC in Your Account

Scenarios

If two VPCs from the same region cannot communicate with each other, you can use a VPC peering connection. This section describes how to create a VPC peering connection between two VPCs in the same account.

This following describes how to create a VPC peering connection between VPC-A and VPC-B in account A to enable communications between ECS-A01 and RDS-B01.

Procedure:

Step 1: Create a VPC Peering Connection

Step 2: Add Routes for the VPC Peering Connection

Step 3: Verify Network Connectivity

Figure 1 Networking diagram of a VPC peering connection between VPCs in the same account

Currently, VPC peering connections are free of charge.

Notes and Constraints

  • Only one VPC peering connection can be created between two VPCs at the same time.
  • A VPC peering connection can only connect VPCs in the same region.
    • A VPC peering connection can enable a VPC created on the Huawei Cloud Chinese Mainland website and the other created on the Huawei Cloud International website to communicate, but the VPCs must be in the same region. For example, one VPC on the Chinese Mainland website is in CN-Hong Kong region, and the other VPC on the International website is also in CN-Hong Kong region.
    • If you want to connect VPCs in different regions, you can use Cloud Connect.
    • If you only need few ECSs in different regions to communicate with each other, you can assign and bind EIPs to the ECSs.
  • If the local and peer VPCs have overlapping CIDR blocks, the VPC peering connection may not take effect.

    In this case, you can refer to networking configuration examples.

Prerequisites

You have two VPCs from the same account in the same region. If you want to create one, see Creating a VPC.

Step 1: Create a VPC Peering Connection

  1. Go to the VPC peering connection list page.
  2. In the upper right corner of the page, click Create VPC Peering Connection.

    The Create VPC Peering Connection page is displayed.

  3. Configure the parameters as prompted.

    For details, see Table 1.

    Figure 2 Create VPC Peering Connection
    Table 1 Parameters for creating a VPC peering connection

    Parameter

    Description

    Example Value

    VPC Peering Connection Name

    Mandatory

    Enter a name for the VPC peering connection.

    The name can contain a maximum of 64 characters, including letters, digits, hyphens (-), and underscores (_).

    peering-AB

    Local VPC

    Mandatory

    VPC at one end of the VPC peering connection. You can select one from the drop-down list.

    VPC-A

    Local VPC CIDR Block

    CIDR block of the selected local VPC

    172.16.0.0/16

    Account

    Mandatory

    • Options: My account and Another account
    • Select My account.

    My account

    Peer Project

    The system fills in the corresponding project by default because My account is set to Account.

    For example, if VPC-A and VPC-B are in account A and region A, the system fills in the correspond project of account A in region A by default.

    ab-cdef-1

    Peer VPC

    This parameter is mandatory if Account is set to My account.

    VPC at the other end of the VPC peering connection. You can select one from the drop-down list.

    VPC-B

    Peer VPC CIDR Block

    CIDR block of the selected peer VPC

    If the local and peer VPCs have overlapping CIDR blocks, the VPC peering connection may not take effect. For details, see VPC Peering Connection Usage Examples.

    172.17.0.0/16

    Description

    Optional

    Enter the description of the VPC peering connection in the text box as required.

    peering-AB connects VPC-A and VPC-B.

  4. Click OK.

    A dialog box for adding routes is displayed.

  5. In the displayed dialog box, click Add Now. On the displayed page about the VPC peering connection details, go to Step 2: Add Routes for the VPC Peering Connection to add a route.

Step 2: Add Routes for the VPC Peering Connection

  1. In the lower part of the VPC peering connection details page, click Add Route.

    The Add Route dialog box is displayed.

    Figure 3 Add Route
  2. Add routes to the route tables as prompted.

    Table 2 describes the parameters.

    Table 2 Parameter description

    Parameter

    Description

    Example Value

    VPC

    Select a VPC that is connected by the VPC peering connection.

    VPC-A

    Route Table

    Select the route table of the VPC. The route will be added to this route table.

    Each VPC comes with a default route table to control the outbound traffic from the subnets in the VPC. In addition to the default route table, you can also create a custom route table and associate it with the subnets in the VPC. Then, the custom route table controls outbound traffic of the subnets.
    • If there is only the default route table in the drop-down list, select the default route table.
    • If there are both default and custom route tables in drop-down list, select the route table associated with the subnet connected by the VPC peering connection.

    rtb-VPC-A (Default route table)

    Destination

    An IP address or address range in the other VPC connected by the VPC peering connection. The value can be a VPC CIDR block, subnet CIDR block, or ECS IP address. For details about the route configuration example, see VPC Peering Connection Usage Examples.

    VPC-B CIDR block: 172.17.0.0/16

    Next Hop

    The default value is the current VPC peering connection. You do not need to specify this parameter.

    peering-AB

    Description

    Supplementary information about the route. This parameter is optional.

    The description can contain a maximum of 255 characters and cannot contain angle brackets (< or >).

    Route from VPC-A to VPC-B

    Add a route for the other VPC

    If you select this option, you can also add a route for the other VPC connected by the VPC peering connection.

    To enable communications between VPCs connected by a VPC peering connection, you need to add both forward and return routes to the route tables of the VPCs. For details, see VPC Peering Connection Usage Examples.

    Selected

    VPC

    By default, the system selects the other VPC connected by the VPC peering connection. You do not need to specify this parameter.

    VPC-B

    Route Table

    Select the route table of the VPC. The route will be added to this route table.

    Each VPC comes with a default route table to control the outbound traffic from the subnets in the VPC. In addition to the default route table, you can also create a custom route table and associate it with the subnets in the VPC. Then, the custom route table controls outbound traffic of the subnets.
    • If there is only the default route table in the drop-down list, select the default route table.
    • If there are both default and custom route tables in drop-down list, select the route table associated with the subnet connected by the VPC peering connection.

    rtb-VPC-B (Default route table)

    Destination

    An IP address or address range in the other VPC connected by the VPC peering connection. The value can be a VPC CIDR block, subnet CIDR block, or ECS IP address. For details about the route configuration example, see VPC Peering Connection Usage Examples.

    VPC-A CIDR block: 172.16.0.0/16

    Next Hop

    The default value is the current VPC peering connection. You do not need to specify this parameter.

    peering-AB

    Description

    Supplementary information about the route. This parameter is optional.

    The description can contain a maximum of 255 characters and cannot contain angle brackets (< or >).

    Route from VPC-B to VPC-A.

  3. Click OK.

    You can view the routes in the route list.

Step 3: Verify Network Connectivity

After you add routes for the VPC peering connection, verify the communication between the local and peer VPCs.
  1. Log in to ECS-A01 in the local VPC.

    Multiple methods are available for logging in to an ECS. For details, see Logging In to an ECS.

  2. Check whether ECS-A01 can communicate with RDS-B01.

    ping IP address of RDS-B01

    Example command:

    ping 172.17.0.21

    If information similar to the following is displayed, ECS-A01 and RDS-B01 can communicate with each other, and the VPC peering connection between VPC-A and VPC-B is successfully created.
    [root@ecs-A02 ~]# ping 172.17.0.21
    PING 172.17.0.21 (172.17.0.21) 56(84) bytes of data.
    64 bytes from 172.17.0.21: icmp_seq=1 ttl=64 time=0.849 ms
    64 bytes from 172.17.0.21: icmp_seq=2 ttl=64 time=0.455 ms
    64 bytes from 172.17.0.21: icmp_seq=3 ttl=64 time=0.385 ms
    64 bytes from 172.17.0.21: icmp_seq=4 ttl=64 time=0.372 ms
    ...
    --- 172.17.0.21 ping statistics ---