# Configure a Manual Elastic IP

**Manual Elastic IPs require additional configuration** on the target instance
for that instance to receive traffic.

> [!WARNING] 
> The Elastic IP address is set up as an additional IP address for your instance. 
> The original IP address will still work, as it is used for outgoing connections. 
> **Do not remove the original IP address of the instance** as the Elastic IP will not work without it. 
> Several other native functionalities will also break.

The operations and commands to be performed vary depending on your chosen template. Below are a few examples for different templates:


### Ubuntu 
Ubuntu 18.04 LTS (Bionic Beaver)

In `/etc/netplan/51-eip.yaml`, put the following snippet.

```yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    lo:
      match:
        name: lo
      addresses:
        - 203.0.113.202/32
```

And then, apply it: `sudo netplan apply`

### Debian
Debian 11 and Ubuntu 16.04 LTS (Xenial Xerus) or older.

In `/etc/network/interfaces.d/eip.cfg`, add the following snippet:

```bash
    auto lo:1
    iface lo:1 inet static
        address 203.0.113.202/32
```

Then, use `ifup lo:1` to enable the Elastic IP. It will also be enabled
automatically on boot. From here, you should be able to ping your
instance and any service authorized in the associated security group
should be reachable with this Elastic IP as well.

If you need to add any additional Elastic IPs, use `lo:2`, `lo:3`, et cetera.

On Debian 8, you have to add `source /etc/network/interfaces.d/*` in
your `/etc/network/interfaces`.

### CoreOS
Create the configuration file for loopback interface
`/etc/systemd/network/loopback-alias.network`, with the following
content:

```bash
[Match]
Name=lo

[Network]

[Address]
Label=lo:1
Address=203.0.113.202/32
```

Ensure that systemd-networkd is enable:
`sudo systemctl enable systemd-networkd.service`

To apply the configuration, run `sudo systemctl restart systemd-networkd`
to restart. It will also be enabled automatically on boot. You can now ping the
Elastic IP address and any service authorized in the associated Security Group
should be reachable with this Elastic IP as well.

You can add multiple loopback Address blocks.

### SLES

To configure the EIP on SLES edit the network config with:

```bash
sudo vi /etc/sysconfig/network/ifcfg-lo
```

There add a new line below `IPADDR=127.0.0.1/8` with:

```bash
IPADDR_1='203.0.113.202/32'
```

Then apply the changes:

```bash
sudo wicked ifreload lo
```

To connect to the instance via the EIP using SSH:

```bash
ssh sles@203.0.113.202
```

### Other Linux Distributions
You can manually add the Elastic IP address on any Linux Instance with the
following command:

```bash
ip addr add 203.0.113.202/32 dev lo
```

> **Beware**:   
  this configuration will be lost if you reboot the instance in absence of some custom automation.


### OpenBSD
Configure your Elastic IP with this single command:

```bash
echo inet 203.0.113.202/32 > /etc/hostname.lo1
```

You can reconfigure your network on the fly with:

```bash
sh /etc/netstart
```

Since OpenBSD 6.7, it is now required to enable IP routing. This can be done
with the command `sysctl`:

```bash
sysctl net.inet.ip.forwarding=1

# To persist the change upon reboot
echo net.inet.ip.forwarding=1 >> /etc/sysctl.conf
```

### Windows
As a first step, we need to install a special driver for the hardware wizard.
Open a command line and execute the following command:

```bash
hdwwiz
```

You should get the **Add Hardware Wizard**:

![](eip-windows-2.png "Windows: Add Hardware")

Click on **Next**. On the next screen, choose the
**Install the hardware that I manually select from a list**:

![](eip-windows-3.png "Windows: Add Hardware")

Click on **Next**. On the next screen, choose **Network adapters**:

![](eip-windows-4.png "Windows: Add Hardware")

Click on **Next**. On the next screen, choose **Microsoft** in the list on the
left-hand side, then **Microsoft KM-TEST Loopback Adapter** in the list on the
right-hand side:

![](eip-windows-5.png "Windows: Add Hardware")

click on **Next**, then click on **Install**.

The following steps will assign the EIP to the `Loopback` interface and activate `IP Forwarding` to the relevant interfaces. 

> [!NOTE]
> If you don't have `PowerShell` on your instance, please try and install it or let us know about it.
> We will try and provide a different procedure.

Please open your favorite Windows editor and create a file called `EIP.ps` with the following content:

```bash
# Get the EIP in the format XXX.XXX.XXX.XXX/32 from the cli
param(
[string]$EIP
)
# split the address and its mask
$IPAddress=($EIP -split '/' | Select-Object -First 1)
$Mask=($EIP -split '/' | Select-Object -Last 1)
# query http://metadata.exoscale.com/latest/meta-data/local-ipv4 to get the Public IP
$MyPublicIPAddress=(Invoke-WebRequest metadata.exoscale.com/latest/meta-data/local-ipv4).Content.Trim()
# Rename to Loopback
Get-NetAdapter -InterfaceDescription "Microsoft *" | Rename-NetAdapter Name "Loopback"
# Configure the EIP
Get-NetAdapter -Name "Loopback" | New-NetIPAddress -IPAddress $IPAddress -PrefixLength $Mask
# Get the Public interface ifIndex
$PublicInterfaceIndex=(Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.IPAddress -match $MyPublicIPAddress} | Select-Object InterfaceIndex)
# Get the Loopback interface ifIndex
$LoopbackInterfaceIndex=(Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.IPAddress -match $IPAddress} | Select-Object InterfaceIndex)
# Enable Forwarding
Set-NetIPInterface -ifIndex $PublicInterfaceIndex.InterfaceIndex -Forwarding Enable
Set-NetIPInterface -ifIndex $LoopbackInterfaceIndex.InterfaceIndex -Forwarding Enable
# Print the status after the changes
Get-NetIPInterface -AddressFamily IPv4 | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table
```

Once the file is created you can now add your EIP as follows:

```powershell
EIP.ps 203.0.113.203/32
```

In the same way you can attach multiple EIPs.
