{"id":1191,"date":"2021-06-15T11:14:36","date_gmt":"2021-06-15T11:14:36","guid":{"rendered":"https:\/\/thecloudwiki.com\/?p=1191"},"modified":"2021-06-20T10:01:14","modified_gmt":"2021-06-20T10:01:14","slug":"how-to-assign-static-ip-address-on-ubuntu-21-04","status":"publish","type":"post","link":"https:\/\/thecloudwiki.com\/?p=1191","title":{"rendered":"How to assign static IP address on Ubuntu 21.04"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_90 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6b0417438436f\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6b0417438436f\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/thecloudwiki.com\/?p=1191\/#Step-1_Identify_the_ethernet_interface_name\" >Step-1 : Identify the ethernet interface name<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/thecloudwiki.com\/?p=1191\/#Step-2_Choose_the_IP\" >Step-2 : Choose the IP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/thecloudwiki.com\/?p=1191\/#Step-3_Assign_the_IP_by_editing_the_config_YAML\" >Step-3 :  Assign the IP by editing the config YAML<\/a><\/li><\/ul><\/nav><\/div>\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-1_Identify_the_ethernet_interface_name\"><\/span><strong>Step-1<\/strong> : <strong><span style=\"text-decoration: underline\" class=\"underline\">Identify the ethernet interface name<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ip link<\/strong>   &#8211;&gt; From the below example Interface name is <strong>enp0s3<\/strong><br>Now we will assign the IP to this interface<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sandeepsr@master:~$ <strong>ip link<\/strong>\n 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000\n     link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n 2: enp0s3:  mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000\n     link\/ether 08:00:27:49:8e:45 brd ff:ff:ff:ff:ff:ff<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-2_Choose_the_IP\"><\/span><strong>Step-2<\/strong> : <strong><span style=\"text-decoration: underline\" class=\"underline\">Choose the IP<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">For this example I will use the IP already assigned by DHCP which is 192.168.0.107<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sandeepsr@master:~$ <strong>ip addr show<\/strong>\n 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\n     link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n     inet 127.0.0.1\/8 scope host lo\n        valid_lft forever preferred_lft forever\n     inet6 ::1\/128 scope host\n        valid_lft forever preferred_lft forever\n <strong>2: enp0s3:  mtu 1500 qdisc fq_codel state UP group default qlen 1000\n     link\/ether 08:00:27:49:8e:45 brd ff:ff:ff:ff:ff:ff\n     inet 192.168.0.107\/24 brd 192.168.0.255 scope global dynamic enp0s3\n        valid_lft 5974sec preferred_lft 5974sec\n     inet6 fe80::a00:27ff:fe49:8e45\/64 scope link\n        valid_lft forever preferred_lft forever<\/strong><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step-3_Assign_the_IP_by_editing_the_config_YAML\"><\/span><strong>Step-3 :  <span style=\"text-decoration: underline\" class=\"underline\">Assign the IP by editing the config YAML<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Since am using Ubuntu 21.04 the config YAML stored in <strong>\/etc\/netplan<\/strong>\/ folder<br>and the file name is <strong>00-installer-config.yaml<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since this server already assigned with DHCP the file looks as below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sandeepsr@master:~$ <strong>cat \/etc\/netplan\/00-installer-config.yaml<\/strong>\n This is the network config written by 'subiquity'\n<strong> network:\n   ethernets:\n     enp0s3:\n       dhcp4: true\n   version: 2<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So we need to add IP address , gateway &amp; DNS to the above file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the file as below. please make sure follow the correct indentation <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sandeepsr@master:~$<strong>sudo vim \/etc\/netplan\/00-installer-config.yaml<\/strong>\nThis is the network config written by 'subiquity'\n<strong> network:\n   ethernets:\n     enp0s3:\n       dhcp4: no\n       addresses:\n         - 192.168.0.107\/24\n       gateway4: 192.168.0.1\n       nameservers:\n         addresses: [8.8.8.8, 4.4.4.4]\n   version: 2<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And apply the changes by running below command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sandeepsr@master:~$ <strong>sudo netplan apply<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Static IP was set and you can see the same below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sandeepsr@master:~$ <strong>ip addr show<\/strong>\n 1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\n     link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n     inet 127.0.0.1\/8 scope host lo\n        valid_lft forever preferred_lft forever\n     inet6 ::1\/128 scope host\n        valid_lft forever preferred_lft forever\n<strong> 2: enp0s3:  mtu 1500 qdisc fq_codel state UP group default qlen 1000\n     link\/ether 08:00:27:49:8e:45 brd ff:ff:ff:ff:ff:ff\n     inet 192.168.0.107\/24 brd 192.168.0.255 scope global enp0s3\n        valid_lft forever preferred_lft forever\n     inet6 fe80::a00:27ff:fe49:8e45\/64 scope link\n        valid_lft forever preferred_lft forever<\/strong><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Step-1 : Identify the ethernet interface name ip link &#8211;&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1267,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25],"tags":[17],"class_list":["post-1191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux"],"uagb_featured_image_src":{"full":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2021\/06\/Ubuntu-staticIP-feature-image-e1624183265832.png",400,195,false],"thumbnail":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2021\/06\/Ubuntu-staticIP-feature-image-150x150.png",150,150,true],"medium":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2021\/06\/Ubuntu-staticIP-feature-image-300x146.png",300,146,true],"medium_large":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2021\/06\/Ubuntu-staticIP-feature-image-768x373.png",768,373,true],"large":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2021\/06\/Ubuntu-staticIP-feature-image-1024x498.png",1024,498,true],"1536x1536":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2021\/06\/Ubuntu-staticIP-feature-image-e1624183265832.png",400,195,false],"2048x2048":["https:\/\/thecloudwiki.com\/wp-content\/uploads\/2021\/06\/Ubuntu-staticIP-feature-image-e1624183265832.png",400,195,false]},"uagb_author_info":{"display_name":"Sandeep","author_link":"https:\/\/thecloudwiki.com\/?author=1"},"uagb_comment_info":0,"uagb_excerpt":"Step-1 : Identify the ethernet interface name ip link &#8211;&gt; [&hellip;]","_links":{"self":[{"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/1191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1191"}],"version-history":[{"count":4,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/1191\/revisions"}],"predecessor-version":[{"id":1269,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/posts\/1191\/revisions\/1269"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=\/wp\/v2\/media\/1267"}],"wp:attachment":[{"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecloudwiki.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}