How to Use an Elastic IP as a Public Network Egress IP

Elastic IPs can be used as stable and reliable public egress IP addresses to realize scenarios requiring continuous availability and accessibility.

To use an elastic IP as a public network egress IP, we will perform the following steps:

Step 1 - Purchase and Associate Elastic IP

  • You can create an elastic IP and assign it to your desired instance on zenConsole. View Create an Elastic IP for specified details.

  • If you already have an elastic IP, you can go to the instance details page, and assign the elastic IP to your desired instance.


Only elastic IPs in the same zone of the instance can be assigned.

Step 2 - Set Elastic IP as Public Internet Egress IP

You can use the ip command on your instance to set the priority of the elastic IP address. Here's an example of CentOS 7.6 operating system instance about how to set the elastic IP address priority using the ip command:

sudo ip route add default via default-gateway src source-IP dev network-interface
  • default-gateway: the default gateway address;

  • source-IP: the elastic IP address you want to use;

  • network-interface: the network interface associated with the elastic IP address.


  • The settings are temporary and will be invalid after a system reboot. If you want to permanently set the elastic IP, you can add the relevant command to your system's startup script.

  • The settings may vary depending on your operating system's version. You're recommended to refer to the official documentation of your system to learn more about related configurations.


  1. For CentOS 7.6 operating system instance, you have assigned and to your instance. You want to set as the public egress IP. You can see the gateway

  1. Use the ip a command to get the network interface.

In this case,

  • default-gateway:;

  • source-IP:;

  • network-interface: wan0.

  1. Execute the following command:

sudo ip route add default via src dev wan0


Now all your egress traffic will go through the elastic IP address you have set.

Last updated