Allowing CVM Without a Public Network to Access the Public Netwo

Last Updated At: 2025-11-26 11:12:15

Overview

When purchasing a CVM, if you select a bandwidth limit of 0Mbps, the CVM will not be able to access the public network. Taking CentOS7.5 as an example, this document describes how to connect a CVM without a public IP address to a CVM with a public IP address through PPTP VPN so that it can access the public network.

Prerequisites

  • Two CVMs have been created in the same Virtual Private Cloud (one CVM without a public IP address and one CVM with a public IP address).
  • The private IP address of the CVM with a public IP address has been obtained.

Directions

Configuring PPTP on the CVM with Public IP Address

  1. Log in to the CVM with a public IP address.

  2. Run the following command to install PPTP.

    yum install -y pptpd
    
  3. Execute the following command to open the pptpd.conf configuration file.

    vim /etc/pptpd.conf
    
  4. Press i to switch to the edit mode and add the following content at the end of the file.

    localip 192.168.0.1
    remoteip 192.168.0.234-238,192.168.0.245
    
  5. Press “Esc”, enter “:wq” to save the file and return.

  6. Execute the following command to open the /etc/ppp/chap-secrets configuration file.

    vim /etc/ppp/chap-secrets
    
  7. Press i to switch to the edit mode and add the username and password for connecting to PPTP at the end of the file in the following format.

    Username    pptpd    Password    *
    

    For example, if the username for connecting to PPTP is root and the login password is 123456, the information to be added is as follows:

    root    pptpd    123456    *
    
  8. Press Esc, enter “:wq”, save the file and return.

  9. Run the following command to start the PPTP service.

    systemctl start pptpd
    
  10. Execute the following commands in sequence to enable the forwarding capability.

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j MASQUERADE

Configuring PPTP on the CVM Without Public IP Address

  1. Log in to the CVM without a public IP address.

  2. Run the following command to install the PPTP client.

    yum install -y pptp pptp-setup
    
  3. Run the following command to create a configuration file.

    pptpsetup --create (the name of the configuration file) --server (the private IP address of the CVM with a public IP address) --username (the username for connecting to PPTP) --password (the password for connecting to PPTP) --encrypt
    

    For example, to create a test configuration file, if the obtained private IP address of the CVM with a public IP address is 10.100.100.1, run the following command:

    pptpsetup --create test --server 10.100.100.1 --username root --password 123456 --encrypt
    
  4. Run the following command to connect to PPTP.

    pppd call test (name of the configuration file created in Step 3)
    
  5. Execute the following commands in sequence to set the route.

    route add -net 10.0.0.0/8 dev eth0
    route add -net 172.16.0.0/12 dev eth0
    route add -net 192.168.0.0/16 dev eth0
    route add -net 169.254.0.0/16 dev eth0
    route add -net 9.0.0.0/8 dev eth0
    route add -net 100.64.0.0/10 dev eth0
    route add -net 0.0.0.0 dev ppp0
    

Checking Whether the Configuration Is Successful

On the CVM without a public IP address, execute the following command to PING any public IP address, and check whether the PING is successful.

ping -c 4 public IP address

If the following result is returned, the configuration is successful: