Setting a Static IP Address in Ubuntu 24.04 via the Command Line
Configuring a static IP address on your Ubuntu server is essential for various reasons, such as ensuring consistent network configuration, facilitating server management, and improving network security. Ubuntu 24.04, like its predecessors, uses the Netplan utility for network configuration, which simplifies the process of setting a static IP address through YAML configuration files.
In this tutorial you will learn:
- How to identify your network interface using the command line
- How to edit the Netplan configuration file to set a static IP address
- How to apply the configuration changes
- How to ensure your configuration file permissions are secure

Configuring a Static IP Address
Before diving into the configuration steps, ensure you have sudo or root access to the Ubuntu system. This access is necessary for editing network configuration files and applying changes.
- Identify Your Network Interface: To set a static IP address, you first need to know which network interface youâre configuring.$ nmcli d
Identify Your Network InterfaceThis command lists all network interfaces on your system. Note the interface name you plan to configure, such as âenp0s3â.
- Edit the Netplan Configuration File: Netplan configuration files are stored in /etc/netplan/. You will find this file in theÂ
/etc/netplan
 directory. It might be namedÂ01-netcfg.yaml
,Â50-cloud-init.yaml
, or something similar, depending on your setup. Open or create a file for editing.$ sudo nano /etc/netplan/01-netcfg.yamlHereâs an example configuration to set a static IP address:network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: no addresses: - 192.168.1.10/24 routes: - to: default via: 192.168.1.1 nameservers: addresses: [8.8.8.8, 8.8.4.4] Replace âenp0s3â with your interface name. Adjust the IP address, subnet mask, default gateway, and DNS servers as necessary for your network.Detailed Explanation of the Netplan Configuration FileThe Netplan configuration file is a YAML document used in Ubuntu systems for network configuration. It defines how network interfaces should be configured to connect to the network. Below is a detailed breakdown of each section within the configuration file example provided:network:Â This is the root element of the configuration file, signifying the start of the network configuration.version: 2
This specifies the Netplan configuration format version. Version 2 is currently used for most configurations and supports additional features not available in version 1.
https://a19a7fb382416820b63452213d6a550d.safeframe.googlesyndication.com/safeframe/1-0-40/html/container.htmlrenderer: networkd
The renderer indicates which backend Netplan uses to apply the configurations. ânetworkdâ is used for server and headless environments, providing a system daemon to manage network configurations. Another common renderer is NetworkManager, which is more suited for desktop and user-friendly environments.ethernets:
This section specifies that the configuration is for Ethernet interfaces. Itâs a top-level key under which individual Ethernet interfaces are defined.enp0s3:
This is the identifier for the specific Ethernet interface being configured. âenp0s3â is a common name for a network interface on virtual machines but could vary depending on your systemâs hardware and kernel. Use the commandÂip link
 to find out the names of your interfaces.dhcp4: no
This setting disables DHCP for IPv4 on the interface, indicating that a static IP address will be used instead. If set to âyes,â the interface would obtain an IP address automatically from a DHCP server.addresses:
This list specifies the static IP addresses (and optionally, subnet masks) to assign to the interface. â192.168.1.10/24â denotes the static IP address â192.168.1.10â with a subnet mask indicating a â/24â (or 255.255.255.0) network. You can list multiple addresses in this section if needed.routes:
This section is used to define static routes. The âto: defaultâ and âvia: 192.168.1.1â lines specify a default route (i.e., where packets should be sent if their destination doesnât match any other route) through the gateway â192.168.1.1â.nameservers:
The nameservers key specifies the DNS servers to be used by the system. âaddresses: [8.8.8.8, 8.8.4.4]â configures Googleâs DNS servers as the primary and secondary DNS servers, respectively. This setting is critical for resolving domain names to IP addresses.This Netplan configuration example sets a static IP address for a single Ethernet interface, disables DHCP to prevent automatic IP address assignment, specifies a default gateway for outbound traffic, and defines DNS servers for name resolution. Itâs a common setup for servers that need a consistent network configuration to ensure reliable network connectivity and services accessibility. - Secure Configuration File Permissions: Itâs crucial to ensure that the Netplan configuration file permissions are secure to prevent unauthorized access.$ sudo chmod 600 /etc/netplan/01-netcfg.yamlThis command sets the file permissions so that only the root user can read and write to the file.
- Apply the Configuration Changes: Once youâve edited the configuration file, apply the changes to update your network settings.$ sudo netplan applyThis command activates the new network configuration. If there are no errors, your system will start using the static IP address youâve configured.
- Verify the New Static IP Address: To confirm that the static IP address has been successfully assigned to your network interface, use theÂ
ip a
 command.$ ip aThis command displays all network interfaces and their configuration details. Locate your configured interface (e.g., enp0s3) in the output to verify the new static IP address is correctly assigned.Verify the New Static IP Address
Conclusion
Setting a static IP address on Ubuntu 24.04 involves identifying the correct network interface, editing the Netplan configuration file with the new IP settings, securing the file permissions, and applying the changes. This process ensures your server can communicate consistently and securely on your network. Remember to always backup configuration files before making changes to prevent any unintended network disruptions.