Skip to Content

Change IP Address in Ubuntu: A Comprehensive Guide

In the world of Linux, understanding how to manage your network settings is a fundamental skill.

For Ubuntu users, the need to change an IP address can arise for various reasons, from setting up a server with a stable address to troubleshooting network connectivity issues.

This guide will walk you through the various methods to change your IP address on an Ubuntu system, whether you prefer the ease of a graphical interface or the power of the command line.

Get Your Free Linux training!

Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Start Learning Linux today - Free!

Understanding IP Addresses in Ubuntu: Static vs. Dynamic

Before diving into the “how,” it’s essential to understand the “what.” An IP (Internet Protocol) address is a unique numerical label assigned to each device connected to a computer network. There are two primary ways an IP address is assigned:

  • Dynamic IP Address: This is the most common method for consumer devices. Your Internet Service Provider (ISP) or local network’s router automatically assigns an IP address from a pool of available addresses using a protocol called DHCP (Dynamic Host Configuration Protocol). This address can change over time.
  • Static IP Address: A static IP address is manually configured and does not change. This is often necessary for servers, network printers, or any device that needs to be consistently accessible at the same address.

Changing Your IP Address Using the Graphical User Interface (GUI) in Ubuntu

For Ubuntu Desktop users, the most straightforward way to change your IP address is through the system’s network settings. This method is ideal for those who are more comfortable with a visual interface.

Here are the steps to set a static IP address using the GUI:

  1. Open Settings: Click on the system menu in the top-right corner of your screen and select “Settings.”
  2. Navigate to Network Settings: In the Settings window, find and click on the “Network” tab in the left-hand pane. For a wired connection, you will see a “Wired” section, and for a wireless connection, a “Wi-Fi” section.
  3. Access Connection Details: Click on the gear icon next to the network connection you wish to modify.
  4. Configure IPv4 Settings: In the new window, select the “IPv4” tab.
  5. Set to Manual: By default, the “IPv4 Method” will be set to “Automatic (DHCP).” Change this to “Manual.”
  6. Enter IP Address Details: You will now see fields to enter your desired IP address, netmask, and gateway. You will also need to provide the addresses of DNS (Domain Name System) servers. A common choice for DNS is Google’s public DNS servers: 8.8.8.8 and 8.8.4.4.
  7. Apply Changes: Once you have entered all the necessary information, click the “Apply” button.
  8. Reconnect: To ensure the changes take effect, it’s a good practice to disconnect and then reconnect to the network.

Harnessing the Power of the Command Line to change your IP address

For server administrators or users who prefer the command line, Ubuntu offers powerful tools to manage network configurations. The primary tool for this in modern Ubuntu versions is Netplan. Netplan is a utility that uses YAML configuration files to manage network interfaces.

Temporarily Changing Your IP Address

If you only need to change your IP address for a short period, you can do so without altering any configuration files. This change will be lost upon reboot.

  1. Open the Terminal: You can open the terminal using the keyboard shortcut Ctrl + Alt + T.
  2. Identify Your Network Interface: Use the ip a or ip addr show command to list your network interfaces and their current IP addresses. Note the name of the interface you want to configure (e.g., eth0, enp0s3).
  3. Assign a New IP Address: Use the ip addr add command to assign a new IP address. For example: Replace 192.168.1.100/24 with your desired IP address and subnet mask, and enp0s3 with your interface name.
    sudo ip addr add 192.168.1.100/24 dev enp0s3
    
    
  4. Verify the Change: You can confirm the new IP address by running the ip a command again.

Permanently Changing Your IP Address with Netplan

For a lasting change, you’ll need to edit a Netplan configuration file. These files are typically located in the /etc/netplan/ directory.

  1. Identify the Configuration File: Use the ls /etc/netplan/ command to find the name of your Netplan configuration file. It will usually have a .yaml extension (e.g., 01-netcfg.yaml).
  2. Back Up the Configuration File: Before making any changes, it’s wise to create a backup of your current configuration:
    sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak
    
    
  3. Edit the Configuration File: Open the file with a text editor like nano or vim:
    sudo nano /etc/netplan/01-netcfg.yaml
    
    
  4. Configure a Static IP: Modify the file to set a static IP address. The syntax is crucial, as YAML files are sensitive to indentation. Here is an example configuration for a wired connection: Make sure to replace enp0s3 with your network interface name and adjust the IP address, gateway, and DNS servers to match your network’s requirements.
    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: no
          addresses: [192.168.1.100/24]
          gateway4: 192.168.1.1
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]
    
    
  5. Apply the Changes: After saving the file, apply the new configuration using the following command: Netplan will parse the configuration and apply the changes to your network interface.
    sudo netplan apply
    
    
  6. Verify the New IP: You can check if the IP address has been successfully changed by running ip a.

Renewing a DHCP Lease

Sometimes, you may not want to set a static IP but rather force your system to request a new IP address from the DHCP server. This is known as renewing the DHCP lease.

You can do this from the command line using the dhclient command.

  1. Release the Current IP Address: First, release the existing IP address for a specific interface: For example: sudo dhclient -r eth0
    sudo dhclient -r <interface_name>
    
    
  2. Obtain a New IP Address: Now, request a new IP address from the DHCP server: For example: sudo dhclient eth0
    sudo dhclient <interface_name>
    
    

It’s often recommended to combine these two commands to avoid losing your connection, especially if you are connected remotely:

sudo dhclient -r <interface_name> && sudo dhclient <interface_name>

For newer versions of Ubuntu that may use different DHCP clients, you might need to use networkctl or nmcli to renew the lease. For instance, with systemd-networkd, you can use:

sudo networkctl renew <interface_name>

If using NetworkManager (common on Desktop)

You can use nmcli:

# Renew DHCP lease for eth0
sudo nmcli device reapply eth0

# Or bring the interface down and up
sudo nmcli device disconnect eth0
sudo nmcli device connect eth0

By following these steps, you can confidently manage and change the IP address of your Ubuntu system to suit your networking needs.

Whether you’re a desktop user who prefers a graphical approach or a server administrator comfortable with the command line, Ubuntu provides the flexibility to handle your network configuration with ease.