Configuring a static IP address on Ubuntu provides consistent network identification that is essential for servers, network printers, and any device requiring reliable remote access. Unlike dynamic assignment via DHCP, a static IP eliminates address changes that disrupt automated workflows or scheduled tasks. This guide walks through the necessary steps for both modern Ubuntu desktop and server editions using Netplan, the current standard for network management.
Understanding Netplan and Network Configuration
Since Ubuntu 17.10, the distribution transitioned to Netplan, a YAML-based configuration system that simplifies network management by generating backend configurations for NetworkManager or systemd-networkd. You will find the primary Netplan configuration files within the /etc/netplan/ directory, typically named with a 01-netcfg.yaml or similar prefix. Before editing these files, it is crucial to identify your active network interface name, which is usually enp0s3, ens33, or similar, and to back up the existing configuration to recover quickly from potential syntax errors.
Preparing to Configure a Static IP Address
Collecting specific network details is the logical first step before modifying any configuration. You need your desired static IP address, ensuring it falls outside the DHCP range managed by your router to prevent conflicts, along with the appropriate network mask, gateway address, and DNS server IPs. Mistakes in these values, such as an incorrect gateway, will prevent your machine from reaching the broader network, so verify this information from your router or current DHCP lease details.
Identifying Your Network Interface
Use the ip command in the terminal to list active interfaces and confirm the exact name you will use in the configuration file. The output will show interfaces such as eth0 for older systems or enpXsY for newer hardware, and you should note the one that currently receives an IPv4 address via DHCP. This name is then referenced directly in your Netplan YAML file to apply the static settings to the correct network adapter.
Applying the Static IP Configuration via Netplan
With the interface name and network details prepared, you can edit the existing Netplan YAML file using a terminal text editor like nano or vim. Below is a common template structure that you can adapt by replacing the placeholder values with your specific network settings. Pay strict attention to spacing and indentation, as YAML is sensitive to these elements and will cause the configuration to fail if improperly formatted.