Share your love
Easy Steps To Set Static IP Address on Ubuntu 22.04 From CLI

This tutorial intends to teach you to Set Static IP Address on Ubuntu 22.04 From CLI. A static IP address is an IP address that doesn’t change over time. Let’s see why we should set a static IP address.
Because of insufficient IP addresses, some service providers may assign the same address to two different users. For this reason, connection problems can happen. Instead of this, you can see the static IP addresses.
Now follow the steps below on the Orcacore website to see how to Set Static IP Address on Ubuntu 22.04 From CLI by using the Linux Commands.
Table of Contents
Learn To Set Static IP Address on Ubuntu 22.04 From CLI
To Set Static IP Address on Ubuntu 22.04 From CLI, you must have access to your server as a non-root user with sudo privileges. To do this, you can check this guide on Initial Server Setup with Ubuntu 22.04.
Follow the steps below to learn how to Set Static IP Address on Ubuntu 22.04 From CLI.
Step 1 – Configure a Static IP on Ubuntu 22 with nmcli Command
The nmcli is a command line tool that can be used to create, edit, activate/deactivate, and delete network connections. So we want to use this command line utility to set a static IP address on our Ubuntu server.
To use this tool, you must install Network Manager on your server. To do this, run the command below:
sudo apt install network-manager -y
Then, you can use the nmcli command to get your connection information:
sudo nmcli connection show
In your output, you will get the following connection information:
- NAME
- UUID
- TYPE
- DEVICE
Example Output
NAME UUID TYPE DEVICE
Wired connection 1 12f312a7-f0e7-334a-8ab4-c7b3f8249c7e ethernet enp0s3
Next, you should create a static link. You need to manually configure the device and ipv4 settings with the appropriate parameters in the nmcli command:
sudo nmcli con add type ethernet con-name 'static' ifname enp0s3 ipv4.method manual ipv4.addresses 192.168.1.89/24 gw4 192.168.1.1
When you are done, recheck your connection information and you should see the static link has been added:
sudo nmcli connection show
Example Output
NAME UUID TYPE DEVICE
Wired connection 1 12f312a7-f0e7-334a-8ab4-c7b3f8249c7e ethernet enp0s3
static ... ethernet --
At this point, you need to add the static connection you have created to the DNS IP with the command below:
sudo nmcli con mod static ipv4.dns 192.168.*.*
Then, you must activate the static connection on Ubuntu with the following command:
sudo nmcli con up id 'static'
In your output, you should see the “connection successfully activated,” message.
Also, you can use the following IP command to verify your static IP address:
ip route
That’s it, you have set a static IP address on your server.
Step 2 – Configure a Static IP on Ubuntu 22 with Netplan
At this step, you can use an alternative command called Netplan to Set Static IP Address on Ubuntu 22.04 From CLI. To do this, you just need to follow the steps below.
First, use the command below to find your desired network interface:
sudo ip a

Then, you must create a new file in the /etc/netplan. Here we named it 01-netcfg.yaml and created it by using the vi editor:
sudo vi /etc/netplan/01-netcfg.yaml
Add the following content with your settings to the file:
network:
version: 2
renderer: networkd
ethernets:
eth0: #Edit this line with your network interface name.
dhcp4: no
addresses:
- 192.168.1.10/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Here we disabled the DHCP and set DNS settings with Google.
When you are done, save and close the file.
Finally, you must run the command below to apply your configuration:
sudo netplan apply
That’s it, you are done. You have learned to Set Static IP Address on Ubuntu 22.04 From CLI.
Conclusion
At this point, you have learned why it is good to set a static IP and configure it from CLI with Linux Commands such as Netplan and NMCLI on Ubuntu 22.04.
Hope you enjoy it. You may also interested in these articles:
10 Useful ncat Commands on AlmaLinux