Help Center/ Cloud Firewall/ Best Practices/ Configuring a Protection Rule to Protect SNAT Traffic/ Configuring CFW Protection Rules to Protect SNAT Traffic
Updated on 2026-09-23 GMT+08:00

Configuring CFW Protection Rules to Protect SNAT Traffic

This section describes how to configure CFW protection rules to protect SNAT traffic.

Step 1: Connect VPC1 and VPC-NAT to an Enterprise Router

This section describes how to connect VPC1 and VPC-NAT to an enterprise router.

  1. Add VPC attachments.

    Add two attachments. Set their Attached Resource to VPC1 and VPC-NAT, respectively.

    For details, see Adding VPC Attachments to an Enterprise Router.

  2. Create two route tables.

    1. In the upper left corner, click and choose Networking > Enterprise Router. Click Manage Route Table.
    2. Create an association route table and a propagation route table, used for connecting to a protected VPC and a firewall, respectively.

      On the enterprise router details page, click the Route Tables tab. On the route table configuration page, click Create Route Table. In the displayed dialog box, configure parameters.

      Table 1 Route table parameters

      Parameter

      Description

      Example Value

      Name

      Route table name.

      It must meet the following requirements:
      • Must contain 1 to 64 characters.
      • Can contain letters, numbers, underscores (_), hyphens (-), and periods (.).

      er-rtb-01

      AS_Path Route Selection

      (Optional)

      • Do not configure: The system compares AS_Path attributes for the routes during load balancing and prefers the route with the shortest AS_Path length. The AS_Path attribute records all AS numbers that a BGP route passes through from the local end to the destination in the vector order. The fewer the AS numbers recorded in the AS_Path attribute, the shorter the AS_Path length.
      • Ignore same length AS_Path: The system skips comparing the AS_Path attributes during load balancing if their lengths are identical. AS_Path prevents BGP loops between ASs. If you select this option, there may be BGP loops.

      Do not configure

      Tag

      (Optional)

      During the route table creation, you can tag the route table resources. Tags identify cloud resources for purposes of easy categorization and quick search.

      For details about tags, see Tag Overview.

      Tag key: test

      Tag value: 01

      Description

      (Optional)

      Route table description.

      -

  3. Configure the association route table.

    1. Create an association between VPC1 and VPC-NAT. On the route table configuration page, click the Associations tab and click Create Association.

      Two associations need to be added. Set their Attachment to VPC1 and VPC-NAT attachments, respectively.

      Table 2 Association parameters

      Parameter

      Description

      Attachment Type

      Select VPC.

      Attachment

      Select the VPC attachment from the Attachment drop-down list.

    2. Add a static route to the firewall. Click the Routes tab and click Create Route.
      Figure 1 Creating a route
      Table 3 Route parameters

      Parameter

      Description

      Destination

      Set the destination address.

      • If 0.0.0.0/0 is configured, all the traffic (IPv4) of the VPC is protected by CFW.
      • If a CIDR block is configured, the traffic of the CIDR block is protected by CFW.

      Blackhole Route

      You are advised to disable this function. If it is enabled, the packets from a route that matches the destination address of the blackhole route will be discarded.

      Attachment Type

      Set Attachment Type to CFW instance.

      Next Hop

      Select the automatically generated firewall attachment cfw-er-auto-attach.

      Description

      (Optional) Description of a route.

  4. Configure the propagation route table.

    1. Add an association with the firewall. On the route table configuration page, click the Associations tab and click Create Association.
      Figure 2 Creating an association
      Table 4 Association parameters

      Parameter

      Description

      Attachment Type

      Set Attachment Type to CFW instance.

      Attachment

      Select the automatically generated firewall attachment cfw-er-auto-attach.

    2. Configure propagation for VPC1. Click the Propagations tab and click Create Propagation.
      Figure 3 Creating a propagation
      Table 5 Propagation parameters

      Parameter

      Description

      Attachment Type

      Select VPC.

      Attachment

      Select the VPC1 attachment from the Attachment drop-down list.

    3. Add a static route to VPC-NAT. Click the Routes tab and click Create Route.
      Table 6 Route parameters

      Parameter

      Description

      Destination

      Set it to 0.0.0.0/0.

      Blackhole Route

      You are advised to disable this function. If it is enabled, the packets from a route that matches the destination address of the blackhole route will be discarded.

      Attachment Type

      Select VPC.

      Next Hop

      Select the VPC-NAT attachment from the drop-down list.

Step 2: Configure a NAT Gateway

This section describes how to configure a NAT gateway.

Prerequisites

  • A NAT gateway has been purchased and its VPC has not been associated with any cloud resources (such as cloud servers).
  • If there are no NAT gateways available, buy a public NAT gateway. For details about NAT gateway pricing, see Billing.

If VPC-NAT is associated with the NAT gateway, a route will be added to the default route table by default. (The destination address is 0.0.0.0/0, and the Next Hop Type is NAT gateway.) This route diverts the traffic destined for VPC-NAT to the NAT gateway. Do not delete it.

Configuring a NAT Gateway

  1. Add an SNAT rule.
    1. Go to the public NAT gateway list.
    2. Click the name of a public network NAT gateway. The Basic Information tab is displayed. Click the SNAT Rules tab.
    3. Click Add SNAT Rule and configure parameters.
      Table 7 Adding an SNAT rule

      Parameter

      Description

      Scenario

      Scenario where the SNAT rule is used. Select VPC.

      CIDR Block

      Select Custom. Allow servers in the specified CIDR block to use this SNAT rule to access the Internet.

      Custom: Customize a CIDR block or enter the IP address of a VPC.

      • If you select Custom, you can enter 0.0.0.0/0.
      • Only a 32-bit server IP address is supported.

      Public IP Address Type

      Select EIP, which is an EIP for Internet access.

      You can select only an EIP not bound to any resource, an EIP bound to a DNAT rule whose Port Type is not set to All ports in the current public NAT gateway, or an EIP bound to an SNAT rule of the current public NAT gateway.

      You can select multiple EIPs at once. Up to 20 EIPs can be selected for each SNAT rule. If you have selected multiple EIPs for an SNAT rule, one of them will be chosen randomly.

      Monitoring

      Monitoring of the number of SNAT connections.

      You can set alarm rules to monitor your SNAT connections and keep informed of any changes in a timely manner.

      Description

      Supplementary information about the SNAT rule. Enter up to 255 characters.

  2. Configure the route table for the VPC-NAT gateway.
    1. Go to the route table list.
    2. In the Name column, click the route table name of a VPC. The Summary page is displayed.
    3. Click Add Route and configure parameters.
      Table 8 Route parameters

      Parameter

      Description

      Destination Type

      Select IP address.

      Destination

      Destination CIDR block. Enter the IP address of VPC1.

      The CIDR block cannot conflict with existing routes or subnet CIDR blocks in the VPCs.

      Next Hop Type

      Select Enterprise router from the drop-down list.

      Next Hop

      Select a resource for the next hop.

      The drop-down list displays the enterprise routers you created.

      Description

      (Optional) Supplementary information about the route.

      Enter up to 255 characters. Angle brackets (< or >) are not allowed.

Step 3: Configure the Route Table of VPC 1

  1. Go to the route table list.
  2. In the Name column, click the route table name of VPC1. The Summary page is displayed.
  3. Click Add Route and configure parameters.

    Table 9 Route parameters

    Parameter

    Description

    Destination Type

    Select IP address.

    Destination

    Destination CIDR block. Set it to 0.0.0.0/0.

    Next Hop Type

    Select Enterprise router from the drop-down list.

    Next Hop

    Select a resource for the next hop.

    The drop-down list displays the enterprise routers you created.

    Description

    (Optional) Supplementary information about the route.

    Enter up to 255 characters. Angle brackets (< or >) are not allowed.

(Optional) Step 4: Test Network Connectivity

Test network connectivity. Use a test server in the service VPC to access the external network. If the access is successful, the NAT configuration is proper.

Step 5: Enable Inter-VPC Firewall Protection

For details, see Enabling the Inter-VPC Firewall.

(Optional) Step 6: Test Network Connectivity Again

Use the test server in the service VPC to test the network connectivity again. If the firewall traffic log contains response records, traffic has been successfully diverted to the firewall. For details about how to query traffic logs, see Traffic Logs.

Step 7: Configure a NAT Protection Rule

After verifying the traffic flow, configure protection rules so that the CFW can allow or block traffic accordingly.

  1. Log in to the CFW console.
  2. Click in the upper left corner of the management console and select a region.
  3. (Optional) Switch to another firewall instance. If there are multiple firewall instances, you can select a desired instance from the drop-down list in the upper left corner of the page.
  4. In the navigation pane of the CFW console, choose Protection Policies > Access Control > Internet Border Protection Rules. The Internet Border Protection Rules page is displayed.
  5. On the Protection Rules tab page, click the NAT sub-tab, and click Add Rule. On the Add Rule page, configure the key parameters as follows:

    • Rule Type: Select NAT.
    • Direction: Select SNAT.
    • Source: Select IP address. Enter a private IP address.
    • Destination: Select IP address (and enter a public IP address) or Domain name/Domain name group.
    • Application: Select Any.

  6. Click OK.

(Optional) Step 8: View Logs

Use the test server to access the IP address or domain name and check whether the access control log contains a log that matches the rule. If it does, the protection rule has taken effect. For more information, see Access Control Logs.

Step 9: Switch Workloads

After the configurations pass the verification, gradually switch workloads from the production-like or live network environment to CFW.