Ubuntu

How to change from DHCP to Static IP Address in Ubuntu 20.04?

Network Administrators need to manage and assign the static IP address to their server, especially when constant access to the server is required or the server is configured as the FTP server. The router assigns the new IP address when the lease time gets expired. This is due to its limited amount of range of IP addresses from 0 to 255.

So, in this post, you will learn to change from DHCP to Static IP address on:

  • Ubuntu 20.04 LTS
  • Ubuntu 20.04 Server or Terminal

Let’s start with the graphical way first.

Using GUI

First of all, you need to open up the settings of your Ubuntu system.

If your system is connected to a wired connection, go to the Network tab.

Otherwise, go to the Wireless tab.

And click on the gear icon in the wired or wireless section concerning the connection type you are connected to.

After clicking on the gear icon, a pop-up settings box will appear on your screen like this.

You can see the currently assigned IP address to my system, Default Route, and DNS in the details tab.

To change the IP address to your desired static IP address, go to the “ipv4” tab from the top bar in the settings pop-up.

Select the “Manual” radio button from the ipv4 method section.

Enter the IP address (which will be the static IP address of your choice), Netmask, and Gateway.

DNS is set to Automatic, but if you want to provide manual DNS, turn it off using the toggle button and provide the DNS. You can provide the multiple Domain Name Servers by separating them with commas.

After filling in all these fields, click on the apply button at the top right corner of the pop-up box to save the settings.

Turn Off the connection once using the toggle button, and turn it on again to apply the changes and have results.

After turning it ON, click on the gear icon again to open the settings pop-up window. You can see in the details tab that the IP address, Netmask, Gateway, and DNS are changed successfully.

This is the simplest and easy way to change from DHCP to Static IP Adress graphically.

Using Terminal

We can configure or change the DHCP to Static IP address in the terminal using the Netplan utility. Ubuntu or Ubuntu server, by default, uses Netplan to configure the network configurations.

Since Netplan uses the YAML file for the configuration of the network, then we need to edit the YAML file in the /etc/netplan directory. Head to the /etc/netplan directory by using the cd command in the terminal.

$ cd /etc/netplan

If we list the files in the /etc/netplan directory using the ls command,

$ ls

we can have the name of the YAML file for network configuration.

Open it in a nano editor.

$ sudo nano 01-network-manager-all.yaml

Provide the static IP address of your choice with the netmask, gateway, and the addresses of the nameservers using the following given syntax or paste the following lines in that YAML file.

# Let NetworkManager manage all devices on this system
network
:
  version
: 2
  renderer
: NetworkManager
  ethernets
:
    enp0s3
:
      dhcp4
: no
      addresses
: [10.0.2.60/24]
      gateway4
: 10.0.2.2
      nameservers
:
        addresses
: [192.168.18.1, 8.8.8.8]

Once you’re done, save the file and get back to the terminal.

Now, run the following command in the Ubuntu server or terminal to apply changes.

$ sudo netplan apply

And reboot your system for the changes to take effect.

$ sudo reboot

After rebooting your system, Run the “ip a” command to verify the changes.

$ ip a

It can be seen in the screenshot above that the IP address is changed to the desired static IP address successfully.

Wrap up

These were the two different ways to change the DHCP to Static IP address in Ubuntu 20.04 LTS and Ubuntu 20.04 Server or Terminal.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.