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 Configure SSH Access on Ubuntu? SSH &SCP
How to transfer files from windows to Ubuntu
How To Configure Netplan (Ubuntu) Network – Examples
How To Install And Configure SNMP on Ubuntu?
How To Install Windows 10 on Ubuntu KVM?
What is DHCP network?
For a host on the network to communicate with each other, it is essential for it to have an IP address. If you have multiple end hosts on the network and assigning an IP address manually on each one is a tedious process. So DHCP helps you dynamically assign and IP address to a machine on the network. If you wanted to learn more about the DHCP in details, you can check out the article here.
What is static IP address?
As static IP configuration is a method with which you can configure IP address manually on the network hosts. It is useful in some specific situations. for example if you have server and you wanted to keep an IP address permanently to it, then you can use static IP configuration. Once you have the static IP configured it would never change.
How to change static IP in Ubuntu?
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.
Set static IP for Ubuntu in GUI for 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.
Set static IP in Ubuntu GUI for wired.
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 18.104.22.168, 22.214.171.124
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.
How to set static IP on ubuntu command line?
Set Wi-Fi IP address using CLI.
To configure the Wi-Fi IP address via CLI, you need to do it with the help of netplan configuration.
You can check out the article here if you wanted to learn more about 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.
1. find out the Wi-Fi 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.
2. Modify the Netplan with new wifi 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: 126.96.36.199, 188.8.131.52.2
The netplan configuration is located in /etc/netplan
Do a list file here by typing ‘ls’
There is a configuration file here called
01-network-manager-all.yaml. You need to go ahead and make changes to the file.
3. Backup the netplan configuration.
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
4. Modify the netplan configuration.
You need to configure the netplan configuration as below for the wifi 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: [184.108.40.206,220.127.116.11]
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.
5. 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
Set Static IP for Ubuntu 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: 18.104.22.168, 22.214.171.124.2
1. Find the wired interface on Ubuntu.
Just like how you found the wifi interface, you can type the command IP addr and it would show you the interfaces on your machine.
In my case eno2 is my wired interface.
2. Modify the netplan configuration to reflect the wired network.
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: [126.96.36.199,188.8.131.52] wifis: wlo1: access-points: "mywifi2.4": password: "00000000" dhcp4: no addresses: [192.168.1.102/24] gateway4: 192.168.1.1 nameservers: addresses: [184.108.40.206,220.127.116.11]
Save the configuration.
3. 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.