A static IP address is an IP address manually specified by a network administrator instead of being dynamically assigned from a DHCP server. It is essential in environments where the IP address must not change, such as server operation, remote access, and network service hosting. Ubuntu 24.04 LTS uses Netplan as the default network configuration tool and also supports nmcli and nmtui interfaces through NetworkManager, allowing users to configure networks in their preferred way.

The Need for Static IP

DHCP vs Static IP

DHCP (Dynamic Host Configuration Protocol) is a protocol that automatically assigns IP addresses to devices connected to the network, which is convenient for client devices. However, servers and network equipment require static IP because service connections break when IP addresses change.

Using a static IP address allows consistent access to servers with the same IP, maintaining stable SSH remote access, web server operation, and database connections. When registering IP in DNS records or setting firewall rules based on IP, configuration can be done without worrying about IP changes. When network problems occur, having clear IP addresses for each device makes problem diagnosis and resolution easier, and traffic from specific devices can be easily identified during log analysis.

Situations Requiring Static IP

SituationReason
Server OperationService access points for web servers, DB servers, file servers must not change
Remote AccessIP must be consistent when connecting via SSH, RDP
DNS ConfigurationStatic IP needed for A records linked to domains
Firewall RulesWhen setting IP-based allow/block rules
Network MonitoringTracking and analyzing traffic from specific IPs
Port ForwardingWhen forwarding ports to specific IPs on router

Network Configuration Method Comparison

There are three main methods to set a static IP on Ubuntu 24.04 LTS. Each method has unique advantages and disadvantages and can be selected based on environment and user preference.

MethodInterfaceConfig FileSuitable Environment
NetplanCLI/YAML/etc/netplan/*.yamlServers, headless systems
nmcliCLINetworkManagerRemote management, script automation
nmtuiTUINetworkManagerTerminal environment, intuitive setup

Prerequisites

Before setting a static IP, current network status must be checked and necessary information collected. First, check the network interface name and current IP address with the ip a or ip addr command, check the default gateway address with the ip route command, and check the current DNS server with cat /etc/resolv.conf.

Required Information

ItemDescriptionExample
Interface NameNetwork device identifiereth0, ens33, enp0s3
IP AddressStatic IP to assign192.168.1.100
Subnet MaskNetwork range specification/24 (255.255.255.0)
GatewayNetwork exit, router IP192.168.1.1
DNS ServerDomain name resolution server8.8.8.8, 1.1.1.1

Method 1: Configuration Using Netplan

What is Netplan?

Netplan is a network configuration utility introduced in Ubuntu 17.10 that uses YAML format configuration files to configure networks. It can use systemd-networkd or NetworkManager as backends and is primarily used in server environments.

Netplan configuration files are located in the /etc/netplan/ directory. Filenames may vary by system, such as 01-netcfg.yaml, 50-cloud-init.yaml, or 00-installer-config.yaml, so check with ls /etc/netplan/ before editing the appropriate file.

Configuration File Structure

Netplan configuration files are written in YAML format. They are sensitive to indentation, so spaces (2 or 4) must be used instead of tabs, and there must be a space after colons (:).

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      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

Configuration Item Descriptions

ItemDescription
version: 2Netplan version (always use 2)
rendererBackend selection (networkd or NetworkManager)
ethernetsWired network interface settings
dhcp4: noDisable DHCP for manual configuration
addressesIP address and subnet mask to assign
routesRouting settings, default means default gateway
nameserversDNS server list

Applying Configuration

After saving the configuration file, apply changes with sudo netplan apply. If there are syntax errors, error messages are displayed and the original settings are rolled back. Using sudo netplan try before applying automatically reverts to original settings after 120 seconds, allowing safe testing in remote access environments.

Method 2: Configuration Using nmcli

nmcli (NetworkManager Command Line Interface) is a CLI tool for controlling NetworkManager. It enables automation through scripts and allows stable network configuration even in remote SSH sessions.

Checking Current Connections

First, check the current network connection list with nmcli connection show and identify the name of the connection to modify.

Static IP Configuration Commands

# Set IP address
sudo nmcli connection modify "connection-name" ipv4.addresses 192.168.1.100/24

# Set gateway
sudo nmcli connection modify "connection-name" ipv4.gateway 192.168.1.1

# Set DNS
sudo nmcli connection modify "connection-name" ipv4.dns "8.8.8.8 8.8.4.4"

# Change to manual configuration mode
sudo nmcli connection modify "connection-name" ipv4.method manual

# Apply changes
sudo nmcli connection up "connection-name"

If the connection name contains spaces (e.g., “Wired connection 1”), it must be enclosed in quotes. To apply all settings at once, multiple options can be chained to the nmcli connection modify command.

Method 3: Configuration Using nmtui

nmtui (NetworkManager Text User Interface) is a text-based user interface that runs in the terminal. It allows network configuration while visually checking settings, making it useful for users unfamiliar with commands.

nmtui Usage Procedure

Run the interface with sudo nmtui, select “Edit a connection”, then select the network connection to modify. In the IPv4 CONFIGURATION section, change <Automatic> to <Manual> and press <Show> to expand detailed settings. Enter the IP and subnet mask (e.g., 192.168.1.100/24) in Addresses, gateway address in Gateway, and DNS server address in DNS servers. Select <OK> to save, exit with <Back> then <Quit>, and apply changes with sudo nmcli connection up "connection-name".

Verifying Configuration

After setting a static IP, verify that settings are correctly applied with the following commands.

Check ItemCommandExpected Result
IP Addressip aShows configured IP address
Gatewayip routedefault via gateway-address
DNScat /etc/resolv.confnameserver DNS-address
Internet Connectionping -c 4 8.8.8.8No packet loss
DNS Resolutionping -c 4 google.comPing succeeds with domain

Troubleshooting

Common Problems and Solutions

ProblemCauseSolution
netplan apply errorYAML syntax errorCheck indentation, use spaces instead of tabs
No internet connectionGateway errorCheck gateway with ip route, verify router IP
Domain resolution failsDNS configuration errorVerify DNS server address, test with 8.8.8.8
IP conflictAnother device using same IPCheck IPs in use on network and change
Connection lost after configIncorrect IP settingsAccess via console and modify settings

If remote connection is lost after Netplan configuration, physically access the system to modify the configuration file or use sudo netplan try to leverage the automatic rollback feature. To restart NetworkManager, use sudo systemctl restart NetworkManager. To restart the entire network service, run sudo systemctl restart systemd-networkd.

Conclusion

There are three methods to set a static IP on Ubuntu 24.04 LTS: Netplan, nmcli, and nmtui. They are suitable for YAML-based configuration in server environments, CLI environments requiring script automation, and intuitive TUI environments respectively. Setting a static IP maintains stable server operation, remote access, and network service hosting while making network management easier. Static IP configuration is recommended in environments operating servers or network equipment.