News
3 new Serverspace GPT API Language Models available now!
MA
July 13 2020
Updated June 24 2025

How to Set a Static IP Address on Ubuntu 18.04 Using Netplan

Ubuntu

How to configure static IP address in Ubuntu 18.04:

When setting up a server or working in a network-restricted environment, assigning a static IP address is often a crucial step. Unlike dynamic IP addresses assigned by DHCP, a static IP ensures that your system's address stays fixed across reboots — which is essential for remote access, port forwarding, and other network-related services. In this guide, we’ll walk you through the process of configuring a static IP address on Ubuntu 18.04 using Netplan, the default network configuration tool. Whether you're new to Ubuntu networking or need a quick refresher, this step-by-step tutorial will help you get your system properly configured.

List All Active Network Interfaces on Ubuntu


First, you need to identify the network interface you are going to configure. You can list all attached network interfaces on your system using the command as shown below:

Ip a

List All Active Network Interfaces on Ubuntu

From the output of the above command, we have 3 interfaces attached to the Ubuntu system: 2 ethernet interfaces (one of them is docker) and the loopback interface. The ens33 ethernet interface has been configured to obtain IP address from DHCP. And we need to change it to static IP.

Set Static IP Address in Ubuntu 18.04

In this example, we will set up a static IP address for the ens33 network interface using the Netplan utility.

Netplan is a modern command-line tool for managing network settings, introduced in Ubuntu starting from version 17.10. It simplifies the configuration of network interfaces through a declarative YAML syntax. Netplan works in conjunction with system components like NetworkManager and systemd-networkd, which act as "renderers" — you can choose the one that best suits your environment.

Network settings are defined in YAML files located in the /etc/netplan/ directory. These configuration files allow you to specify parameters for all available network interfaces.

So the first thing to do is to check what configuration files do we have in /etc/netplan/
We can check this out by using the command:

ls /etc/netplan/

Set Static IP Address in Ubuntu 18.04

As we can see there is a configuration file called 50-cloud-init.yaml. We need to edit it to change configuration.

If there’s no configuration files in /etc/netplan/ you can use command as shown below to generate it:

sudo netplan generate

Change configuration

In addition, auto generated files may have different filenames on desktop, servers, cloud instantiations etc (for example 01-network-manager-all.yaml or 01-netcfg.yaml, 50-cloud-init.yaml, etc.), but all files under /etc/netplan/*.yaml will be read by netplan.

Open the netplan configuration file using your text editor as shown:

sudo nano /etc/netplan/50-cloud-init.yaml

Open the netplan configuration file

Find your network interface name in there. It’s ens33 in this example.

Find your network interface name

As you can see there’s dhcp4: true = dchp for ipv4 is enabled.

To change that simply change the config like that:

As you can see there’s dhcp4: true = dchp for ipv4 is enabled

Where:

  • ens33 – the name of the network interface being configured.
  • dhcp4 and dhcp6 – define whether the interface should use DHCP to obtain IPv4 or IPv6 addresses, respectively.
  • addresses – a list of static IP addresses assigned to the interface, including the subnet mask (e.g., /24).
  • gateway4 – the default gateway address for IPv4 traffic.
  • nameservers – a list of DNS server IP addresses used for domain name resolution.

The addresses property of an interface expects a sequence entry for example [192.168.14.2/24, “2001:1::1/64”] or [192.168.56.110/24, ] (see netplan man page for more information).

Important: don’t use tabs in this configuration file.

Save the file and exit. (to save file press Ctrl+O and then choose the filename and press Enter. To exit nano press Ctrl+X)

Then apply the recent network changes using the following command:

sudo netplan apply

Apply the recent network changes

If everything is ok you’ll not get any error messages.

Just check your ip configuration again with the command:

ip a

Check your ip configuration again

As you can see now the ens33 have an IP addresses as we configured before in yaml file.

Congratulations! You’ve successfully configured a network static IP addresses to your Ubuntu server.

FAQ: Configuring Static IP on Ubuntu 18.04

  • Q: What is the benefit of using a static IP instead of DHCP?
    A: A static IP ensures that your system always has the same network address, which is critical for services like SSH access, port forwarding, hosting web applications, or managing servers remotely.
  • Q: Can I use Netplan on older Ubuntu versions like 16.04?
    A: No, Netplan was introduced starting with Ubuntu 17.10. If you're using Ubuntu 16.04 or earlier, you should configure your static IP using the /etc/network/interfaces file instead.
  • Q: I don’t see any files in /etc/netplan/. What should I do?
    A: If the /etc/netplan/ directory is empty, you can generate the configuration files using the command:
sudo netplan generate

If that doesn't work, it’s possible your system is using another method for network management (e.g., NetworkManager or legacy tools).

  • Q: Why shouldn't I use tabs in the YAML file?
    A: YAML strictly requires spaces for indentation. Using tabs can break the configuration and cause netplan apply to fail.
  • Q: How can I check if my static IP configuration was applied successfully?
    A: After running sudo netplan apply, you can verify the current IP configuration by executing:
ip a

Your configured static IP should now be listed for the specified interface.

Vote:
4 out of 5
Аverage rating : 4
Rated by: 2
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.