--- title: "Set up failover with a Floating IP" description: "Keep a service reachable when a node fails, by attaching a Floating IP to a primary node and a backup and configuring failover." content_type: "how-to" product: "reserved-ip" platform: "MyAccount" url: "/myaccount/reserved-ip/how-to/set-up-failover-with-a-floating-ip/" topic: ["floating"] relationships: {"requires":["/myaccount/reserved-ip/how-to/use-a-reserved-ip-as-a-floating-ip/"]} --- # Set up failover with a Floating IP With a Floating IP on two nodes, you can keep a service reachable when one of them fails. One node holds the address; the other watches it and takes the address over when the first one stops. The steps set that up on two Ubuntu nodes with Keepalived, an open-source tool commonly used for this. Other tools that move an address between machines work on the same idea. ## Before you begin - A [Floating IP](/myaccount/reserved-ip/how-to/use-a-reserved-ip-as-a-floating-ip/) attached to both nodes. - The same service running on both nodes, so either one can answer. - SSH access to both nodes as `root`. ## Set up the primary node 1. Connect to the primary node over SSH and install Keepalived: ```bash apt update apt install keepalived -y ``` 2. Create `/etc/keepalived/keepalived.conf` with this content: ```text vrrp_instance VI_1 { state MASTER interface ens3 virtual_router_id 51 priority 100 authentication { auth_type PASS auth_pass } virtual_ipaddress { } } ``` Put your Floating IP in place of ``. Put a password of your own in place of ``; Keepalived reads its first eight characters. `ens3` is the public network interface on Ubuntu 24.04 nodes, and `ip addr` shows the name on yours. 3. Start Keepalived, now and at every boot: ```bash systemctl enable --now keepalived ``` Within a few seconds the primary claims the Floating IP, and your service answers on it. ## Set up the backup node 1. Connect to the backup node and install Keepalived the same way. 2. Create `/etc/keepalived/keepalived.conf` with the same content and two changes: `state` is `BACKUP`, and `priority` is lower than the primary's. ```text vrrp_instance VI_1 { state BACKUP interface ens3 virtual_router_id 51 priority 90 authentication { auth_type PASS auth_pass } virtual_ipaddress { } } ``` Keep the virtual router id, `51` here, and the password the same as on the primary. That is how the two nodes know they are a pair. 3. Start Keepalived: ```bash systemctl enable --now keepalived ``` ## Test the failover On the primary, check that it holds the address: ```bash ip addr show ens3 | grep ``` Now stop Keepalived on the primary to act out a failure: ```bash systemctl stop keepalived ``` Run the same `ip addr` command on the backup: within a second or two the Floating IP is there, and your service still answers on it. Start Keepalived on the primary again with `systemctl start keepalived`, and with its higher priority it takes the address back. Your service now stays on one address through a node failure. For a third or fourth node, attach it to the Floating IP and give it the backup configuration with a lower priority again; see [Use a reserved IP as a Floating IP](/myaccount/reserved-ip/how-to/use-a-reserved-ip-as-a-floating-ip/#add-or-remove-nodes).