change ip address ubuntu

IP address assignment is typically handled by a DHCP server. You can request the server to end the DHCP lease and release your device’s current IP address. Depending on how the server is configured, your device may or may not be assigned a different IP address with this method.

Another way to change your IP address is with DHCP reservation. But that’s a feature that’s configured from your router settings. Instead of such methods, we’ll specifically cover ways to change your IP address directly from Ubuntu in this article.

Network Settings

The easiest way to change your IP address on Ubuntu is via the NetworkManager GUI.

  1. Open the Settings app and switch to the Network (wired) or Wi-Fi tabs depending on which connection you want to change the IP address for.
    ubuntu settings app
  2. Click on the Settings cog next to the connection.
    ubuntu network settings
  3. In the IPv4 tab, set the IPv4 method to Manual and fill in the IP Address, Gateway, and Netmask values. You can leave DNS to Automatic, or toggle off Automatic and manually enter the DNS server.
    ubuntu ipv4 configuration
  4. Press Apply and reset the connection (toggle off/on) to apply the changes.
    apply ip changes ubuntu

Netplan

Netplan is used to configure networking on Linux systems through the networkd or NetworkManager backends. It reads the configuration from a YAML description file and hands off device control to the specified networking daemon.  

To change your IP address, you’ll need to modify the netplan config file. The default config file named 01-network-manager-all.yaml or 50-cloud-init.yaml can be found in the /etc/netplan directory. 

First, check the interface’s logical name.

sudo lshw -c network

Open the config file with a text editor like nano.

sudo nano /etc/netplan/*.yaml

Use the configuration provided below. Ensure the number of prefix spaces is correct as shown here or the config won’t work.  

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp1s0:
      dhcp4: no
      addresses:
        - 192.168.122.50/24
      routes:
        - to: default
          via: 192.168.122.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

We’re using NetworkManager as the backend here. We specified enp1s0 as the Ethernet interface and DHCP is disabled. Then, we set the interface’s IP address with a Class C subnet prefix length (192.168.122.50/24).

We then set the gateway, defined it via a default route, and finally set the DNS servers. Remember to change these values as appropriate for your own network. After your configuration looks good, apply the new config with

sudo netplan apply

You can verify the changes with

ip a

Ip Command

IP Address changes made by the previous two methods were persistent. But if you only want to make a temporary IP change that’ll revert upon connection reset, you can use the ip command.

First, identify the interface.

sudo lshw -c network

Use the add option to add a new IP address to the interface. Remember to adjust the IP address and interface name values.

sudo ip addr add 192.168.122.186/24 dev enp1s0

Remove the old IP address with del option like so

sudo ip addr del 192.168.122.11/24 dev enp1s0

Here, we changed the IP address of the enp1s0 interface from 192.168.122.11 to 192.168.122.186. Once again, you can verify the change with

ip a

Networkd

Ubuntu desktops use the NetworkManager daemon by default, whereas Ubuntu servers normally handle network configuration with networkd. On such systems, you can edit the network configs in /etc/systemd to change your IP address.

Open the config file with a text editor like nano.

sudo nano /etc/systemd/networkd.conf

Use the following configuration and adjust the interface name, IP address, gateway, and DNS values as you require.

[Match]
Name=enp1s0

[Network]
Address=192.168.122.154/24
Gateway=192.168.122.1
DNS=8.8.8.8

Save the new configuration and restart the networkd service to apply the changes.

sudo systemctl restart systemd-networkd

Nmcli

You can also use NetworkManager’s command-line version (nmcli) to manage network configurations such as your IP address.

First, list your connections and note the connection name.

nmcli c

You can directly change the IP address configuration, replacing the values with your own like so

sudo nmcli con modify 'Wired connection 1' ipv4.method manual ipv4.addresses 192.168.122.141/24 ipv4.gateway 192.168.122.1 ipv4.dns "8.8.8.8, 8.8.4.4"

We identified that we need to modify Wired connection 1 with the previous command. Then, we set the IPv4 method to manual and set the IP address with prefix, gateway, and DNS values.

Finally, activate the connection and verify the change with

sudo nmcli con up id ‘Wired connection 1’
ip a

This is sufficient for basic configuration, but nmcli is a highly versatile tool. If you want to learn to make advanced config changes, we recommend using the interactive editor.

sudo nmcli connection edit ‘Wired connection 1’

The editor will display which settings you can edit (connection profile, ipv4, proxy, etc). Enter help to list the available commands (set, print, describe, save, quit, etc). Enter print ipv4 to list the modifiable IPv4 settings and properties.

You can use the describe command to view the documentation for each setting (e.g., describe ipv4, describe ipv4.addresses). Now, use the set command to set the property values like so

set ipv4.method manual 
set ipv4.addresses 192.168.122.141/24 
set ipv4.gateway 192.168.122.1 
set ipv4.dns 8.8.8.8, 8.8.4.4

Save the connection with save persistent or save temporary. Then, enter quit to exit nmcli and verify the new config with

ip a
Anup Thapa

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.