The IP address of most devices today is generated by the Dynamic Host Configuration Protocol (DHCP) server. A DHCP server assigns a dynamic IP address to your device when it’s connected to a network. Thus, you have the chance to change this IP address from time to time.
On the other hand, a static IP refers to a fixed, immutable address, different from dynamic IPs. You can set static IP settings in Ubuntu 22.04 LTS in three different ways. Here’s how to get started.
Set a Static IP on Ubuntu With the nmcli Command
It is easy to set static IP settings in Ubuntu 22.04 using the nmcli command. nmcli is a text-based utility used to check the status of the wired connections you are using on your device.
With this command, you can access additional networking information such as your connection status, the name of your host device, and general permissions in your network configuration.
Follow the steps below to set a static IP address with the nmcli command.
You can get information about your connection with the following command:
nmcli connection show
The output of this command will be as follows:
NAME UUID TYPE DEVICE
Wired connection 1 12f312a7-f0e7-334a-8ab4-c7b3f8249c7e ethernet enp0s3
Create a static link with the command below. Then, manually configure the enp0s3 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
If you use the nmcli connection show command again, you can see that the static link has been added.
After this process, add the static connection you created to the DNS IP.
sudo nmcli con mod static ipv4.dns 192.168.*.*
Now use the command below to activate the connection:
sudo nmcli con up id 'static'
If the output displays “connection successfully activated,” you’ve successfully set up a static IP address on your machine.
You can verify the static IP you want to assign to your device by running the following command:
Using Netplan for Static IP Settings on Ubuntu
Similar to nmcli, the netplan command allows you to set static IP settings on Ubuntu 22.04 LTS. To do this, follow the steps below.
First, find out the name of your network interface using the command below:
sudo ip a
What you see here is your network interface name. This name may be different on each device.
Now, create a file named 01-netcfg.yaml in the /etc/netplan folder. Edit it with your favorite text editor.
sudo vim /etc/netplan/01-netcfg.yaml
Add the following lines to the file:
As you can see, you have disabled the DHCP IP setting with the dhcp4: no statement. You’ve then added the IP address and DNS settings assigned by Google.
After saving this file, run the following command to apply the changes:
sudo netplan apply
Configure Static IP Settings on Ubuntu Graphically
The graphical network settings interface in Ubuntu 22.04 is very useful if you don’t like to deal with the command line. You can set the static IP address you want using this interface.
To do this, click on the Network icon in the upper right corner of your desktop. Then, select Wired Settings from the drop-down menu. Click on the Gear icon to open the settings window.
Then, switch to the IPv4 tab in the window that opens.
As you can see, DHCP is enabled by default. Change the IPv4 Method to Manual as you want to use a static IP instead of a dynamic one. Next, change your address, netmask, and gateway settings. Finally, modify your DNS setting and click the Apply button.
You must restart this wired connection for all these actions to take effect. To do this, simply toggle the switch next to the network name on and then off.
Why Should You Use Static IP Addresses?
You learned how to configure static IP settings in “Jammy Jellyfish” 22.04, the latest LTS version of Ubuntu, using both the graphical settings interface and the two terminal commands: nmcli and netplan.
You can consider using static IP addresses to avoid connection problems caused by dynamic IP addresses. A static IP address allows you to have a fixed identity and location when connected to the internet.
Due to insufficient IP addresses, some service providers may assign the same address to two different users. In this case, connection problems can occur. Using static IP addresses instead does not cause such problems as it is user-specific.
What Can Someone Do With Your IP Address?
About The Author