Static IP Configuration (Ubuntu 24.04)

Configure a static IP address on an Ubuntu virtual machine using Netplan.

Overview

By default, Ubuntu uses DHCP to automatically assign IP addresses. For servers and virtual machines, it is recommended to configure a static IP address so the address does not change.

Step 1: Identify Network Interface

Run the following command to list available network interfaces:

ip a
						

Look for your active interface name (example: enp6s18 ).

Step 2: Locate Netplan Configuration File

Netplan configuration files are stored in:

/etc/netplan/
						

List the files:

ls -la /etc/netplan/
						

View the contents of the configuration file:

sudo cat /etc/netplan/50-cloud-init.yaml
						

Step 3: Edit Netplan Configuration

Open the configuration file:

sudo nano /etc/netplan/50-cloud-init.yaml
						

Example configuration:

network:
  version: 2
  ethernets:
    enp6s18:
      dhcp4: false
      addresses:
        - 192.168.50.100/24
      routes:
        - to: default
          via: 192.168.50.1
      nameservers:
        addresses:
          - 9.9.9.11
          - 149.112.112.11
							

Replace the following values as needed:

  • enp6s18 – your network interface name
  • 192.168.50.100 – desired static IP address
  • 192.168.50.1 – gateway address
  • DNS servers – your preferred DNS provider

Step 4: Secure Configuration File

sudo chmod 600 /etc/netplan/*.yaml
						

Step 5: Apply Configuration

sudo netplan apply
						

Step 6: Verify IP Address

Confirm the new static IP address:

ip a show enp6s18
						

Step 7: Test Network Connectivity

ping -c 3 192.168.50.1
						

If successful, your static IP configuration is complete.