{"id":2293,"date":"2020-06-09T21:36:53","date_gmt":"2020-06-09T13:36:53","guid":{"rendered":"https:\/\/www.wesbytes.com\/guide\/?post_type=kb&#038;p=2293"},"modified":"2025-12-29T14:44:00","modified_gmt":"2025-12-29T06:44:00","slug":"how-to-configure-static-ip-address-on-ubuntu-18-04","status":"publish","type":"kb","link":"https:\/\/www.servergigabit.com\/guide\/kb\/how-to-configure-static-ip-address-on-ubuntu-18-04","title":{"rendered":"How to Configure Static IP Address on Ubuntu 18.04"},"content":{"rendered":"<div class=\"code-label\">\n<p>In this article, we will clarify how to set up a static IP address on <a href=\"https:\/\/ubuntu.com\/\" target=\"_blank\" rel=\"noopener\">Ubuntu<\/a> 18.04.<\/p>\n<p>The IP addresses allocated to your DHCP service router. In various cases, such as setting up a port forwarding or running a media server on your network, it might be appropriate to create a static IP address on your Ubuntu machine.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h2 id=\"configuring-static-ip-address-using-dhcp\" class=\"anchor mkb-anchor__title\" aria-hidden=\"true\">Configuring Static IP address using DHCP<\/h2>\n<p>&nbsp;<\/p>\n<\/div>\n<p>The easiest and most recommended way to assign a static IP address to a device on your LAN is to set up a static DHCP on your router. The feature found on most routers is Static DHCP or DHCP Reservation . It causes the DHCP server to automatically assign the same IP address to a specific network device each time the device requests an address from the DHCP server. This works by assigning a static IP to the specific MAC address of the computer. The steps to configure a DHCP reservation vary from router to router and it is best to review the vendor&#8217;s documentation.<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h2 id=\"netplan\" class=\"anchor mkb-anchor__title\" aria-hidden=\"true\">Netplan<\/h2>\n<p>&nbsp;<\/p>\n<\/div>\n<p>Starting with 17.10 release,\u00a0Netplan\u00a0is the default network management tool on Ubuntu, replacing the configuration file\u00a0<code>\/etc\/network\/interfaces<\/code>\u00a0that had previously been used to configure the network on Ubuntu.<\/p>\n<p>Netplan uses configuration files with YAML syntax. To configure a network interface with Netplan you simply create a\u00a0YAML\u00a0description for that interface and Netplan generates the required configuration files for your chosen renderer tool.<\/p>\n<p>Netplan currently supports two renderers NetworkManager and Systemd-networkd.\u00a0<span class=\"word\">NetworkManager\u00a0<\/span><span class=\"word\">is\u00a0<\/span><span class=\"word\">mostly\u00a0<\/span><span class=\"word\">used\u00a0<\/span><span class=\"word\">on\u00a0<\/span><span class=\"word\">desktop\u00a0<\/span><span class=\"word\">machines,\u00a0<\/span><span class=\"word\">while\u00a0<\/span><span class=\"word\">System-network\u00a0<\/span><span class=\"word\">is\u00a0<\/span><span class=\"word\">used\u00a0<\/span><span class=\"word\">without\u00a0<\/span><span class=\"word\">a\u00a0<\/span><span class=\"word\">GUI\u00a0<\/span><span class=\"word\">on\u00a0<\/span><span class=\"word\">servers.<\/span><\/p>\n<p>&nbsp;<\/p>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h2 id=\"configuring-static-ip-address-on-ubuntu-server\" class=\"anchor mkb-anchor__title\" aria-hidden=\"true\">Configuring Static IP address on Ubuntu Server<\/h2>\n<p>&nbsp;<\/p>\n<\/div>\n<p><span id=\"ezoic-pub-ad-placeholder-159\" class=\"ezoic-adpicker-ad\"><\/span>The newer\u00a0versions of Ubuntu\u00a0uses \u2018Predictable Network Interface Names\u2019 that start with\u00a0<code>en[letter][number]<\/code>. by default. The first step is to identify the name of the ethernet interface you want to configure. You can use the\u00a0ip link command\u00a0as shown below:<span id=\"ezoic-pub-ad-placeholder-140\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<pre class=\"console-bash\"><code class=\"language-console-bash\" data-lang=\"console-bash\"><span class=\"line\">ip link\r\n<\/span><\/code><\/pre>\n<p>The command will print a list of all the available network interfaces. In this case, the name of the interface is\u00a0<code>ens3<\/code>:<\/p>\n<pre><code class=\"language-output\" data-lang=\"output\">1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000\r\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\r\n3: ens3: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000\r\n    link\/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff\r\n<\/code><\/pre>\n<p>Netplan configuration files are stored in the\u00a0<code>\/etc\/netplan<\/code>\u00a0directory and have the extension\u00a0<code>.yaml<\/code>. You\u2019ll probably find one or two YAML files in this directory. The file may differ from setup to setup. Usually, the file is named either\u00a0<code>01-netcfg.yaml<\/code>,\u00a0<code>50-cloud-init.yaml<\/code>\u00a0or\u00a0<code>NN_interfaceName.yaml<\/code>, but in your system it may be different.<\/p>\n<p>Open the YAML configuration file with your\u00a0text editor:<\/p>\n<pre class=\"console-bash\"><code class=\"language-console-bash\" data-lang=\"console-bash\"><span class=\"line\">sudo nano \/etc\/netplan\/01-netcfg.yaml\r\n<\/span><\/code><\/pre>\n<div class=\"code-label\">\/etc\/netplan\/01-netcfg.yaml<\/div>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-yaml\" data-lang=\"yaml\">network<span class=\"p\">:<\/span>\r\n  version<span class=\"p\">:<\/span> <span class=\"m\">2<\/span>\r\n  renderer<span class=\"p\">:<\/span> networkd\r\n  ethernets<span class=\"p\">:<\/span>\r\n    ens3<span class=\"p\">:<\/span>\r\n      dhcp4<span class=\"p\">:<\/span> yes<\/code><\/pre>\n<\/div>\n<div>Copy<\/div>\n<div><\/div>\n<p><span class=\"word\">Let\u2019s\u00a0<\/span><span class=\"word\">explain\u00a0<\/span><span class=\"word\">the\u00a0<\/span><span class=\"word\">code\u00a0<\/span><span class=\"word\">in\u00a0<\/span><span class=\"word\">a\u00a0<\/span><span class=\"word\">short\u00a0<\/span><span class=\"word\">time\u00a0<\/span><span class=\"word\">before\u00a0<\/span><span class=\"word\">changing\u00a0<\/span><span class=\"word\">the\u00a0<\/span><span class=\"word\">configuration.<\/span><br \/>\nEach Netplan Yaml file starts with the\u00a0<code>network<\/code>\u00a0key that has at least two required elements. The first required element is the version of network configuration format and the second one is the device type. Device types values can be\u00a0<code>ethernets<\/code>,\u00a0<code>bonds<\/code>,\u00a0<code>bridges<\/code>, and\u00a0<code>vlans<\/code>.<\/p>\n<p>The configuration above also includes the\u00a0<code>renderer<\/code>\u00a0type. Out of the box, if you installed Ubuntu in server mode the renderer is configured to use\u00a0<code>networkd<\/code>\u00a0as the back end.<span id=\"ezoic-pub-ad-placeholder-160\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<p>Under the device\u2019s type ( in this case\u00a0<code>ethernets<\/code>) we can specify one or more network interfaces. In this example we have only one interface\u00a0<code>ens3<\/code>\u00a0that is configured to obtain IP addressing from a DHCP server\u00a0<code>dhcp4: yes<\/code>.<\/p>\n<p>To assign a static IP address to\u00a0<code>ens3<\/code>\u00a0interface edit the file as follows:<\/p>\n<ul>\n<li>Firstly, Set DHCP to no <code>dhcp4: yes<\/code><\/li>\n<li>Further, Specify the static IP address <code>192.168.121.199\/24<\/code>. Under\u00a0<code>addresses:<\/code>\u00a0you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.<\/li>\n<li>Specify the gateway <code>gateway4: 192.168.121.1<\/code><\/li>\n<li>Lastly, specify the nameservers <code>addresses: [8.8.8.8, 1.1.1.1]\u00a0<\/code>Under <code>nameservers<\/code>,<code><\/code><\/li>\n<\/ul>\n<div class=\"code-label\">\/etc\/netplan\/01-netcfg.yaml<\/div>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-yaml\" data-lang=\"yaml\">network<span class=\"p\">:<\/span>\r\n  version<span class=\"p\">:<\/span> <span class=\"m\">2<\/span>\r\n  renderer<span class=\"p\">:<\/span> networkd\r\n  ethernets<span class=\"p\">:<\/span>\r\n    ens3<span class=\"p\">:<\/span>\r\n<span class=\"hl\">      dhcp4<span class=\"p\">:<\/span> no\r\n<\/span><span class=\"hl\">      addresses<span class=\"p\">:<\/span>\r\n<\/span><span class=\"hl\">        - <span class=\"m\">192.168<\/span><span class=\"m\">.121<\/span><span class=\"m\">.199<\/span>\/<span class=\"m\">24<\/span>\r\n<\/span><span class=\"hl\">      gateway4<span class=\"p\">:<\/span> <span class=\"m\">192.168<\/span><span class=\"m\">.121<\/span><span class=\"m\">.1<\/span>\r\n<\/span><span class=\"hl\">      nameservers<span class=\"p\">:<\/span>\r\n<\/span><span class=\"hl\">          addresses<span class=\"p\">:<\/span> <span class=\"p\">[<\/span><span class=\"m\">8.8<\/span><span class=\"m\">.8<\/span><span class=\"m\">.8<\/span><span class=\"p\">,<\/span> <span class=\"m\">1.1<\/span><span class=\"m\">.1<\/span><span class=\"m\">.1<\/span><span class=\"p\">]<\/span><\/span><\/code><\/pre>\n<\/div>\n<p>Copy<\/p>\n<p><span class=\"word\">Make\u00a0<\/span><span class=\"word\">sure\u00a0<\/span><span class=\"word\">you\u00a0<\/span><span class=\"word\">follow\u00a0<\/span><span class=\"word\">the\u00a0<\/span><span class=\"word\">YAML\u00a0<\/span><span class=\"word\">code\u00a0<\/span><span class=\"word\">indent\u00a0<\/span><span class=\"word\">requirements\u00a0<\/span><span class=\"word\">when\u00a0<\/span><span class=\"word\">editing\u00a0<\/span><span class=\"word\">Yaml\u00a0<\/span><span class=\"word\">files\u00a0<\/span><span class=\"word\">as\u00a0<\/span><span class=\"word\">it\u00a0<\/span><span class=\"word\">may\u00a0<\/span><span class=\"word\">not\u00a0<\/span><span class=\"word\">work\u00a0<\/span><span class=\"word\">if\u00a0<\/span><span class=\"word\">the\u00a0<\/span><span class=\"word\">configuration\u00a0<\/span><span class=\"word\">includes\u00a0<\/span><span class=\"word\">a\u00a0<\/span><span class=\"word\">syntax\u00a0<\/span><span class=\"word\">error.<\/span><\/p>\n<p><span class=\"word\">After saved and closed\u00a0 the file <\/span><span class=\"word\">and applied<\/span><span class=\"word\">\u00a0<\/span><span class=\"word\">the\u00a0<\/span><span class=\"word\">changes with:<\/span><\/p>\n<pre class=\"console-bash\"><code class=\"language-console-bash\" data-lang=\"console-bash\"><span class=\"line\">sudo netplan apply\r\n<\/span><\/code><\/pre>\n<p>Verify the changes by typing:<\/p>\n<pre class=\"console-bash\"><code class=\"language-console-bash\" data-lang=\"console-bash\"><span class=\"line\">ip addr show dev ens3\r\n<\/span><\/code><\/pre>\n<pre><code class=\"language-output\" data-lang=\"output\">3: ens3: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq state UP group default qlen 1000\r\n    link\/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff\r\n    inet 192.168.121.199\/24 brd 192.168.121.255 scope global dynamic ens3\r\n       valid_lft 3575sec preferred_lft 3575sec\r\n    inet6 fe80::5054:ff:feb0:f500\/64 scope link \r\n       valid_lft forever preferred_lft forever\r\n<\/code><\/pre>\n<p>That\u2019s it! You have assigned a static IP to your Ubuntu server.<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"mkb-anchor mkb-clearfix mkb-back-to-top-inline\">\n<h3 id=\"configuring-static-ip-address-on-ubuntu-desktop\" class=\"anchor mkb-anchor__title\" aria-hidden=\"true\">Configuring Static IP address on Ubuntu Desktop<\/h3>\n<\/div>\n<p>Setting up a static IP address on Ubuntu Desktop computers requires no technical knowledge.<\/p>\n<p>1.Firstly,\u00a0 search for \u201cnetwork\u201d and click on the Network icon in the Activities screen,. This will open the GNOME Network configuration settings. Click on the cog icon.<\/p>\n<p>&nbsp;<\/p>\n<p>2. This will open the Network interface settings dialog box.<\/p>\n<p>&nbsp;<\/p>\n<p>3. In \u201cIPV4\u201d Method\u201d section select \u201cManual\u201d, and enter your static IP address, Netmask and Gateway.\u00a0<span class=\"word\">Click\u00a0<\/span><span class=\"word\">on\u00a0<\/span><span class=\"word\">the\u00a0<\/span><span class=\"word\">\u201cApply\u201d\u00a0<\/span><span class=\"word\">button\u00a0<\/span><span class=\"word\">once\u00a0<\/span><span class=\"word\">completed.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>After you have set up a static IP Address, open your terminal either by using the <code>Ctrl+Alt+T<\/code>\u00a0keyboard shortcut or by clicking on the terminal icon and verify the changes by typing:<span id=\"ezoic-pub-ad-placeholder-157\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<pre class=\"console-bash\"><code class=\"language-console-bash\" data-lang=\"console-bash\"><span class=\"line\">ip addr\r\n<\/span><\/code><\/pre>\n<p>The output will show the interface IP address:<span id=\"ezoic-pub-ad-placeholder-145\" class=\"ezoic-adpicker-ad\"><\/span><\/p>\n<pre><code class=\"language-output\" data-lang=\"output\">...\r\n2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel state UP group default qlen 1000\r\n    link\/ether 52:54:00:e9:40:f2 brd ff:ff:ff:ff:ff:ff\r\n    inet 192.168.121.106\/24 brd 192.168.121.255 scope global dynamic noprefixroute eth0\r\n       valid_lft 3523sec preferred_lft 3523sec\r\n    inet6 fe80::5054:ff:fee9:40f2\/64 scope link \r\n       valid_lft forever preferred_lft forever<\/code><\/pre>\n<p>In conclusion,, You have learned how to assign a static IP address on your Ubuntu 18.04 machine. If you have any question, please leave a comment below<\/p>\n<p>Please refer to the following articles <a href=\"https:\/\/www.servergigabit.com\/guide\/kb\/how-to-set-up-private-nameserver-for-linux-server\/\">How to set up private nameserver for Linux server<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will clarify how to set up a static IP address on Ubuntu 18.04. The IP addresses allocated to your DHCP service router. In various cases, such as setting up a port forwarding or running a media server on your network, it might be appropriate to create a static IP address on your Ubuntu machine. &nbsp; Configuring&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"kbtopic":[56],"kbtag":[1273,1109],"class_list":["post-2293","kb","type-kb","status-publish","hentry","kbtopic-ubuntu","kbtag-ip-address","kbtag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/2293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/comments?post=2293"}],"version-history":[{"count":5,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/2293\/revisions"}],"predecessor-version":[{"id":4459,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/2293\/revisions\/4459"}],"wp:attachment":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/media?parent=2293"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=2293"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtag?post=2293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}