Tutorials How to configure floating IP on CoreOS

How to configure floating IP on CoreOS

Once you get a confirmation from the UpCloud Support that a floating IP has been added, you can find it attached to one of your servers at your UpCloud Control Panel, but using the added IP will require some manual setup. Follow the steps below to find out how to get this done on a CoreOS server.

As an example of a public floating IP, server 1 (185.20.139.167) and the server 2 (185.20.139.162) have a common floating IP 185.20.139.29, netmask 255.255.252.0 and gateway 185.20.136.1. These are highlighted below in red.

In case you wish to configure a private floating IP, see the example with server 1 (10.2.9.231), server 2 (10.2.10.25), private floating IP 10.2.9.108, netmask 255.255.252.0 and gateway 10.2.8.1. Follow the instructions underneath highlighted in purple.

Configuring public floating IP address

Firstly, you’ll need to configure the servers at the OS level, so start up your servers at your UpCloud control panel and log in.

Check your current network settings with the following command.

ip addr

Commonly the second network interface card (NIC) named eth0 has your public IPv4 address assigned to it, like in the example output below.

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
   link/ether 6e:d7:1b:bf:20:df brd ff:ff:ff:ff:ff:ff
   inet 94.237.33.165/22 brd 94.237.35.255 scope global eth0
      valid_lft forever preferred_lft forever
   inet6 fe80::6cd7:1bff:febf:20df/64 scope link
      valid_lft forever preferred_lft forever

In addition to the IP addresses, you will need the default gateway, it can be found with the command underneath.

route -n
Kernel IP routing table
Destination  Gateway      Genmask        Flags  Metric  Ref  Use  Iface
0.0.0.0      94.237.32.1  0.0.0.0        UG     0       0    0    eth0
10.0.0.0     10.1.8.1     255.0.0.0      UG     1024    0    0    eth1
10.1.8.0     0.0.0.0      255.255.252.0  U      0       0    0    eth1
94.237.32.0  0.0.0.0      255.255.252.0  U      0       0    0    eth0
172.17.0.0   0.0.0.0      255.255.0.0    U      0       0    0    docker0
172.18.0.0   0.0.0.0      255.255.0.0    U      0       0    0    docker_gwbridge

Set the addresses statically on the NIC with your public IPv4, eth0 in this case. On a CoreOS host, this can be done by creating a network configuration file at /etc/systemd/network.

sudo vi /etc/systemd/network/static.network

Enter the following two sections with the specified details found in the outputs above. The name match defines which network interface the addresses belong to, while the addresses include the normal IPv4 and the floating IP address. For the gateway, use the IP address ending in .1 shown in the Kernel IP routing table for your network interface.

[Match]
Name=eth0

[Network]
Address=94.237.33.165/22
Address=94.237.33.180/22
Gateway=94.237.32.1

After adding in the required details, save the file and exit. You will then need to restart the networking process to enable the static configuration.

sudo systemctl restart systemd-networkd

If you were connected with SSH, the networking restart should not cause you to disconnect. In case you do loose connection and are unable to reconnect, you can always use the web Console at UpCloud control panel under your Server settings to go through the setup again to make sure everything is entered correctly.

Repeat the steps on your other server to configure it with static IP addresses as well.

Configuring private floating IP address

Firstly, you’ll need to configure the servers at the OS level, so start up your servers at your UpCloud control panel and log in.

Check your current network settings with the following command.

ip addr

Commonly the second network interface card (NIC) named eth1 has your private IPv4 address assigned. See the example output below.

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 6e:d7:1b:bf:de:ca brd ff:ff:ff:ff:ff:ff
    inet 10.2.9.231/22 brd 10.2.11.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::6cd7:1bff:febf:deca/64 scope link
       valid_lft forever preferred_lft forever

In addition to the IP addresses, you will need the default gateway which can be found with the command underneath.

route -n
Kernel IP routing table
Destination  Gateway      Genmask        Flags  Metric  Ref  Use  Iface
0.0.0.0      94.237.32.1  0.0.0.0        UG     0       0    0    eth0
10.0.0.0     10.2.8.1     255.0.0.0      UG     1024    0    0    eth1
10.2.8.0     0.0.0.0      255.255.252.0  U      0       0    0    eth1
94.237.32.0  0.0.0.0      255.255.252.0  U      0       0    0    eth0
172.17.0.0   0.0.0.0      255.255.0.0    U      0       0    0    docker0

Next, set the addresses statically on the NIC with your private IPv4, eth1 in this case. On a CoreOS host, this can be done by creating a network configuration file at /etc/systemd/network.

sudo vi /etc/systemd/network/static.network

Enter the following three sections with the specified details found in the outputs above. The name match defines which network interface the addresses belong to, while the addresses include the private IP and the private floating IP address. For the gateway, use the IP address ending in .1 shown in the IP routing table for your network interface and include the same destination as in the example below.

[Match]
Name=eth1

[Network]
Address=10.2.9.231/22
Address=10.2.9.108/22

[Route]
Gateway=10.2.8.1
Destination=10.0.0.0/8

After adding in the required details, save the file and exit. You will then need to restart the networking process to enable the static configuration.

sudo systemctl restart systemd-networkd

If you are connected with SSH, the networking restart should not cause you to disconnect. In case you do loose connection and are unable to reconnect, you can always use the web Console at UpCloud control panel under your Server settings to go through the setup again to make sure everything is entered correctly.

Repeat the steps on your other server to configure the private floating IP address there as well.

Enabling traffic to the floating IP

With the floating IP address set up, check which server the floating IP is attached to under the Network list at your UpCloud control panel. The traffic to the floating IP is by default directed to the server it was initially assigned to.

Check your network configuration again with the same command as before.

ip addr

The newly added floating IP should show up under the same NIC as the same IP address it was configured together with.

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
   link/ether 6e:d7:1b:bf:20:df brd ff:ff:ff:ff:ff:ff
   inet 94.237.33.165/22 brd 94.237.35.255 scope global eth0
      valid_lft forever preferred_lft forever
   inet 94.237.33.180/22 brd 94.237.35.255 scope global secondary eth0
      valid_lft forever preferred_lft forever
   inet6 fe80::6cd7:1bff:febf:20df/64 scope link
      valid_lft forever preferred_lft forever

Or alternatively with a private floating IP address.

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 6e:d7:1b:bf:c9:a6 brd ff:ff:ff:ff:ff:ff
    inet 10.2.9.231/22 brd 10.2.11.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet 10.2.9.108/22 brd 10.2.11.255 scope global secondary eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::6cd7:1bff:febf:c9a6/64 scope link
       valid_lft forever preferred_lft forever

Now attempt to connect to your server using the floating IP with SSH, or if you have a web server configured open the floating IP on your web browser. For private floating IPs, you’ll need to test it from another UpCloud server on your account, for example, using ping.

If you get a reply, the floating IP works on that server and you can continue forward. If it didn’t work, make sure you entered the IP address and gateway correctly, that your firewall isn’t blocking your connections, or try another method to connect.

Transferring the floating IP

Your configuration should now be working, but a static floating IP would be of a little use. Test that the address can be transferred between the server.

To do this, you will need to tell the gateway which decides the host the traffic coming to the floating IP should be directed to. A simple way to do this is using the arping command line network tool, but it is not installed on the minimalistic CoreOS by default. Fortunately, docker is able to provide a solution with the busybox container image, which includes many useful tools in a small and simple package.

Use the following docker command to run a single arping request on a public IP.

docker run --network=host --entrypoint=/bin/arping --rm busybox -c 1 -s floating_ip gateway

Docker will download the latest busybox image, starts it up attached to the host network and runs the arping command with the parameters after the busybox image name. Replace the floating_ip and gateway with the correct IP addresses for your system and you should see an output similar to the example below.

docker run --network=host --entrypoint=/bin/arping --rm busybox -c 1 -s 94.237.33.180 94.237.32.1
ARPING to 94.237.32.1 from 94.237.33.180 via eth0
Unicast reply from 94.237.32.1 [00:00:0c:9f:f0:10] 0.208ms
Sent 1 probe(s) (0 broadcast(s))
Received 1 reply (0 request(s), 0 broadcast(s))

In case you are attempting to use a private floating address, you’ll also need to define the network interface that should be used.

docker run --network=host --entrypoint=/bin/arping --rm busybox -c 1 -I eth1 -U -s 10.2.9.108 10.2.8.1
ARPING 10.2.8.1 from 10.2.9.108 eth1
Unicast reply from 10.2.8.1 [00:00:5e:00:01:0a] 0.251ms
Sent 1 probe(s) (0 broadcast(s))
Received 1 response(s) (0 request(s), 0 broadcast(s))

Then test the floating IP again with any method you prefer. When you get a connection you have successfully transferred the floating IP.

Using your new floating IP

You can now transfer the floating IP between your cloud servers by running the busybox arping command on the new destination host.

Depending on your intended use case for the floating IP you may wish to continue by setting up automated load balancing, but if you wish to manually transfer the traffic between your servers, it might be useful to create scripts of the required command.

One thought on “How to configure floating IP on CoreOS

Leave a Reply

Your email address will not be published. Required fields are marked *

Locations

Helsinki (HQ)

In the capital city of Finland, you will find our headquarters, and our first data centre. This is where we handle most of our development and innovation.

London

London was our second office to open, and a important step in introducing UpCloud to the world. Here our amazing staff can help you with both sales and support, in addition to host tons of interesting meetups.

Seattle

Seattle is our 4th and latest office to be opened, and our way to reach out across the pond to our many users in the Americas.

Singapore

Singapore was our 3rd office to be opened, and enjoys one of most engaged and fastest growing user bases we have ever seen.