Help Center/ Elastic Cloud Server/ User Guide/ EIPs/ Enabling Internet Connectivity for an ECS Without an EIP Bound
Updated on 2026-08-10 GMT+08:00

Enabling Internet Connectivity for an ECS Without an EIP Bound

Scenarios

To ensure platform security and conserve EIPs, EIPs are only assigned to specified ECSs. ECSs without EIPs cannot access the Internet directly.

If these ECSs need to access the Internet (for example, to perform a software upgrade or install a patch), you can choose from the following solutions:
  • (Recommended) Using NAT Gateway

    A NAT gateway provides SNAT and DNAT to enable multiple ECSs in the same VPC to share an EIP to access the Internet or provide services for the Internet.

  • Using a Linux Proxy ECS

    If you already have an ECS that has an EIP bound, you can use the ECS as the proxy to provide an Internet access channel for other ECSs that are in the same network segment, in the same security group, and have no EIPs bound.

Constraints

Table 1 Constraints

Item

Using NAT Gateway

Using a Linux Proxy ECS

Service dependency

SNAT and DNAT

N/A

Resource dependency

  • EIP
  • Public NAT gateway: must be in the same VPC as the target ECS.
  • EIP
  • Proxy ECS: must have an EIP bound and must be in the same subnet and security group as the target ECS.

Supported status

Running

Running

Prerequisites

  • Using NAT Gateway
    • An EIP has been purchased.
    • A public NAT gateway has been purchased in the same VPC as the ECSs that need to access the Internet.
  • Using a Linux Proxy ECS
    • A proxy ECS with an EIP bound is available.
    • The IP address of the proxy ECS is in the same network and same security group as the ECSs that need to access the Internet.

(Recommended) Using NAT Gateway

Table 2 NAT gateway operations

Scenario

Gateway Rule

Reference

Enabling ECSs without EIPs bound to access the Internet

SNAT

Using a Public NAT Gateway to Enable Servers to Share One or More EIPs to Access the Internet

Enabling ECSs without EIPs bound to provide services for the Internet

DNAT

Using a Public NAT Gateway to Enable Servers to Be Accessed by the Internet

Using a Linux Proxy ECS

The following uses CentOS 7.9 as an example. The operations apply to CentOS 7.9 and earlier versions as well as Huawei Cloud EulerOS 2.0.

For other OSs and versions, see the help documentation of the corresponding official website or (Recommended) Using NAT Gateway.

  1. Disable Source/Destination Check for the proxy ECS.
    1. Log in to the ECS console and access the ECS list page.
    2. In the search box above the ECS list, enter the proxy ECS name for search.
    3. Click the name of the proxy ECS. The ECS details page is displayed.
    4. On the Network Interfaces tab, click . Then, disable Source/Destination Check.
      Figure 1 Disabling Source/Destination Check

      By default, the source/destination check function is enabled. When this function is enabled, the system checks whether source IP addresses contained in the packets sent by ECSs are correct. If the IP addresses are incorrect, the system does not allow the ECSs to send the packets. This mechanism prevents packet spoofing for improved system security. However, it prevents the packet sender from receiving returned packets, so you need to disable source/destination check.

  1. Configure SNAT for the proxy ECS.
    1. Log in to the proxy ECS.

      For more details, see Login Overview (Linux).

    2. Check whether the proxy ECS can access the Internet.

      ping www.huaweicloud.com

      The proxy ECS can access the Internet if information similar to the following is displayed:

      Figure 2 Checking connectivity
    3. (Optional) Install the iptables service and set the automatic startup of iptables.

      Perform this step only for ECSs running CentOS 7.x.

      yum install iptables-services -y

      systemctl start iptables

      systemctl enable iptables

    4. Check whether IP forwarding is enabled on the proxy ECS.

      cat /proc/sys/net/ipv4/ip_forward

      • If 0 (disabled) is displayed, go to 2.e.
      • If 1 (enabled) is displayed, go to 2.j.
    5. Open the IP forwarding configuration file in the vi editor.

      vi /etc/sysctl.conf

    6. Press i to enter Insert mode.
    7. Change the parameter value.

      Set the net.ipv4.ip_forward value to 1.

      If the sysctl.conf file does not contain the net.ipv4.ip_forward parameter, run the following command to add it:

      echo net.ipv4.ip_forward=1 >> /etc/sysctl.conf

    8. Press Esc, type :wq, and press Enter.

      The system saves the configurations and exits the vi editor.

    9. Apply the change.

      sysctl -p /etc/sysctl.conf

    10. Delete the original iptables rules.

      iptables -F

    11. Configure source network address translation (SNAT) to enable ECSs in the same network segment to access the Internet through the proxy ECS.

      iptables -t nat -A POSTROUTING -o eth0 -s subnet/netmask-bits -j SNAT --to nat-instance-ip

      For example, if the proxy ECS is in network segment 192.168.125.0, the subnet mask has 24 bits, and the private IP address is 192.168.125.4, run the following command:

      iptables -t nat -A POSTROUTING -o eth0 -s 192.168.125.0/24 -j SNAT --to 192.168.125.4

      To retain the preceding configuration even after the ECS is restarted, run the vi /etc/rc.local command to edit the rc.local file. Specifically, copy the rule described in step 2.k into rc.local, press Esc to exit Insert mode, and enter :wq to save the settings and exit.

    12. Save the iptables configuration and set the automatic startup of iptables.

      service iptables save

      chkconfig iptables on

      1. Check whether SNAT has been configured.

        iptables -t nat --list

        SNAT has been configured if information similar to Figure 3 is displayed.

        Figure 3 Successful SNAT configuration
  1. Add a custom route to the route table of the VPC that the ECS belongs to.
    1. Log in to the VPC console and access the route table list page.
    2. Select the target VPC and click the number in the Route Tables column. The route table list page is displayed.
    3. Click the target route table to go to the details page.
    4. Above the route list, click Add Route.
    5. Set route information in the displayed dialog box.
      • Destination: indicates the destination network segment. The default value is 0.0.0.0/0.
      • Next Hop: indicates the private IP address of the proxy ECS.

        You can obtain the private IP address of the ECS on the Elastic Cloud Server page.

    6. Click OK. The custom route is added.
  2. Delete the added iptables rules as needed.

    iptables -t nat -D POSTROUTING -o eth0 -s subnet/netmask-bits -j SNAT --to nat-instance-ip

    For example, if the proxy ECS is in network segment 192.168.125.0, the subnet mask has 24 bits, and the private IP address is 192.168.125.4, run the following command:

    iptables -t nat -D POSTROUTING -o eth0 -s 192.168.125.0/24 -j SNAT --to 192.168.125.4