Ubuntu

How to change the IP address on Ubuntu

Changing the IP address on your Ubuntu system can be necessary for various situations, such as in the port forwarding process or when you want to run a media server on your network. In most cases, your router’s DHCP server dynamically assigns IP addresses to your network interface. However, you can easily change the assigned IP address on your system by using “netplan” or through the Ubuntu GUI Network settings.

In Ubuntu, the tool utilized for managing and configuring the network settings is known as “netplan”. netplan interacts with the kernel through the systemd-networkd and NetworkManager daemons which are also known as renderers. You have to choose any one from both of them. Netplan reads the network configurations from “/etc/netplan/*.yaml” files, saving the configuration settings for all network interfaces. If you use the netplan command in the Ubuntu terminal, it becomes easy to restart and change network settings.

Now, we will show you how to change the IP address on Ubuntu using terminal and GUI. So, let’s start!

How to change the IP address on Ubuntu terminal using netplan

First of all, list out the active network interfaces by using the “ip” command. The “ip” command is utilized in the Ubuntu terminal to assign, delete routes, put up or down interfaces, etc. Adding “link” in the “ip” command will display the link-layer information, name, and status of an interface, etc. Execute the below-given “ip link” command to know more about your network interfaces:

$ ip link

Next step is to open the “/etc/netplan/*.yaml” file in your nano editor:

$ sudo nano /etc/netplan/*.yaml

The opened “/etc/netplan/*.yaml” file will have the following information:

Now write out the following code in the “/etc/netplan/*.yaml” file to change the IP address on your system:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.2.2/24]
      gateway4:  192.168.2.2
      nameservers:
              addresses: [8.8.4.4, 8.8.8.8]

Here:

  • dhcp4 and dhcp6 are IPv4 and IPv6 DHCP properties.
  • enp0s3 is the network interface name for which we will change the IP address.
  • addresses contain the sequence of addresses for the network interface.
  • gateway4 contains the default gateway’s IPv4 address.
  • nameservers comprise a series of IP addresses for nameservers.

Press “CTRL+O” to save the changes we made in the file:

Apply the modified settings by utilizing the below-given netplan command in your terminal:

$ sudo netplan apply

Now, check out that the IP address of the “enpos3” network interface is changed or not:

$ ip a

You can see that we have successfully changed the IP address on our Ubuntu system:

How to change the IP address on Ubuntu using GUI

Yes, you read it right! Ubuntu also provides the option to change the IP address of your network interface using its Graphical User Interface (GUI). To do so, open up your system “Settings” application by searching it manually in the Application’s search bar:

From the left side vertical menu, select the “Network” settings. After that, click on the “gear” icon to change the IP address of the selected network:

You will see a window displaying settings related to your wired network connection. Now, select the “IPv4” tab from the menu, and you will see that by default “Automatic (DHCP)” IPv4 method is enabled on your system:

Select the “Manual” option; then, add the new IP address, Netmask, Gateway, and DNS-related information in the given fields. Lastly, click on the “Apply” button:

All done! You can check out the updated information by selecting the “details” tab of your network interface:

Conclusion

Ubuntu provides you the option to change the IP address of your network interface, whether you want to do it for port forwarding or running any media server on your system. In an Ubuntu system, netplan” is the network management tool capable of configuring and managing the network settings. This article showed you how to change the IP address using the “netplan” utility in the Ubuntu terminal. The procedure for changing the IP address using Ubuntu GUI is also provided in the article.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.