Blog Post - 2. März 2019
Add a second Elastic IP to a AWS EC2 instance with Ubuntu 18

Add a second Elastic IP to a AWS EC2 instance with Ubuntu 18

Adding a second public (Elastic) IP to a Amazon AWS EC2 instance with Ubuntu 18 can be quite a pain. With my former EC2 instances running on Ubuntu 14 and 16 I was using two network interfaces with a single private IP and a single public (Elastic) IP on each interface. To make this configuration work, I simply needed to adjust the routing tables.

Since Ubuntu 18 is using netplan, the whole configuration changed a lot. After a few failed attempts with two seperate network interfaces and a corresponding netplan config, I almost gave up on this. At any time the instance was only reachable with only one of the two public IPs from the outside. Even though I used some official AWS EC2 documentation.

1.1 While being frustrated, I remebered reading somewhere, that it was also possible to assign two public IPs on the same interface. Therefore the interface also needs two private IPs. If you start from scratch, in Step 3: Configure Instance Details you need to specify a Subnet and disable Auto-assign Public IP. Afterwards you'll see a new selection Network at the bottom of the form, where you can add secondary IP addresses to the first network interface. Remember both private IPs, you'll need them in the next step. Continue with 2.

- OR -

1.2 If you have an already running instance, in the EC2 Management Console go to Network Interfaces, select the primary interface from that machine (or create an additional one) and hit Actions/Manage Ip Addresses. Now you can add another private IP to the interface. Remember both private IPs, you'll need them in the next step.

2. Now you can obtain (if not already done) two elastic IPs under the point Elastic IPs. Now you need to assign both Elastic IPs to the same interface on your EC2 instance and chose a corresponding Private IP manually for each interface.

3. (Re)Start your instance and try logging in via SSH with the first of your Elastic IPs.

4. Check the default netplan config at /etc/netplan/50-cloud-init.yaml

# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
  version: 2
      dhcp4: true
        macaddress: 12:34:56:ab:cd:ef
      set-name: eth0

5. Now create a new netplan config for the same interface  /etc/netplan/60-eth0.yaml

  version: 2
  renderer: networkd

Where is your second public (Elastic) IP.

6. Now check and apply the new settings with:

sudo netplan try