Configuring a stable network identity is a fundamental skill for managing any Linux environment. You might find yourself needing a static IP address to ensure your server remains reachable via SSH after a reboot, or perhaps you are troubleshooting a connectivity issue where a DHCP conflict has knocked your machine offline.
Modern Ubuntu systems primarily use Netplan to manage persistent network configurations. This guide explains how to use both Netplan for permanent changes and the ip command for quick, temporary adjustments. Before you begin, it is highly recommended that you learn how to find your IP address in Ubuntu to verify your current settings.
Table of Contents
Key Takeaways: Changing IP Settings
- Netplan → The standard tool for persistent network configuration in Ubuntu. It uses YAML files located in
/etc/netplan/. - ip command → Best for temporary changes that take effect immediately but are lost after a system reboot.
- YAML Syntax → Netplan configuration is sensitive to indentation and spaces; incorrect formatting will cause the configuration to fail.
- sudo Requirement → Administrative privileges are mandatory for all network changes to maintain Linux system security.
Method 1: Persistent Changes with Netplan
Netplan is the modern standard for Ubuntu networking. It acts as an abstraction layer, allowing you to define your network in a YAML file which the system then applies to the underlying hardware.
1. Locate the configuration file: Netplan files are typically found in /etc/netplan/. Look for files ending in .yaml, such as 01-netcfg.yaml or 50-cloud-init.yaml.
2. Edit the file for a Static IP: Open the file with a text editor (like vi or nano) using sudo. A standard static IP configuration looks like this:
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
3. Apply the changes: After saving the file, you must run the following command to make the settings live: sudo netplan apply.
Method 2: Temporary Changes with the ip Command
If you only need to change an IP for a single session, use the ip utility. This is excellent for testing but remember that these settings will disappear once the machine restarts. For a deeper dive, see our guide on understanding the IP command in Linux.
1. Assign the new IP: Specify the address, subnet mask (in CIDR notation), and the interface name (e.g., enp0s25): sudo ip addr add 10.102.66.200/24 dev enp0s25.
2. Set the default gateway: To allow the machine to reach the internet, add a default route: sudo ip route add default via 10.102.66.1.
Method 3: Using the nmcli Utility
On Ubuntu Desktop or systems where NetworkManager is active, you can use the nmcli tool for a command-line approach to connection management. For a full list of capabilities, check out our ultimate nmcli cheat sheet.
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
Run this to modify an existing connection: sudo nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.1.50/24 ipv4.method manual Follow this by restarting the connection: sudo nmcli connection up "Wired connection 1"
Step-by-Step Process: Setting a Permanent Static IP
- Open your terminal and identify your interface name using
ip link show. - Navigate to the Netplan directory:
cd /etc/netplan/. - Backup your existing config:
sudo cp <filename>.yaml <filename>.yaml.bak. - Edit the YAML file to include your new addresses, gateway, and nameservers.
- Test the syntax for errors:
sudo netplan generate. - Commit the changes:
sudo netplan apply. - Verify the new address: Type
ip addr showto confirm the update.
Summary Tables
| Goal | Recommended Tool | Persistence |
|---|---|---|
| Permanent Server Setup | Netplan | Yes (Saves to disk) |
| Temporary Lab Testing | ip addr | No (Lost on reboot) |
| Managed Desktop Link | nmcli | Yes (Via NetworkManager) |
| Netplan Keyword | Purpose | Example |
|---|---|---|
| addresses | Sets the IP and Subnet | 192.168.1.10/24 |
| via | Defines the Gateway | 192.168.1.1 |
| nameservers | Sets DNS providers | [8.8.8.8, 1.1.1.1] |
| dhcp4 | Enables/Disables DHCP | true or false |
FAQs
What does the /24 mean at the end of an IP? This is the subnet mask in CIDR format. /24 represents a mask of 255.255.255.0, which is the standard for most local area networks.
Why did my system stop working after I edited the Netplan file? Netplan is extremely sensitive to spaces. Ensure you are using spaces (not tabs) for indentation and that your YAML structure matches the examples exactly.
How do I switch back to automatic (DHCP) addressing? In your Netplan file, remove the addresses, routes, and nameservers blocks and set dhcp4: true under your interface. Run sudo netplan apply to finish.


