Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Virtual Private Cloud/ User Guide/ VPC Peering Connection/ Creating a VPC Peering Connection to Connect Two VPCs in the Same Account

Creating a VPC Peering Connection to Connect Two VPCs in the Same Account

Updated on 2025-01-24 GMT+08:00

Scenarios

Two VPCs from the same region cannot communicate with each other by default, but you can use a VPC peering connection to connect them.

The following describes how to create a VPC peering connection to connect two VPCs (vpc-A and vpc-B in this example) in the same account. In this way, instances (the service server ECS-A01 and database server RDS-B01 in this example) in the two VPCs can communicate with each other.

The procedure is as follows:

Step 1: Create a VPC Peering Connection

Step 2: Add Routes for the VPC Peering Connection

Step 3: Configure Security Group Rules for Instances in Local and Peer VPCs

Step 4: Verify Network Connectivity

Figure 1 Connecting two VPCs in an account using a VPC peering connection
NOTICE:

Currently, VPC peering connections are free.

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 to connect to one created on the Huawei Cloud International website, but the VPCs must be in the same region. For example, if the VPC created on the Chinese Mainland website is in the CN-Hong Kong region, then the VPC created on the International website must also be in the CN-Hong Kong region.
    • If you want to connect VPCs in different regions, you can use Cloud Connect.
    • If you only need a 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 be usable.

    In this case, you can configure the network by referring to VPC Peering Connection Usage Examples.

Prerequisites

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

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 Creating a VPC peering connection
    Table 1 Parameters for creating a VPC peering connection

    Parameter

    Description

    Example Value

    Region

    Mandatory

    The region where the VPC peering connection is created. Select the region nearest to you to ensure the lowest latency possible.

    CN-Hong Kong

    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

    Description (Optional)

    Optional

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

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

    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 project is selected in by default if Account is set to My account.

    In this example, vpc-A and vpc-B are created in region A, and the corresponding project of the account in region A is selected 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 be usable. For details, see VPC Peering Connection Usage Examples.

    172.17.0.0/16

  4. Click Create Now.

    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 Adding a 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)

    Destination

    An IP address or address range in the VPC being 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 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)

    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: Configure Security Group Rules for Instances in Local and Peer VPCs

When configuring security group rules to control traffic in and out of ECS-A01 and RDS-B01, you can set Template to Custom. Table 3 shows the preset security group rules.
Table 3 Preset security group rules (Custom rules)

Direction

Action

Type

Protocol & Port

Source/Destination

Description

Inbound

Allow

IPv4

All

Source: current security group

Allows the instances in the security group to communicate with each other over any IPv4 protocol and port.

Inbound

Allow

IPv6

All

Source: current security group

Allows the instances in the security group to communicate with each other over any IPv6 protocol and port.

Outbound

Allow

IPv4

All

Destination: 0.0.0.0/0

Allows all IPv4 traffic from the instances in the security group to external resources over any protocol and port.

Outbound

Allow

IPv6

All

Destination: ::/0

Allows all IPv6 traffic from the instances in the security group to external resources over any protocol and port.

As you can see, the above preset rules only allow instances in the security group to communicate with each other. To allow external traffic to access the instances in the security group, add inbound rules by referring to Adding a Security Group Rule.
  • If the instances in the local and peer VPCs are associated with the same security group, they can communicate with each other.

    For example, if ECS-A01 and RDS-B01 are associated with security group Sg-AB, you only need to perform the operations in 1 to allow remote logins.

  • If the instances in the local and peer VPCs are associated with different security groups, they cannot communicate with each other unless you add rules to allow them to.

    For example, if ECS-A01 is associated with security group Sg-A, and RDS-B01 is associated with security group Sg-B, you need to perform the operations in 1 and 2 to allow remote logins.

  1. Add security group rules in Table 4 to allow remote logins.
    Table 4 Security group rules for remote logins

    Direction

    Action

    Type

    Protocol & Port

    Source

    Description

    Inbound

    Allow

    IPv4

    TCP: 22

    IP address: 0.0.0.0/0

    Allows any IPv4 address to remotely log in to the Linux instances in Sg-AB over SSH port 22.

    Inbound

    Allow

    IPv4

    TCP: 3389

    IP address: 0.0.0.0/0

    Allows any IPv4 address to remotely log in to the Windows instances in Sg-AB over RDP port 3389.

    NOTICE:

    If the source of an inbound rule is set to 0.0.0.0/0, all external IP addresses are allowed to remotely log in to your cloud server. Exposing port 22 or 3389 to the public network will leave your instances vulnerable to network risks. To address this issue, set the source to a trusted IP address, for example, the IP address of your local PC.

  2. (Optional) Add security rules to allow the instances in Sg-A and Sg-B to communicate with each other.
    Select either of the following solution based on your service requirements.
    • Solution 1 in Table 5: Set Source to the CIDR block of peer VPC or subnet.
      Table 5 Security group rules (CIDR block as the source)

      Security Group

      Direction

      Action

      Type

      Protocol & Port

      Source

      Description

      Sg-A

      Inbound

      Allow

      IPv4

      All

      IP address: 172.17.0.0/16 (vpc-B CIDR block)

      Allows traffic from 172.17.0.0/16 to access instances in Sg-A over any IPv4 protocol and port.

      Sg-B

      Inbound

      Allow

      IPv4

      All

      IP address: 172.16.0.0/16 (vpc-A CIDR block)

      Allows traffic from 172.16.0.0/16 to access instances in Sg-B over any IPv4 protocol and port.

    • Solution 2 in Table 6: Set Source to Sg-A and Sg-B.
      Table 6 Security group rules (security group as the source)

      Security Group

      Direction

      Action

      Type

      Protocol & Port

      Source

      Description

      Sg-A

      Inbound

      Allow

      IPv4

      All

      Sg-B

      Allows instances in Sg-B to access those in Sg-A over any IPv4 protocol and port.

      Sg-B

      Inbound

      Allow

      IPv4

      All

      Sg-A

      Allows instances in Sg-A to access those in Sg-B over any IPv4 protocol and port.

Step 4: Verify Network Connectivity

After you add routes for the VPC peering connection, verify communications 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 <peer-server-IP-address>

    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-A01 ~]# 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 ---
    NOTICE:

    In this example, ECS-A01 and RDS-B01 are in the same security group. If the instances in different security groups, you need to add inbound rules to allow access from the peer security group. For details, see Enabling Communications Between Instances in Different Security Groups.

    If VPCs connected by a VPC peering connection cannot communicate with each other, refer to Why Did Communication Fail Between VPCs That Were Connected by a VPC Peering Connection?

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback