asb
By:
Andrew SB
We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How to Enable Floating IPs on an Older Droplet

PostedOctober 20, 2015 10.9k views DigitalOcean High Availability

Introduction

Network traffic between a Floating IP and a Droplet flows through an anchor IP, which is an IP address that is aliased to a Droplet's public network interface. As such, a Droplet must have an anchor IP before a Floating IP can be assigned to it. Droplets created after October 20, 2015 will automatically have an anchor IP. However, if you have an older Droplet, you will need to add an anchor IP to it before it can work with Floating IPs.

This tutorial will show you how to enable Floating IPs on older DigitalOcean Droplets, by adding an anchor IP. Each distribution requires a different set of steps, so be sure to follow the appropriate section.

Prerequisites

Before continuing, you might want to attempt assigning a Floating IP to the Droplet in question. If it is a Droplet that was created without an anchor IP, instructions to add an anchor IP address should pop up. Follow those instructions and see if that resolves your issue. Otherwise, read on.

If you are simply trying to find your Droplet's anchor IP address, the easiest way to retrieve it is to use the Droplet Metadata service: Run this command from a Droplet to retrieve its anchor IP address:

  • curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/anchor_ipv4/address

The rest of this tutorial will consist of sections that apply only to specific distributions. Please only follow the section that is applicable to the distribution installed on your Droplet.

Ubuntu and Debian

On Ubuntu and Debian, in order to add the "anchor" ip address to your networking configuration, run the following command:

  • sudo ip addr add 10.16.0.5/16 dev eth0

Remember to replace the IP address highlighted in red with your anchor IP found previously.

In order to make sure that this setting will persist after a reboot of your Droplet, you will need to make a change to the file /etc/network/interfaces Open the file with an editor (e.g. nano /etc/network/interfaces) and add the line highlighted in red below:

auto eth0
iface eth0 inet static
        address 162.243.184.156
        netmask 255.255.252.0
        gateway 162.243.184.1
        up ip addr add 10.16.0.5/16 dev eth0
        dns-nameservers 8.8.8.8 8.8.4.4

Again, remember to replace the highlighted IP address your anchor IP.

Fedora, CentOS 6 and CentOS 7

On Fedora and CentOS, in order to add the "anchor" ip address to your networking configuration, run the following command:

  • sudo ip addr add 10.16.0.5/16 dev eth0

Remember to replace the IP address highlighted in red with your anchor IP found previously.

In order to make sure that this setting will persist after a reboot of your Droplet, you will need to make a change to the file /etc/sysconfig/network-scripts/ifcfg-eth0 Open the file with an editor (e.g. nano /etc/sysconfig/network-scripts/ifcfg-eth0) and add the line highlighted in red below:

DEVICE='eth0'
TYPE=Ethernet
BOOTPROTO=none
ONBOOT='yes'
HWADDR=04:01:76:bc:91:01
IPADDR=104.131.99.188
NETMASK=255.255.192.0
GATEWAY=104.131.64.1
NM_CONTROLLED='yes'
IPADDR2=10.16.0.5
PREFIX2=16
DNS1=8.8.8.8
DNS2=8.8.4.4

Again, remember to replace the highlighted IP address your anchor IP.

CentOS 5

On CentOS 5, in order to add the "anchor" ip address to your networking configuration, run the following command:

  • sudo ip addr add 10.16.0.5/16 dev eth0

Remember to replace the IP address highlighted in red with your anchor IP found previously.

In order for it to persist after reboot, you must create a new file containing the networking information at /etc/sysconfig/network-scripts/ifcfg-eth0:0 on the Droplet. This can be done by copying the existing /etc/sysconfig/network-scripts/ifcfg-eth0 file and updating the value of the IPADDR and DEVICE fields to the value of your anchor IP.

  • sudo cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
  • sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0:0

Again, remember to replace the highlighted IP address your anchor IP.

DEVICE='eth0:0'
TYPE=Ethernet
BOOTPROTO=none
ONBOOT='yes'
HWADDR=04:01:76:d6:cb:01
IPADDR=10.16.0.5
NETMASK=255.255.224.0
GATEWAY=45.55.64.1
NM_CONTROLLED='yes'
PREFIX2=16
DNS1=8.8.8.8
DNS2=8.8.4.4

CoreOS

On CoreOS, in order to add the "anchor" ip address to your networking configuration, run the following command:

  • sudo ip addr add 10.16.0.5/16 dev eth0

Remember to replace the IP address highlighted in red with your anchor IP found previously.

In order for it to persist after reboot, you must create a new file containing the networking information at /etc/systemd/network/static.network This can be done by copying the existing file named similar to /var/run/systemd/network/00-04:01:7e:8f:35:01.network and adding a second Address field with the value of your anchor IP. The name of the file will match your Droplet's MAC address.

  • sudo cp /var/run/systemd/network/00-04:01:7e:8f:35:01.network /etc/systemd/network/static.network
  • sudo vi /etc/systemd/network/static.network

Then add the following line to the unit to persist the address:

MACAddress=04:01:7e:8f:35:01

[Network]
DNS=8.8.8.8
DNS=8.8.4.4

[Address]
Address=45.55.81.49/20
Address=10.16.0.5

[Route]
Destination=0.0.0.0/0
Gateway=45.55.64.1

FreeBSD

On FreeBSD, in order to add the "anchor" ip address to your networking configuration, run the following command:

  • sudo ifconfig vtnet0 10.17.0.15 netmask 255.255.0.0 alias

Remember to replace the IP address highlighted in red with your anchor IP found previously.

In order for it to persist after reboot, append the new networking information to the file /etc/rc.digitalocean.d/droplet.conf. This can be accomplished by running the following command on your Droplet:

echo 'ifconfig_vtnet0_alias0="inet 10.17.0.15 netmask 255.255.0.0"' | sudo tee -a /etc/rc.digitalocean.d/droplet.conf

Conclusion

Once you have added an anchor IP to your Droplet, you should be able to use it with a Floating IP. To learn more about DigitalOcean Floating IPs, read this tutorial: How To Use Floating IPs on DigitalOcean.

5 Comments

Creative Commons License