{"id":334,"date":"2018-08-12T19:02:11","date_gmt":"2018-08-12T16:02:11","guid":{"rendered":"http:\/\/kifarunix.com\/?p=334"},"modified":"2024-03-10T18:02:15","modified_gmt":"2024-03-10T15:02:15","slug":"configure-static-ip-addresses-using-netplan-on-ubuntu","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/configure-static-ip-addresses-using-netplan-on-ubuntu\/","title":{"rendered":"Configure Static IP Addresses using Netplan on Ubuntu"},"content":{"rendered":"\n<figure data-wp-context=\"{&quot;uploadedSrc&quot;:&quot;https:\\\/\\\/kifarunix.com\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/static-ip-addresses-using-netplan.png&quot;,&quot;figureClassNames&quot;:&quot;wp-block-image size-full&quot;,&quot;figureStyles&quot;:null,&quot;imgClassNames&quot;:&quot;wp-image-15345&quot;,&quot;imgStyles&quot;:null,&quot;targetWidth&quot;:1066,&quot;targetHeight&quot;:597,&quot;scaleAttr&quot;:false,&quot;ariaLabel&quot;:&quot;Enlarge image: Configure Static IP Addresses using Netplan on Ubuntu&quot;,&quot;alt&quot;:&quot;Configure Static IP Addresses using Netplan on Ubuntu&quot;}\" data-wp-interactive=\"core\/image\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1066\" height=\"597\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/01\/static-ip-addresses-using-netplan.png\" alt=\"Configure Static IP Addresses using Netplan on Ubuntu\" class=\"wp-image-15345\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/01\/static-ip-addresses-using-netplan.png?v=1674892583 1066w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/01\/static-ip-addresses-using-netplan-768x430.png?v=1674892583 768w\" sizes=\"(max-width: 1066px) 100vw, 1066px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge image: Configure Static IP Addresses using Netplan on Ubuntu\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on-async--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"context.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"context.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<p>How to set static IP addresses using Netplan on Ubuntu? In this tutorial, you will learn how to configure static IP addresses using Netplan on Ubuntu 20.04\/18.04\/22.04. To manage network interfaces, recent versions of Ubuntu uses the Netplan utility. <a href=\"https:\/\/netplan.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Netplan<\/a>&nbsp;is a YAML network configuration abstraction for various back-ends.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#configuring-static-ip-addresses-using-netplan-on-ubuntu\">Configuring Static IP Addresses using Netplan on Ubuntu<\/a><ul><li><a href=\"#using-netplan-to-configure-static-ip-addresses-on-ubuntu\">Using Netplan to Configure Static IP Addresses on Ubuntu<\/a><\/li><li><a href=\"#other-tutorials\">Other Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"configuring-static-ip-addresses-using-netplan-on-ubuntu\">Configuring Static IP Addresses using Netplan on Ubuntu<\/h2>\n\n\n\n<p>The Netplan command has replaced the commonly used static interfaces IP address configuration file, <strong>\/etc\/network\/interfaces<\/strong>, with various network configuration files in the <strong>\/etc\/netplan\/<\/strong> directory. The files in this directory are in <strong>yaml<\/strong> format.<\/p>\n\n\n\n<p>On Ubuntu 18.04 server and later, networkd renderer is used to control network interfaces.<\/p>\n\n\n\n<p>If you need to connect to WiFi in Linux using NMCLI command, then you can check our guide by following the link below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/connect-to-wifi-in-linux-using-nmcli-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">Connect to WiFi in Linux Using NMCLI command<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-netplan-to-configure-static-ip-addresses-on-ubuntu\">Using Netplan to Configure Static IP Addresses on Ubuntu<\/h3>\n\n\n\n<p>Before we proceed to configure static IP address on an interface on Ubuntu 20.04\/18.04 Server, let us have a look at the format of the default netplan configuration file, <strong>\/etc\/netplan\/01-netcfg.yaml<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>less \/etc\/netplan\/01-netcfg.yaml<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n# This file describes the network interfaces available on your system\n# For more information, see netplan(5).\nnetwork:\n  version: 2\n  renderer: networkd\n  ethernets:\n    enp0s3:\n    dhcp4: yes\n<\/code><\/pre>\n\n\n\n<p>From the above output, DHCP is enabled for interface enp0s3 and is thus relying on DHCP server for IP addresses assignment.<\/p>\n\n\n\n<p>To <a href=\"https:\/\/lightyear.ai\/blogs\/ultimate-guide-to-static-ips-use-cases-costs-ipv4-vs-ipv6-and-much-more\" target=\"_blank\" rel=\"noreferrer noopener\">set static IP address<\/a> on an interface using Netplan on Ubuntu, we will use the same format as in the output of the configuration file above.<\/p>\n\n\n\n<p>We will have to disable the DHCP server for our interface along with adding other details as shown below. In the example below, we will configure <strong>enp0s8<\/strong> interface as follows;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>static IP address 192.168.59.81<\/li>\n\n\n\n<li>netmask 255.255.255.0<\/li>\n\n\n\n<li>gateway 192.168.59.1<\/li>\n\n\n\n<li>nameserver 1.1.1.1, 4.2.2.2.<\/li>\n<\/ul>\n\n\n\n<p>To reduce too much work, we will just copy the above configuration file and do some modification.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp \/etc\/netplan\/{01,02}-netcfg.yaml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/netplan\/02-netcfg.yaml<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n# This file describes the network interfaces available on your system\n# For more information, see netplan(5).\nnetwork:\n  version: 2\n  renderer: networkd\n  ethernets:\n    enp0s8:\n      dhcp4: no\n      addresses: [192.168.59.81\/24]\n      routes:\n        - to: 0.0.0.0\/0\n          via: 192.168.59.1\n      nameservers:\n        addresses: [1.1.1.1,4.2.2.2]\n<\/code><\/pre>\n\n\n\n<p>Save the configuration file and apply the changes using the command below.<\/p>\n\n\n\n<p>Before you can save the changes, first of all check if any error with configuration;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>netplan try<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nDo you want to keep these settings?\n\n\nPress ENTER before the timeout to accept the new configuration\n\n\nChanges will revert in 107 seconds\n\n<\/code><\/pre>\n\n\n\n<p>If there is any error, it will be printed out. Otherwise, you will be asked to Press ENTER to save changes before timeout is reached.<\/p>\n\n\n\n<p>You can as well cancel the above and apply changes using;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>netplan apply<\/code><\/pre>\n\n\n\n<p>Check the IP add on the enp0s8 interface to confirm the assignment.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ip add show enp0s8<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n4: enp0s8: &lt;BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000\n   link\/ether 08:00:27:87:d4:14 brd ff:ff:ff:ff:ff:ff\n   inet <strong>192.168.59.81\/24<\/strong> brd 192.168.59.255 scope global enp0s8\n      valid_lft forever preferred_lft forever\n   inet6 fe80::a00:27ff:fe87:d414\/64 scope link\n       valid_lft forever preferred_lft forever\n<\/code><\/pre>\n\n\n\n<p>As you can see, the IP address is assigned.<\/p>\n\n\n\n<p>If you want to assign different IPs to different interfaces in the same configuration file, you can do so as follows.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vim \/etc\/netplan\/02-netcfg.yaml<\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n# This file describes the network interfaces available on your system\n# For more information, see netplan(5).\nnetwork:\n  version: 2\n  renderer: networkd\n  ethernets:\n    enp0s8:\n      dhcp4: no\n      addresses: [192.168.59.81\/24]\n      routes:\n        - to: 192.168.59.0\/24\n          via: 192.168.59.1\n      nameservers:\n        search: example.com\n        addresses: [1.1.1.1,4.2.2.2]\n    enp0s9:\n      dhcp4: no\n      addresses: [192.168.58.92\/24]\n      routes:\n        - to: 192.168.58.0\/24\n          via: 192.168.58.1\n      nameservers:\n        addresses: [1.1.1.1,4.2.2.2]\n<\/code><\/pre>\n\n\n\n<p>Once done with configuration, remember to run the <code>netplan apply<\/code> command to apply the changes and bring the interfaces up.<\/p>\n\n\n\n<p>That is all about how to configure Static IP Addresses using Netplan on Ubuntu.<\/p>\n\n\n\n<p>See also;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/set-static-routes-via-an-interface-ip-on-centos-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Set Static Routes via an Interface\/IP on CentOS\/Ubuntu<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"other-tutorials\">Other Tutorials<\/h3>\n\n\n\n<p><a title=\"Install and Setup Kolide Fleet on Ubuntu 18.04\" href=\"https:\/\/kifarunix.com\/install-and-setup-kolide-fleet-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"bookmark noopener noreferrer\">Install and Setup Kolide Fleet on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-microsoft-teams-client-on-ubuntu-20-04-18-04\/\" target=\"_blank\" rel=\"noopener noreferrer\">Install Microsoft Teams Client on Ubuntu 20.04\/18.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-zoom-client-on-ubuntu-20-04\/\" target=\"_blank\" rel=\"noopener noreferrer\">Install Zoom Client on Ubuntu 20.04<\/a><\/p>\n\n\n\n<p><a title=\"Install and Setup Kolide Fleet on Ubuntu 18.04\" href=\"https:\/\/kifarunix.com\/install-and-setup-kolide-fleet-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"bookmark noopener noreferrer\">Install and Setup Kolide Fleet on Ubuntu 18.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to set static IP addresses using Netplan on Ubuntu? In this tutorial, you will learn how to configure static IP addresses using Netplan on<\/p>\n","protected":false},"author":1,"featured_media":15345,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[64,68,63],"tags":[6328,65,1500,6326,1498,66,1499,67,1200,6327],"class_list":["post-334","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu-18-04","category-netplan","category-networking","tag-configure-static-ip-addresses-using-netplan-on-ubuntu","tag-netplan","tag-netplan-ubuntu-20-04-18-04","tag-set-static-ip-address-using-netplan-on-ubuntu","tag-set-static-ip-using-netplan","tag-static-ip","tag-static-ip-address-ubuntu-20-04","tag-ubuntu-18-04","tag-ubuntu-20-04","tag-ubuntu-netplan-ip-address-configuration","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/334"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=334"}],"version-history":[{"count":13,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/334\/revisions"}],"predecessor-version":[{"id":20961,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/334\/revisions\/20961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/15345"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}