← Back to Guides Homepage

How to Set a Static IP on Ubuntu Server

In this guide, we are going to set a static IP address on an Ubuntu Server (specifically version 22.04 Jammy Jellyfish). By default, the server is often configured to receive an IP via DHCP, but for server operations, a static IP is usually preferred. We will achieve this by editing the Netplan configuration YAML file.

Step 1: Check Current Netplan Configuration

First, log into your machine. You can verify your current IP address and ensuring you have connectivity (e.g., to a Cloudflare DNS) before making changes.

Navigate to the Netplan configuration directory to see the current settings. Usually, the file is located in /etc/netplan/. If you check the file content, you will likely see dhcp4: true, indicating the server is currently configured for DHCP.

Step 2: Edit the Netplan YAML File

We will use the nano text editor to modify the configuration file. It is crucial to maintain correct indentation when editing YAML files, as they are space-sensitive.

Configuration Details

You will need to replace the DHCP configuration with specific static details:

Your configuration should look similar to this:

network:
  ethernets:
    ens33:
      addresses:
      - 192.168.74.10/24
      nameservers:
        addresses:
        - 1.1.1.1
        - 8.8.8.8
      routes:
      - to: default
        via: 192.168.74.2
  version: 2

After editing, save the file and exit Nano.

Step 3: Apply and Verify Changes

Once the file is saved, apply the new configuration using the following command:

sudo netplan apply

You may see a warning regarding Open vSwitch, which is generally okay to ignore for this virtual machine setup.

Verification

Verify that the IP address has changed by running the ip address command:

ip a

You should see your new static IP (e.g., 192.168.74.10) listed under your interface. Finally, test connectivity by pinging your default gateway and an external address:

ping 192.168.74.2
ping 1.1.1.1

If the pings are successful, your static IP is correctly configured and operational.

← Back to Guides Homepage