How to Configure Static IP Address on Ubuntu 22.04

An IP address identifies every device on the internet, and the purpose of the IP address is to handle connections between devices that send and receive information across the network.

It is a string of numbers separated by periods ranging from 0.0.0.0. to 255.255.255.255. The public IP address can be public, private, dynamic, consumer, or static.

In this tutorial, we are going to explain to you how to configure a static IP address on Ubuntu 22.04 OS. Let’s get started!

Prerequisites

  • A server with Ubuntu 22.04 as OS
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

Before we start with the configuration of static IP address, we need to update the system packages to the latest versions available.

sudo apt-get update -y && sudo apt-get upgrade -y

Step 2. What is Netplan?

Netplan is a utility for easily configuring the network on a Linux system. Netplan stores the configuration in YAML files which are mostly written by the system administrators, network engineers or DevOps engineers. Without configuration, Netplan will not do anything. The Yaml files can be created and stored in /etc/netplan directory on the server.

Netplan has a set of commands, such as:

netplan generate: Used for generating the required configuration.

netplan apply: Used for applying the configurations.

netplan try: Used for applyging the configurations and user confirmation. This command will roll back a broken network configuration.

Step 3. Configure a static IP address

To configure a static IP address, first, create a YAML file with the following command:

touch /etc/netplan/01-network-configuration.yaml

Once created, open it with your favorite editor and paste the following lines of code:

network:
    version: 2
    renderer: NetworkManager
    ethernets:
        eth0:
            addresses:
                - 192.168.1.21/24
            nameservers:
                addresses: [8.8.8.8, 8.8.4.4]
            routes:
                - to: default
                  via: 192.168.1.1

Now, we will explain all lines in this configuration file:

eth0 is the network interface name.

addresses The static IPv4 address, in this case, the static IP address, is set to 192.168.1.21

nameservers: We need to set the nameservers; in this case, these nameservers belong to Google.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

routes: The routes are used for the gateway of the system.

Now, to apply the changes in the configuration file, execute the following command:

netplan apply

To confirm if your static IP address has been added successfully, execute the following command:

ip a

The output should look like this:

root@host:~# ip a
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:16:3e:79:35:ec brd ff:ff:ff:ff:ff:ff
    altname enp0s3
    altname ens3
    inet 192.168.1.21/21 brd 162.246.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fe79:35ec/64 scope link
       valid_lft forever preferred_lft forever

That’s it. You successfully installed Netplan and configured a static IP address on Ubuntu 22.04.

Of course, if this setup is difficult for you, please contact our technical support. We are available 24/7 and will help you with any aspect of IP address configurations. All you need to do is to sign up for one of our managed hosting plans and submit a support ticket.

If you liked this post on how to configure a static IP address on Ubuntu 22.04, please share it with your friends on social networks using the buttons on the left or simply leave a reply below. Thanks.

2 thoughts on “How to Configure Static IP Address on Ubuntu 22.04”

  1. The section ‘addresses’ of ‘nameservers’ are for the IP addresses of the DNS servers, right?
    What about the first ‘addresses’ section, immediately under the ‘eth0’ line? What are those addresses for?

    Reply
    • Yes, the addresses of nameservers are for the IP address of the DNS server.

      The first addresses section is for your Local IPv4 address, which will be the static address.

      Reply

Leave a Comment