How to Configure Static IP Address on Ubuntu 24.04


An IP address falls either in the Static or the Dynamic category. By default, Ubuntu 24.04 is configured at DHCP (Dynamic Host Configuration Protocol), which changes the IP address frequently. In a DHCP-based configured machine, the IP address changes frequently upon each restart (machine/network). Thus, you have to check the IP address of the server each time before setting up a connection, which is a tedious task.

In such a case, you can set up/configure the static IP address for the server to which you have to attempt multiple connections in a day.

Keeping its importance in view, this post will list the methods to configure/set up static IP addresses on Ubuntu 24.04. The methods are demonstrated for both the Ubuntu server and Desktop.

Outline:

How to Choose the Static IP Address for Your System

While setting a Static IP address, you might be thinking about which IP address to choose. Is it already occupied by any device on the network? Don’t worry here’s the two-step remedy to choose an unconflicted IP address for your machine:

Step 1: Check the Broadcast Range

First, you need to use the following command and check which broadcast range is permitted on your network:

ip a

Locate the “brd” instance in the output, i.e., 192.168.18.255 which means you can choose between 192.168.18.1 and 192.168.18.255.

Step 2: Check the Active Hosts on Your Network

Once the IP range is found, you need to check the IP addresses of the active hosts on your network and drill down the IP selection to avoid IP conflicts. For that, we are using the Nmap utility as follows:

nmap -sP 192.168.18.*

Here you go, you need to pick the IP addresses in the range “192.168.18.1 – 192.168.18.255” except those that are listed by the output of the above command.

Note: If the Nmap support is not yet installed, do it using the command, “sudo apt install nmap”.

How to Configure Static IP Address on Ubuntu 24.04

Ubuntu 24.04 manages the network through the “networkd” or the “Network Manager”. The “networkd” can be configured using the netplan utility while the Network Manager is managed using the NMCLI, NMTUI, or the system’s network settings. The netplan decides whether the “networkd” is the network renderer or the “Network Manager”. The system acts accordingly after reading the netplan’s configuration file.

Let’s start learning the methods:

Netplan | Server and Desktop

The netplan’s configuration file is placed at “/etc/netplan/01-netowrk-manager.yaml”. This file decides which renderer to use and the static IP settings can be configured here too. Let’s see how you can use netplan’s for static IP configuration:

Step 1: Backup the Yaml Configuration

First, either backup the yaml file or note down the entries to back up it when required:

sudo cp /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all.yaml.backup

When you open the netplan configuration file in any editor, you will find the current configuration of your Ubuntu networking:

In our case, the NetworkManager is the network renderer which is being managed via the GUI, and “version 2” shows the version of the yaml configuration syntax.

Let’s dig further:

Step 2: Check the Current IP Address and the Network Interface

Use the below command to check the current IP address and the network interface you want to configure:

ip addr show

The current IP address of the interface “enp0s3” is “192.168.18.82” and the interface is “enp0s3”.

Note: Before you proceed further, go through this Method to choose the IP address.

Step 3: Configure the Static IP Address Inside the Yaml File

You need to understand the “version 2” syntax of the Yaml file to carry out the error-free configuration. Otherwise, your network connection will be lost.

Do it as:

Here:

  • Version 2 is selected which is the only supported YAML file version at this time.
  • The networkd is used as a renderer.
  • The value of dhcp4 is set to “no” and then the IP address is set (following the Method).
  • The gateway4 or gateway6 entries are deprecated in version 2 of the YAML file. Thus, use the “routes” to “default” via the lowest IP of the broadcast, i.e., 192.168.18.1.

Step 4: Apply the Changes

Use the following netplan’s command to apply the changes:

sudo netplan apply

  • Note: Address the Permission Related Warning

You might get a warning related to the permissions, i.e., permissions for the netplan file are too open which means that it can be changed/configured by all the users:

To fix that, use the chmod with 600 privileges where the owner has the rights to make changes while other users can view the file only:

sudo chmod 600 /etc/netplan/01-network-manager-all.yaml

As soon the chmod command is executed, the netplan’s warning is removed:

Now, check the newly set IP address on the chosen interface:

ip a

That’s how you can set the static IP address via the netplan.

NMCLI | Server and Desktop

Network Manager Command Line Interface (NMCLI), as its name suggests, is used to configure the Network Manager. The nmcli command allows you to set the IP address, gateway, and DNS for the specific network interface. Follow the below steps to configure the static IP address using nmcli:

Prerequisites: Set the Renderer to Network Manager in Netplan

As the nmcli utility configures the Network Manager. Thus, you have to put the “Network Manager” as the network renderer in the netplan’s configuration file:

Step 2: Check the Network Interface/Device Name

First, check the device and the connection name that will be used in the following steps:

sudo nmcli con show

Note down the connection name, i.e., wired which is pointing to our device “enp0s3”.

Step 3: Set the IP Address, Gateway, and the DNS

First, check/choose the IP address following the Prerequisites Method. The commands to set the address, Gateway, and the DNS are here:

  • IP-Address
sudo nmcli con mod wired ipv4.addresses 192.168.18.144/24

  • Gateway
sudo nmcli con mod wired ipv4.gateway 192.168.18.1

  • DNS
sudo nmcli con mod wired ipv4.dns 8.8.8.8

  • Connection Mod to Manual (For Static IP Address)
sudo nmcli con mod wired ipv4.method manual

  • Activate the Connection
sudo nmcli con up wired

Let’s verify the ip address:

And the chosen IP address is set now.

NMTUI | Server and Desktop

NMTUI is semi-GUI method. It provides an interactive text-based user interface on the terminal to manage the Network Manager. You just have to pick the IP-Address for your specific interface and follow the below steps:

Launch the NMTUI’s interface using the “nmtui” command and “Edit a connection”:

Choose the connection and then select the “<Edit …>”:

Change the IPv4 configuration to Manual and select “<Show>”:

Put the IP address, Gateway, and DNS. Scroll down and choose “OK” to save the settings:

Lastly, activate the configured connection:

Check the newly set IP address of the interface:

The methods discussed until now are applicable to both Ubuntu servers and desktops.

Network Settings | Desktop Only

When the Network Manager is the renderer in the netplan, you can configure the network settings from the GUI Settings. This method applies to the Ubuntu Desktops only. Follow the below steps to set the static IP address from the Ubuntu settings:

Open the Network Settings and go to the network options of your connection:

Select/Choose the IP address, DNS, Gateway, and Netmask (optional) and click on “Apply”:

Now, check the newly set IP address:

That’s how you can configure the Static IP Address on Ubuntu 24.04.

Bottom Line

Ubuntu 24.04 provides various ways to configure the Static IP address. If you are using the Ubuntu server, then you can use the netplan’s method, nmcli, and the nmtui whereas the network settings option is only applicable on the Ubuntu desktop.

It is recommended to first define the renderer (networkd or Network Manager) in the netplan config file and then choose one of the methods to configure the IP address.

That’s all about this post.

Print Friendly, PDF & Email
Categories