Configure Static IP Address on Ubuntu 18.04

Last modified: April 1, 2020
You are here:
Estimated reading time: 3 min

In this tutorial, we’ll explain how to set up a static IP address on Ubuntu 18.04.

Your router DHCP server dynamically assigns the IP addresses.

In different situations such as configuring port forwarding or running media server on your network, it may be necessary to set static IP address on your Ubuntu computer.

The easiest and the recommended way to assign a static IP address to a device on your LAN is by setting up a Static DHCP on your router. Static DHCP or DHCP reservation is a feature found on most routers. In addition, it makes the DHCP server to automatically assign the same IP address to a specific network device, every time the device requests an address from the DHCP server. This works by assigning a static IP to the device unique MAC address. The steps for configuring a DHCP reservation varies from router to router and it’s advisable to consult the vendor’s documentation.

Starting with 17.10 release, Netplan is the default network management tool on Ubuntu, replacing the configuration file /etc/network/interfaces that had previously been used to configure the network on Ubuntu.

Netplan uses configuration files with YAML syntax. Then, to configure a network interface with Netplan you simply create a YAML description for that interface and Netplan generates the required configuration files for your chosen renderer tool.

Netplan currently supports two renderers NetworkManager and Systemd-networkd. NetworkManager is mostly used on desktop machines, while System-network is used without GUI on servers.

The newer versions of Ubuntu uses ‘Predictable Network Interface Names’ that start with en[letter][number]. by default. The first step is to identify the name of the ethernet interface you want to configure. You can use the ip link command as shown below:

ip link

The command will print a list of all the available network interfaces. In this case, the name of the interface is ens3:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff

Netplan configuration files are stored in the /etc/netplan directory and have the extension .yaml. You’ll probably find one or two YAML files in this directory. The file may differ from setup to setup. Usually, the file is named either 01-netcfg.yaml50-cloud-init.yaml or NN_interfaceName.yaml, but in your system it may be different.

Firstly, open the YAML configuration file with your text editor:

sudo nano /etc/netplan/01-netcfg.yaml
  version: 2
  renderer: networkd
      dhcp4: yes

Let’s explain the code in short time before changing the configuration.

Each Netplan Yaml file starts with the network key that has at least two required elements. The first element is the version of network configuration format and the second one is the device type. Device types values can be ethernetsbondsbridges, and vlans.

The configuration above also includes the renderer type. Out of the box, if you installed Ubuntu in server mode the renderer is configured to use networkd as the back end.

Moreover, under the device’s type ( in this case ethernets) we can specify one or more network interfaces. In this example we have only one interface ens3 that is configured to obtain IP addressing from a DHCP server dhcp4: yes.

To assign a static IP address to ens3 interface edit the file as follows:

  • Set DHCP to no dhcp4: yes
  • Specify the static IP address Under addresses: you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.
  • Specify the gateway gateway4:
  • Under nameservers, specify the nameservers addresses: [,]
  version: 2
  renderer: networkd
      dhcp4: no
          addresses: [,]

First of all, make sure you follow the YAML code indent requirements when editing Yaml files as it may not work if the configuration includes syntax error.

Once the file is saved and closed and the changes are applied with:

sudo netplan apply

Then, verify the changes by typing:

ip addr show dev ens3
3: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff
    inet brd scope global dynamic ens3
       valid_lft 3575sec preferred_lft 3575sec
    inet6 fe80::5054:ff:feb0:f500/64 scope link 
       valid_lft forever preferred_lft forever

Finally, you have assigned a static IP to your Ubuntu server.

Setting up a static IP address on Ubuntu Desktop computers requires no technical knowledge.

1. First of all, in the Activities screen, search for “network” and click on the Network icon. This will open the GNOME Network configuration settings. Then, click on the cog icon.

ubuntu desktop-activities screen-GNOME Network
GNOME Network configuration settings


2. Then, this will open the Network interface settings dialog box.
ubuntu desktop-Network interface settings dialog box
Network interface settings dialog box

3. Then, in “IPV4” Method” section select “Manual”, and enter your static IP address, Netmask and Gateway. Click on the “Apply” button once complete.

ubuntu desktop-IPv4-static IP Address
Enter the details


Now that you have set up a static IP Address, open your terminal either by using the Ctrl+Alt+T keyboard shortcut or by clicking on the terminal icon and verify the changes by typing:

ip addr

Lastly, the output will show the interface IP address:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:e9:40:f2 brd ff:ff:ff:ff:ff:ff
    inet brd scope global dynamic noprefixroute eth0
       valid_lft 3523sec preferred_lft 3523sec
    inet6 fe80::5054:ff:fee9:40f2/64 scope link 
       valid_lft forever preferred_lft forever

You now know how to assign a static IP address on your Ubuntu 18.04 machine.

If you have any question, please leave a comment below

Was this article helpful?
Dislike 0
Views: 24
Customer Services Contact

Need Help? Send a Ticket to our 24X7 Technical Support Team

Subscribe Newsletter

Subscribe to Casbay Newsletter for online tips, events and latest promotion !

Copyright © 2010 – 2021 Casbay Sdn. Bhd. (1042688-D). All Rights Reserved.

All Trademarks Are The Property of Their Respective Owner.