How To Change Static IP In Ubuntu GUI and CLI ?

Saifudheen SidheeqNetworkingLeave a Comment

If you’re using Ubuntu Dekstop or server, and one day you decided to change the IP address of your ubuntu machine from automatic (DHCP) to static configuration. how do you achieve that?

If you are using Ubuntu with GUI, it is pretty straightforward, but what if you don’t have GUI and the only option that you have is to configure via the command line? so lets see how we can do that.

In this blog lets discover, How to configure the Static IP in Ubuntu using GUI for both wired and wireless networks also using Netplan if you have only the CLI access.

And I am using my laptop running Ubuntu 20.04 in it. The steps mentioned here are similar on the other versions of Ubuntu as well, including the Ubuntu server.

How to change static IP in Ubuntu?

  1. Using GUI
  2. Using CLI

Change the IP address via GUI.

The easiest and better way to change IP is via GUI. In which we would look at both the wired and wireless networks.

Configure static IP for Ubuntu WiFi.

Click on the right top corner of your Ubuntu machine, and then click on Wi-Fi settings from the drop down list.

I have already connected to a wifi network, to proceed with the static IP configuration, click on the gear icon here.

This should open up the network IP configuration on Ubuntu, Click on IPv4 tab

You can see the current configuration is Automatic (DHCP)

To change it to static, select Manual and configure the IPv4 address, its netmask and the gateway.

Then click on Apply.

You are now back to the wifi configuration page, click on the WiFi switch to turn it off.

And turn it back on again, for the the changes to take affect. You may now click on the gear icon see the IP configurations.

As you can see the IP address has been changed to the one which we configured via the GUI.

Configuring the static IP in Ubuntu wired using GUI

Changing the IP address in ubuntu wired connection is not different than wifi.

Goto right top corner, click on the network icon and the drop-down list, expand Wired Connected, and click on wired settings.

The network configuration wizard now pops up.
Click on the gear icon. This will open the network configuration.

Under the Details tab, you can see the current network configuration. As you can see, my current DHCP IP address is 192.168.0.71.
I need to change that now, so click on the IPv4 tab.

Under IPv4 you can see the automatic (DHCP) is selected.

Select manual and change the IP address to what you wanted to configure, in my case I am going to configure

IP address as 192.168.0.100
Netmask 255.255.255.0
Gateway 192.168.0.1
And the DNS is 4.2.2.2, 8.8.8.8

Click on Apply.

Once you click on Apply, you will now be back to the network configuration settings. Click on the switch to turn the wired connection off and turn it back on. Then click on the gear icon again.

You should now be able to see the new network configurations applied.

One of the benfit of configuring the static IP is that, every time when you reboot the PC, its IP will never change.

Ubuntu set IP address command line using netplan

Change wireless IP address using CLI.

To configure the Wi-Fi IP address via CLI, you need to do it on the netplan configuration.

Note: Before you proceed with the steps, ensure that the Ubuntu machine is not connected to any other wifi network. Mostly in Ubuntu desktop, where users connect to the wifi via GUI. If you have previously connected to the same wifi via GUI, you may click on Forget this network by going into the wifi settings.

Alright, let’s begin.

First, find out the wifi interface name

in the terminal, type ip addr and hit enter

The name of the wireless interface should start with “w”

As you can see, my wifi name is wlo1, and I don’t see any IP address connected to it.

Modify the Netplan with new wireless IP configuration.

Below is the IP configuration that we are going to make.

IP address: 192.168.1.100/24
Gateway: 192.168.1.1
DNS servers: 8.8.8.8, 4.2.2.2.2

The netplan configuration is located in /etc/netplan

Do a list file here by typing ‘ls’

As you can see, there is a configuration file here called 01-network-manager-all.yaml. You need to go ahead and make changes to the file.

Before you make any changes make sure you take a backup of the current file with the below command.

sudo cp 01-network-manager-all.yaml 01-network-manager-all.yaml.bak

01-network-manager-all.yaml.bak is the backup file

You need to configure the netplan configuration as below for the wireless to work.

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eno2:
      addresses: []
      dhcp4: true
  wifis:
    wlo1:
      access-points:
        "mywifi2.4":
          password: "00000000"
      dhcp4: no
      addresses: [192.168.1.102/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8,4.2.2.2]

Did you notice that I haven’t made any changes to the eno2?

That is our wired network. With the above configuration, the wired connection would work with DHCP.

We will make changes to the wired network with static next.

Apply the Netplan Wi-Fi configuration

Type the command sudo netlan apply to apply the configuration and changes to affect.

Alright, we should now have the wifi connection with the new IP address 192.168.1.102 that we have configured through netplan

Type the command ip addr to see the IP address of the machine.

As you can see, my adapter wlo1 has an IP address 192.168.1.102

Ubuntu Static IP for wired using netplan

My wifi is working with the IP we configured using netplan, next let’s go ahead and configure the wired network.

Below is the IP configuration details.

Since I am connected to the same wireless and wired gateway 192.168.1.1 I am going to pick up IP from the same range, which is 192.168.1.200.

IP address: 192.168.1.200/24
Gateway: 192.168.1.1
DNS servers: 8.8.8.8, 4.2.2.2.2

The same netplan configuration that we modified needs to reflect the wired connection now, let’s go ahead and add the configuration for the wired network as shown below.

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eno2:
      dhcp4: no
      addresses: [192.168.1.200/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8,4.2.2.2]
 wifis:
    wlo1:
      access-points:
        "mywifi2.4":
          password: "00000000"
      dhcp4: no
      addresses: [192.168.1.102/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8,4.2.2.2]

Save the configuration.

Apply the configuration and see the result.

To apply the configuration that we just made, type sudo netplan apply

Though I made the changes, I still do not see the IP address on my physical network yet. why is that?

However, did you notice the physical link status ?, it shows that it is down.

That’s because I did not connect the cable to my machine 🙂

Lets go ahead and connect the wired network to the machine.

I just plugged in and let me check the ip address again to see if there is any difference.

As you can see the changes that we just made reflected now.

That’s it, you now configured the netplan static IP for both the wired and wireless network and you should be good to go. In case if you wanted to learn more about how you can configure the netplan in different scenarios, you may check out the article I created here.


Learn About This Author

Saifudheen Sidheeq

Saifudheen is in the Computer networking and technology field for about a decade now. He loves technology and new ideas, and in his spare time, he loves to write about them.