Summary: In this article we’ll teach you how to set a static IP to your Ubuntu 18.04 machine. 

When configuring a Linux machine for a local network, obviously you need to add an IP address to your machine. You can do this in two ways. The IP configuration can be done using either the automatic DHCP or using the Static IP addresses.

The easiest way to configure a computer to use a TCP/IP network is to use DHCP. In modern routers there is DHCP server built into them, which assigned IP addresses dynamically to devices which are connecting to it.

But if you want to set an IP address which is not changing dynamically or in other words if you want to set a static IP to your Ubuntu 18.04 machine follow the below steps.

There are three ways to do this.

  1. Set static IP address using Netplan
  2. Set static IP address using GUI (For Ubuntu Desktop with a GUI)
  3. Set static IP using interfaces file

Also Read: IP Addressing – Introduction and Classful Addressing

Set static IP address using Netplan

Netplan is a utility for easily configuring networking on a Linux system. Starting with 17.10 release, Netplan is the default network management tool on Ubuntu. With this tool we need to simply create a YAML description of the required network interfaces and their configurations. Using those information Netplan will generate all the necessary configuration for your chosen renderer tool. Netplan currently works with these supported renderers.

  1. Network Manager
  2. Systemd-networkd

The first step when configuring a static IP is to identify the name of the ethernet interface you want to configure. You can do this using the ip link command.

Finding the network interfaces using ip link command

Once you identify the interface that you want to configure we need to edit the YAML file which is stored in /etc/netplan directory and it has a .yaml extension. File name of the YAML file may differ from system to system. Open the YAML file and edit the file as follow.

In my case i’m going to configure a static ip to my enp0s3 interface.

When editing the YAML file make sure to follow the YAML code indent standards as it might not work if there is a syntax error. When you done editing the file, save it and run the following command to apply the configurations to your interface.

sudo netplan apply

That’s it. Verify your configuration using the ip a command.

Checking the ip address

Set static IP address using GUI (For Ubuntu Desktop with a GUI)

This is the easiest way to assign a static ip to your device.

Go to settings in your Ubuntu machine and select the network tab. In the Network tab under wired section select the corresponding network interface you wish to assign the static IP address.

Network settings in ubuntu

Click on the gear box icon next to your network connection you wish to configure and select ipv4 from the top menu.

Network settings in ubuntu

Select Manual for the IPv4 method, enter your desired configuration and hit Apply. Now Turn your interface off and turn it back on.

Enter your network configurations here

That’s it. You have successfully set static IP to your machine.

After configuring the static IP

Also Read: How to Install Google Chrome in Ubuntu

Configure static IP using interfaces file

This is the old way of setting static ip addresses in ubuntu. In new versions this method is replaced Netplan.

As in the Netplan configuration first we need to find the interface. After finding the interface edit the /etc/network/interfaces file with your network configuration as follows.

Editing the /etc/network/interfaces file

Now save the file and restart network using the following commands.

sudo ip a flush enp0s3
sudo systemctl restart networking.service

That’s it. Verify your configuration using the ip a command.

So that’s it guys… Hope you guys enjoy the article. See you from another article. Thank you for reading.

Also Read: How to Remotely Control Ubuntu System From Windows via RDP


Sherif Lotfy · February 29, 2020 at 9:33 am

Thank you

    alphaX · March 4, 2020 at 6:11 am

    You are welcome. Hope you enjoyed the post…

Leave a Reply

Your email address will not be published. Required fields are marked *