Methods of payment Abuse

How to Set a Static IP Address in Ubuntu 22.04

28.05.2025, 18:38

Sometimes, a device on your network needs a permanent IP address — like when you’re setting up a server, a VPN, or a storage system. In this guide, we’ll walk you through how to assign a static IP in Ubuntu 22.04 using Netplan.

What’s a Static IP and Why Use One?

Every time you connect a device to a network, it’s assigned an IP address — usually temporarily, by a DHCP server (like your router). That address might change after a reboot or a day or two. That’s fine for laptops, phones, and most user devices.

But for a server that needs to stay reachable at the same address — dynamic IP just doesn’t cut it. Imagine you’ve launched a website, linked your domain to it, and then suddenly the server’s IP changes. The site becomes unreachable. Same story for SSH access, file sharing, or internal APIs.

Types of IP Addresses

→ Static IP is set manually. It never changes unless you change it yourself. It’s reliable, but you need to be careful — don’t assign an address that’s already in use.
 → Dynamic IP is assigned automatically. Convenient, but less predictable.
 → Reserved IP is a middle ground: your router hands out the IP, but always assigns the same one to a specific MAC address. Useful if you control the router.

Setting a Static IP Using Netplan

Netplan is Ubuntu’s tool for configuring network settings, introduced in version 18.04. It uses YAML files for configuration and lets you define static IPs directly.

Step 1: Identify Your Network Interface

Open a terminal and run:

ip a

Look for the active interface — it might be named enp0s3, eth0, or something similar.

Step 2: Edit the Netplan Configuration File

Netplan config files are located in /etc/netplan/. Common file names include:

→ 00-installer-config.yaml

→ 01-network-manager-all.yaml

Open the file for editing:

sudo nano /etc/netplan/01-network-manager-all.yaml

Now paste in a configuration like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.1.100/24]
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

What this means:
→ renderer: networkd — use this if you’re not on a graphical desktop. If you are, use NetworkManager instead.
→ addresses — sets the static IP and subnet mask.
→ routes — defines the default gateway.
→ nameservers — sets DNS servers (in this case, Google’s public DNS).

Important: Make sure the spacing in the YAML file is correct. Use spaces, not tabs — YAML is strict about formatting.

Step 3: Apply the Configuration

Run:

sudo netplan apply

If something goes wrong, try the debug mode:

sudo netplan apply --debug

Check that everything is working:

ip a show enp0s3
ping 8.8.8.8