{"id":16,"date":"2020-07-18T10:32:53","date_gmt":"2020-07-18T10:32:53","guid":{"rendered":"https:\/\/iste.umldb.com\/web-server-management\/?p=16"},"modified":"2020-07-18T10:35:23","modified_gmt":"2020-07-18T10:35:23","slug":"static-ip-address-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/iste.umldb.com\/web-server-management\/2020\/07\/18\/static-ip-address-ubuntu-20-04\/","title":{"rendered":"Static IP Address Ubuntu 20.04"},"content":{"rendered":"\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Configure Static IPv4 Address Ubuntu 20.04\" width=\"960\" height=\"720\" src=\"https:\/\/www.youtube.com\/embed\/sBe0cRGWauI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><figcaption>How to configure a static IPv4 address on Ubuntu 20.04<\/figcaption><\/figure>\n\n\n\n<p>I will warn you in advance that the setup of a static IP address on a Linux Ubuntu server will vary greatly depending on which version of the operating system you are using and how the version came to be.  An Ubuntu installation that started life as Ubuntu 12 and has been upgraded every 2 years is going to have a different IP address configuration process compared to a new installation or even an installation of Ubuntu 18 followed by an upgrade!<\/p>\n\n\n\n<p>The tutorial presented in the video and described here is based on a &#8220;clean install&#8221; of the Ubuntu Server 20.04 live ISO.  I will add additional posts for other versions as I get the time but initially I am providing only Ubuntu 20.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul><li>Working Ubuntu 20 and a user account that is in the sudo group.<\/li><li>Basic file editing (nano, vi, etc)<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Netplan<\/h2>\n\n\n\n<p>In Ubuntu 20.04 the IP address configuration is based on &#8220;netplan&#8221; which is a package where you write your IP address configuration in a language called <a href=\"https:\/\/yaml.org\/\">YAML<\/a> (luckily you do not actually need to go and read this).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Your Ethernet Device?<\/h3>\n\n\n\n<p>Before beginning you need to know the name of the network interface on your machine which normally will be of the form ethN or enpNsN (where N is a number).<\/p>\n\n\n\n<p>On Ubuntu, you can use the &#8220;ip addr&#8221; to list the interfaces.  You can also search the kernel ring buffer for the device <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Sample 1:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">1: lo: &lt;LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\n\u00a0 \u00a0 link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n\u00a0 \u00a0 inet 127.0.0.1\/8 scope host lo\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n\u00a0 \u00a0 inet6 ::1\/128 scope host\u00a0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000\n\u00a0 \u00a0 link\/ether 00:15:5d:64:13:2b brd ff:ff:ff:ff:ff:ff\n\u00a0 \u00a0 inet 192.168.68.12\/24 brd 192.168.68.255 scope global eth0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n\u00a0 \u00a0 inet6 fe80::215:5dff:fe64:132b\/64 scope link\u00a0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n<\/pre>\n\n\n\n<p>In this example, there is a single device called &#8220;eth0&#8221;.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Sample 2:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">1: lo: &lt;LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1\n\u00a0 \u00a0 link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n\u00a0 \u00a0 inet 127.0.0.1\/8 scope host lo\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n\u00a0 \u00a0 inet6 ::1\/128 scope host\u00a0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n2: enp1s0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n\u00a0 \u00a0 link\/ether 70:e1:4c:68:38:86 brd ff:ff:ff:ff:ff:ff\n\u00a0 \u00a0 inet 192.168.100.9\/24 brd 192.168.100.255 scope global enp1s0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n\u00a0 \u00a0 inet6 fe80::72e1:4cff:fe68:3886\/64 scope link\u00a0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n3: enp2s0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n\u00a0 \u00a0 link\/ether 70:e1:4c:68:38:87 brd ff:ff:ff:ff:ff:ff\n\u00a0 \u00a0 inet 192.168.68.1\/24 brd 192.168.68.255 scope global enp2s0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n\u00a0 \u00a0 inet6 fe80::72e1:4cff:fe68:3887\/64 scope link\u00a0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n4: wlp3s0: &lt;BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000\n\u00a0 \u00a0 link\/ether 8c:70:5a:95:a5:20 brd ff:ff:ff:ff:ff:ff<\/pre>\n\n\n\n<p>This particular example is more complex since there are two wired interfaces and one wireless.  The two wired interfaces are called enp1s0 and enp2s0.  If you search the kernel ring buffer (using &#8220;dmesg | grep eth&#8221;) you get the following details:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>robert@gate<\/strong>:<strong>~<\/strong>$ dmesg | grep eth\n[\u00a0 \u00a0 1.930793] r8169 0000:01:00.0 <strong>eth<\/strong>0: RTL8168evl\/8111evl at 0xffffc9000075a000, 70:e1:4c:68:38:86, XID 0c900800 IRQ 89\n[\u00a0 \u00a0 1.930796] r8169 0000:01:00.0 <strong>eth<\/strong>0: jumbo features [frames: 9200 bytes, tx checksumming: ko]\n[\u00a0 \u00a0 1.931566] r8169 0000:02:00.0 <strong>eth<\/strong>1: RTL8168evl\/8111evl at 0xffffc9000075c000, 70:e1:4c:68:38:87, XID 0c900800 IRQ 90\n[\u00a0 \u00a0 1.931569] r8169 0000:02:00.0 <strong>eth<\/strong>1: jumbo features [frames: 9200 bytes, tx checksumming: ko]\n[\u00a0 \u00a0 2.021611] r8169 0000:02:00.0 enp2s0: renamed from <strong>eth<\/strong>1\n[\u00a0 \u00a0 2.036777] r8169 0000:01:00.0 enp1s0: renamed from <strong>eth<\/strong>0<\/pre>\n\n\n\n<p>From the kernel buffer we see that eth0 and eth1 are first detected but then renamed to enp1s0 and enp2s0.  This renaming of the interfaces was found in Ubuntu 16, but it seems to have gone away since Ubuntu 18.  If you are working on a server that started life as Ubuntu 16 and somebody ran an upgrade to Ubuntu 18 or Ubuntu 20, you can expect these &#8220;enp&#8221; renaming.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Configuration File<\/h4>\n\n\n\n<p>The main configuration file is located at \/etc\/netplan\/00-installer-config.yaml. You can edit this with any text editor (the video demonstrates using the nano editor).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Default File<\/h4>\n\n\n\n<p>The initial file created by the installation is set up to pick up an IP address from the DHCP server on the local area network.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">network:\n\u00a0 ethernets:\n\u00a0 \u00a0 eth0:\n\u00a0 \u00a0 \u00a0 dhcp4: true\n\u00a0 version: 2<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">IPv4 Configuration<\/h4>\n\n\n\n<p>Below sets the eth0 device to have IP addresses 192.168.68.12 and 192.168.68.13 with subnet mask 255.255.255.0.  You of course can set just a single value but I will be using the multiple IP addresses later in the Apache2 configuration section.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">network:\n\u00a0 ethernets:\n\u00a0 \u00a0 eth0:\n\u00a0 \u00a0 \u00a0 dhcp4: false\n\u00a0 \u00a0 \u00a0 addresses: [192.168.68.12\/24, 192.168.68.13\/24]\n\u00a0 \u00a0 \u00a0 gateway4: 192.168.68.1\n\u00a0 \u00a0 \u00a0 nameservers:\n\u00a0\u00a0 \u00a0 \u00a0 \u00a0 addresses: [192.168.68.1]\n\u00a0 version: 2<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">IPv6 Configuration<\/h4>\n\n\n\n<p>My ISP doesn&#8217;t currently provide any IPv6 support so I don&#8217;t have any ready made examples but I&#8217;ve added a place holder to my road map to remind myself that I need to write a tutorial.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Apply the Configuration<\/h4>\n\n\n\n<p>Once the configuration file has been saved, you can use the command:  &#8220;netplan apply&#8221; to set the ip address.  <\/p>\n\n\n\n<p>Once set, use the &#8220;ip addr&#8221; to verify the settings.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">root@wsmdemo:\/etc\/netplan# ip addr\n1: lo: &lt;LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\n\u00a0 \u00a0 link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n\u00a0 \u00a0 inet 127.0.0.1\/8 scope host lo\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n\u00a0 \u00a0 inet6 ::1\/128 scope host\u00a0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000\n\u00a0 \u00a0 link\/ether 00:15:5d:64:13:2b brd ff:ff:ff:ff:ff:ff\n\u00a0 \u00a0 inet 192.168.68.12\/24 brd 192.168.68.255 scope global eth0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n\u00a0 \u00a0 inet 192.168.68.13\/24 brd 192.168.68.255 scope global secondary eth0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever\n\u00a0 \u00a0 inet6 fe80::215:5dff:fe64:132b\/64 scope link\u00a0\n\u00a0\u00a0 \u00a0 \u00a0 valid_lft forever preferred_lft forever<\/pre>\n\n\n\n<p>Of course you should also try pinging these ip addresses from another computer on your network and try connecting using ssh to your server.<\/p>\n\n\n\n<p>Other Ubuntu Versions?<\/p>\n\n\n\n<p>Do you have another version of Ubuntu besides 20?  Check the roadmap page and see if I have created a page for setting the static IP address.  I will eventually write one page for everything.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I will warn you in advance that the setup of a static IP address on a Linux Ubuntu server will vary greatly depending on which version of the operating system you are using and how the version came to be. An Ubuntu installation that started life as Ubuntu 12 and has been upgraded every 2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/posts\/16"}],"collection":[{"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iste.umldb.com\/web-server-management\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}