{"id":2380,"date":"2015-12-04T13:40:52","date_gmt":"2015-12-04T11:40:52","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/configure-floating-ip-ubuntu\/"},"modified":"2015-12-04T13:40:52","modified_gmt":"2015-12-04T11:40:52","slug":"configure-floating-ip-ubuntu","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/configure-floating-ip-ubuntu\/","title":{"rendered":"How to configure Floating IP on Ubuntu"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When you attach a new floating IP, you can find it listed to one of the servers at your UpCloud Control Panel that the floating IP currently points to. However, using the new floating IP will require some manual setup. Follow the steps below&nbsp;on how to get this done on Ubuntu&nbsp;servers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As an example, we have a Cloud Server with the public IP address 185.20.139.167, a floating IP 185.20.139.29, with a netmask 255.255.255.255. These are highlighted below in <span style=\"color: #ff0000;\">red<\/span>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before making changes to your network configuration, it\u2019s always a good idea to <a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/taking-backups\">take a backup<\/a>. Also, note that if your network configuration becomes inoperable, remember that you can always log in to your Cloud Server using <a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/connecting-to-your-server\">the console connection<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/signup.upcloud.com\/\">Test hosting on UpCloud!<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring floating IP<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Firstly, you\u2019ll need to configure the servers at the OS level, so start up your Cloud Server at your&nbsp;<a rel=\"noopener\" href=\"https:\/\/hub.upcloud.com\/\" target=\"_blank\">UpCloud Control Panel<\/a>&nbsp;and&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/upcloud.com\/global\/community\/\n\/tutorials\/connecting-to-your-server\/\" target=\"_blank\">log in<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check your current network settings with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ip addr<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Commonly the second network interface card (NIC) named <tt>eth0<\/tt> has your public IPv4 address assigned to it, see the example below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2: <span style=\"color: #ff0000;\">eth0<\/span>: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n&nbsp;&nbsp;&nbsp; link\/ether 6e:d7:1b:bf:5a:b0 brd ff:ff:ff:ff:ff:ff\n&nbsp;&nbsp;&nbsp; inet <span style=\"color: #ff0000;\">185.20.139.167<\/span>\/22 brd 80.69.175.255 scope global eth0\n&nbsp;&nbsp;&nbsp;&nbsp;valid_lft forever preferred_lft forever<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now, to enable the floating IP, add it as an alias to the network interface <tt>eth0<\/tt>&nbsp;that has your public IP address. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Ubuntu 22 and later<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Since the release of Ubuntu 22, the OS has been using netplan which changes how the network interfaces are configured.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create the following file in the netplan configuration directory with the command below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo nano \/etc\/netplan\/99-floating-ip.yaml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">network:\n    version: 2\n    renderer: networkd\n    ethernets:\n        eth0:\n            addresses:\n                - <span style=\"color: #ff0000;\">185.20.139.29<\/span>\/32<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then save the file and exit the editor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, apply the changes with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo netplan apply<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Afterwards, you should be able to see the floating IP attached to the eth0 network interface.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">ip addr<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel state UP group default qlen 1000\n    link\/ether 6e:d7:1b:bf:0a:c7 brd ff:ff:ff:ff:ff:ff\n    altname enp0s3\n    altname ens3\n    inet <span style=\"color: #ff0000;\">185.20.139.29<\/span>\/32 scope global eth0\n       valid_lft forever preferred_lft forever\n     inet <span style=\"color: #ff0000;\">185.20.139.167<\/span>\/22 brd 80.69.175.255 scope global dynamic eth0\n       valid_lft 67261sec preferred_lft 67261sec\n    inet6 fe80::6cd7:1bff:febf:ac7\/64 scope link \n       valid_lft forever preferred_lft forever<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Applying the changes should not cause you to disconnect from the server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In case you do lose connection and are unable to reconnect, you can always use the web&nbsp;<em>Console<\/em> at <a rel=\"noopener\" href=\"https:\/\/hub.upcloud.com\/\" target=\"_blank\">UpCloud Control Panel<\/a> under your <em>Server settings<\/em> to go through the setup again to make sure everything is entered correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Repeat the process to add the alias on&nbsp;any other&nbsp;servers you wish to use the floating IP on.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Ubuntu 20 and earlier<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">On Ubuntu 20 and earlier, adding an alias network interface can be done by adding <tt>eth0:1<\/tt> to the <tt>interfaces<\/tt>&nbsp;file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/network\/interfaces<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enter the example configuration shown below with your floating IP and netmask.&nbsp;The address highlighted in red below is an example, replace it with your floating IP.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">auto eth0:1\niface eth0:1 inet static\naddress <span style=\"color: #ff0000;\">185.20.139.29\n<\/span>netmask <span style=\"color: #ff0000;\">255.255.255.255<\/span><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file and exit after these changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, restart the network manager to enable the new configuration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl restart networking<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you were connected with SSH, the networking restart should not cause you to disconnect. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In case you do lose connection and are unable to reconnect, you can always use the web&nbsp;<em>Console<\/em> at <a rel=\"noopener\" href=\"https:\/\/hub.upcloud.com\/\" target=\"_blank\">UpCloud Control Panel<\/a> under your <em>Server settings<\/em> to go through the setup again to make sure everything is entered correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Repeat the process to add the alias on&nbsp;any other&nbsp;servers you wish to use the floating IP on.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing the configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Your configuration is now complete. You can test that it works by transferring the floating IP from one server to another.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, ping the cloud server or attempt to connect to your server through the floating IP via SSH. Alternatively, if you have a web server configured, open the floating IP on your web browser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then transfer the floating IP to another cloud server you\u2019ve configured. This can be done either at your <a rel=\"noopener\" href=\"https:\/\/hub.upcloud.com\/networks\/floating-ips\" target=\"_blank\">UpCloud Control Panel<\/a> or by using the <a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/managing-floating-ips-upcloud-api\">UpCloud API<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test the floating IP again with any method you prefer.&nbsp;When you get a connection you have successfully transferred&nbsp;your&nbsp;floating IP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you get a reply, the floating IP works on that server and you can continue forward. If it didn\u2019t work, make sure you entered the IP address and netmask correctly, and that your firewall isn\u2019t blocking your connections, or try another method&nbsp;to connect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using your new floating IP<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can now&nbsp;transfer the floating IP between your cloud&nbsp;servers at your <a rel=\"noopener\" href=\"https:\/\/hub.upcloud.com\/networks\/floating-ips\" target=\"_blank\">UpCloud Control Panel<\/a> or by using the <a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/managing-floating-ips-upcloud-api\">UpCloud API<\/a>!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Depending on your intended use case for the floating IP you may wish to continue by setting up automated load balancing, but it\u2019s always possible to manually transfer the traffic between your servers.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","community-category":[259,247],"class_list":["post-2380","tutorial","type-tutorial","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=2380"}],"version-history":[{"count":0,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2380\/revisions"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=2380"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=2380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}