Home/Server & Website Managed Operations/How to Enable Internet Access for VPC Hosts Without EIP on Alibaba Cloud
Server & Website Managed Operations

How to Enable Internet Access for VPC Hosts Without EIP on Alibaba Cloud

Problem Background

Alibaba Cloud’s VPC differs from other OpenStack-based IaaS platforms in that its routing functions only as a multi-subnet router and does not provide outbound internet routing. Therefore, instances within a VPC cannot access the public internet unless they are bound to an Elastic IP (EIP). According to customer support, this can be resolved by adding a route on the virtual router to forward traffic through an instance bound with an EIP, using NAT and iptables rules.

VPC Architecture Diagram

aliyun-vpc-snat

Virtual Router Configuration

Add Route

To allow internal servers to access the public internet via an EIP, configure all routes targeting 0.0.0.0/0 to forward traffic to the ECS instance bound with the public IP. Note that the next-hop ECS instance cannot be searched directly; you must know its name in advance:

aliyun-vpc-snat-2

Configuration of the Instance Bound with EIP

Add SNAT Rules to iptables

iptables -t nat -I POSTROUTING -s 192.168.2.0/24 -j SNAT --to-source 192.168.2.20

Note: On Ubuntu 14.04, you need to install the iptables-persistent package to save iptables settings. Use service iptables-persistent save to save the configuration. After installation, the service starts automatically with the system and applies the saved configuration.

Enable IP Forwarding

echo "net.ipv4.ip_forward=1" >>  /etc/sysctl.conf && sysctl -p
FREE CHECKUP

Free server checkup

We will send a problem checklist and remediation advice within one business day — no obligation to engage.

135 410 16684
Weekdays Mon – Fri 10:00 – 22:00 (UTC+8) · 7×24 emergency response
Call now
CONTACT

Contact Us

How can we help?

* Required