# 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**](https://docs.console.zenlayer.com/welcome/bare-metal/get-started/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.<br>

  <figure><img src="https://3201622183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9X3FDdkCL2HzhbPpPMFt%2Fuploads%2FxGVMtyHM2gR1jAwTCdp2%2Fimage.png?alt=media&#x26;token=631c387f-4ba2-42a5-80bd-9ef2aac0587d" alt=""><figcaption></figcaption></figure>

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

<mark style="color:blue;">Only elastic IPs in the same zone of the instance can be assigned.</mark>
{% endhint %}

## 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:

<pre class="language-bash" data-full-width="false"><code class="lang-bash"><strong>sudo ip route add default via default-gateway src source-IP dev network-interface
</strong></code></pre>

* `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.

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

* <mark style="color:blue;">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.</mark>
* <mark style="color:blue;">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.</mark>
  {% endhint %}

## Example

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

<figure><img src="https://3201622183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9X3FDdkCL2HzhbPpPMFt%2Fuploads%2FBeg0WcqWgZ8MZtASlsRI%2F%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_16994301866496.png?alt=media&#x26;token=5dce78a4-6d4a-4c02-8e37-65a880bbc63f" alt=""><figcaption></figcaption></figure>

2. Use the `ip a` command to get the network interface.

<figure><img src="https://3201622183-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9X3FDdkCL2HzhbPpPMFt%2Fuploads%2FXtBZgNNNUqvI6NLqSFk1%2Fimage.png?alt=media&#x26;token=151fb569-556f-4e5c-94a1-4df7db8da01d" alt=""><figcaption></figcaption></figure>

In this case,

* `default-gateway`: `193.118.55.117`;
* `source-IP`: `193.118.53.186`;
* `network-interface`: `wan0`.

3. Execute the following command:

<pre class="language-bash"><code class="lang-bash"><strong>sudo ip route add default via 193.118.55.117 src 193.118.53.186 dev wan0
</strong></code></pre>

## Result

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