Configuring a static IP address in Ubuntu provides consistent network identification that is essential for servers, network printers, and any device requiring reliable remote access. Unlike dynamic assignments handled by DHCP, a static IP eliminates the risk of address changes disrupting critical services or workflows.
Understanding Network Management in Modern Ubuntu
Before diving into the configuration steps, it is important to understand the networking architecture of contemporary Ubuntu installations. Since version 17.10, Ubuntu has moved away from the traditional ifupdown tools in favor of Netplan, a YAML-based configuration system designed for simplicity and consistency across different deployment scenarios. This change affects how you define and apply network settings, so verifying your Netplan configuration is the logical first step.
Checking Your Current Network Interface Name
Unlike older versions of Linux where interfaces were predictably named eth0 or wlan0, modern Ubuntu uses a predictable network interface naming scheme based on firmware, topology, and location. This means your physical adapter might be named enp0s3, ens3, or something similar. Identifying the correct interface name is critical before editing any configuration files.
Verifying the Active Interface
Open your terminal and utilize the ip command to list current network interfaces. Typing ip link will display all available interfaces along with their operational status. Look for an interface that shows state UP and has a current link-level address; this is the adapter you intend to configure statically.
Configuring Static IP via Netplan
With the interface name confirmed, you can proceed to modify the Netplan configuration file, which is typically located in the /etc/netplan/ directory. The exact filename varies but usually ends in .yaml; common examples include 01-netcfg.yaml or 50-cloud-init.yaml. You must have administrative privileges to edit this file.
Example Netplan Configuration
Below is a standard template for assigning a static IP address. You will need to adjust the address, gateway, and DNS values to match your specific network environment. Ensure the indentation uses spaces rather than tabs, as YAML is sensitive to formatting errors.
network: version: 2 renderer: networkd ethernets: enp0s3: addresses: - 192.168.1.100/24 gateway4: 192.168.1.1 nameservers: addresses: - 8.8.8.8 - 8.8.4.4 Applying the Changes and Verifying Connectivity Once the YAML file is saved with the correct syntax, you must apply the new configuration. This is done using the netplan command, which compiles the YAML and pushes the settings to the kernel networking stack. A misconfigured entry can prevent you from accessing the server, so proceed carefully.
Applying the Changes and Verifying Connectivity
Execute the command sudo netplan apply to implement the changes. This command is non-disruptive to existing SSH sessions in many cases, unlike the older ifdown / ifup method. After the terminal returns, you can verify the new static IP address by running ip addr show enp0s3 and confirming the inet line matches your configuration.