
Setting a static IP address on Ubuntu 24.04 is useful when you need a server or workstation to keep the same IP address all the time. This is common for web servers, file servers, domain controllers, and other systems that must stay reachable on a fixed address. On Ubuntu, network configuration is handled through Netplan, which uses YAML files to define IP settings, routes, and DNS. (Ubuntu)
In this guide, you will learn how to configure a static IP address on Ubuntu 24.04 using Netplan. We will cover how to identify your network interface, edit the Netplan configuration file, apply the changes, and verify that the new IP address is working properly. Netplan supports static IP configuration with keys such as addresses, routes, and nameservers. (Netplan)
Step 1: Check Your Network Interface Name
Before editing the network settings, find your active network interface name:
ip a
Look for an interface such as enp0s3, ens18, or eth0.
Step 2: Find the Netplan Configuration File
Netplan configuration files are usually stored in:
/etc/netplan/
List the files with:
ls /etc/netplan/
You may see a file like:
00-installer-config.yaml
or
50-cloud-init.yaml
Step 3: Back Up the Existing Configuration
Before making changes, create a backup:
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
Replace the filename if your system uses a different Netplan file.
Step 4: Edit the Netplan File
Open the file with nano:
sudo nano /etc/netplan/00-installer-config.yaml
Use a configuration like this:
network:
version: 2
renderer: networkd
ethernets:
ens18:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 1.1.1.1
In this example:
ens18is the network interface name192.168.1.50/24is the static IP address192.168.1.1is the default gateway8.8.8.8and1.1.1.1are DNS servers
Ubuntu documentation shows that static IP settings in Netplan are defined with YAML and commonly include an interface name, one or more addresses, DNS servers, and a default route. The renderer can be networkd or NetworkManager, depending on the system. (Ubuntu)
Step 5: Test the Configuration
Before applying the change permanently, test it:
sudo netplan try
This lets you confirm the network still works before the configuration is committed.
Step 6: Apply the Static IP Configuration
If everything looks correct, apply the new configuration:
sudo netplan apply
Ubuntu and Netplan documentation recommend applying changes with the netplan command after editing the YAML file. (Ubuntu)
Step 7: Verify the Static IP Address
Check that the new IP address is active:
ip a
Check the default route:
ip route
Test DNS and internet connectivity:
ping -c 4 8.8.8.8
ping -c 4 google.com
If the IP address, route, and DNS all work, your Ubuntu 24.04 static IP setup is complete.
Common Netplan Mistakes
A failed Netplan setup is often caused by small YAML errors. Watch for these common issues:
- Wrong indentation
- Incorrect interface name
- Wrong gateway address
- Missing
/24subnet prefix - Tabs instead of spaces
Netplan uses YAML syntax, so spacing and indentation must be correct for the configuration to work. (Ubuntu)
