Reading Time: 2 minutes

Change-IP-Address-on-Ubuntu

While working on Ubuntu systems, many situations force you to change the IP address. In this article, we will reveal how to change Ubuntu IP address. You can easily modify the designated IP address on your system through “netplan” or by using the Ubuntu GUI Network settings.

The basic tool used to change network preferences in Ubuntu is called netplan. This tool corresponds with the kernel via NetworkManager daemons and systemd-networkd, also termed as renderers. Netplan collects the configurations of the network through “/etc/netplan/*.yaml” files while making the configuration preferences for all interfaces of the network.

Let’s find out how to change IP address on Ubuntu through terminal and GUI.

How to Change Ubuntu IP Address in Terminal through Netplan

First thing first, to change Ubuntu IP address, enlist the running network interfaces by running the Ubuntu “ip” command. This command is used in Ubuntu to rearrange interfaces and assign or delete routes, etc.

If you add “link” in the “ip” command it will show the name, link-layer details, the status of an interface, etc. Run the following “ip link” command to get more information about your network systems:

$ ip link 

Next step involves opening the “/etc/netplan/*.yaml” file in editor:

$ sudo nano /etc/netplan/*.yaml 

Up next, write the code given below in the “/etc/netplan/*.yaml” file to alter the IP address on your computer:

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] 

Note:

  • dhcp4 is IPv4 properties and dhcp6 is IPv6 DHCP properties.
  • enp0s3: name of the network interface.
  • addresses enclose the order of addresses for the network system.
  • gateway4 holds the IPv4 address of the default gateway (If you’re still confused, then check out our guide on how to find your default gateway IP address)
  • nameservers hold an order of IP addresses for nameservers.

Now hit “CTRL+O” to reserve the changes done in the file.

After saving, apply the changed settings by using the following netplan command in your terminal:

$ sudo netplan apply 

Next, confirm whether the IP address of the “enpos3” network interface is modified or not:

$ ip a 

After running this command, the result will show a modified IP address.

How to Use GUI to Change the IP Address on Ubuntu

Ubuntu also offers the convenience to modify the IP address of the network interface using its GUI portal. Here’s how you can do that:

  1. Launch Settings and click the Network tab in the menu on the left.
  2. Click on the gear icon to alter the selected network’s IP address.
  3. Next up, select the “IPv4” section from the menu.
  4. Uncheck the Automatic (DHCP) option under the IPv4 menu and select “Manual.”
  5. Now add the desired Netmask, IP address, Gateway, and information related to DNS.
  6. After filling in all the information click on the “Apply” button.
  7. Here you go! You can click the “Details” button to confirm the modified IP address.

Ubuntu Linux Change IP using Command Line Config File

Follow these steps to change Ubuntu server IP address using Command Line Config File:

Launch terminal and write the following command:

sudo vi /etc/network/interfaces

Or

sudo gedit /etc/network/interfaces 

Go to the eth0 section and set up the IP address as desired.

Now save and close the file and restart the network through this command:

$ sudo /etc/init.d/networking restart 

To confirm the new IP address run this command:

$ ifconfig eth0

$ ifconfig 

How to Statically Assign an IP Address

Whenever you are connected to a network, your device immediately gets an IP address from the network. There are two types of IP addresses; static and dynamic. Let’s find out how to assign a static IP address.

  1. First of all, launch Terminal.
  2. Next, run “ip addr show” command to see the network adapter for which you want to change the IP address, and then execute.
  3. Run “ip addr add X.X.X.X/24 dev eth0” command to modify the IP address (you can use any IP address you want to assign).
  4. Once executed, verify the new IP address by running “ip addr show”

FAQs

Run the “ifconfig” command accompanied by the network interface name and the new IP address you wish to change on your system. For the subnet mask, you can add a “netmask” clause along with the subnet mask or utilize the CIDR code straightaway.

Here is how to set up a static IP address using the command line in Ubuntu:

  1. Get the network interface and default gateway’s name.
  2. Locate the Netplan configuration.
  3. Edit the Netplan configuration to set up a static IP address.

Follow the steps below to find your IP address in Ubuntu 20.04:

  1. Run the command $ ip a to check the internal IP.
  2. Execute the command $ systemd-resolve –status | grep Current for checking the current DNS server IP address.
  3. Run command $ ip r for displaying the default gateway IP.

Final Thoughts

Ubuntu offers the option to modify the network interface IP address, whether you are doing it for running any media server on your device or port forwarding.

Netplan is the network management tool in the Ubuntu system that is used to configure and manage the network settings.

In this article, we have elaborated on how to change Ubuntu IP address using the “netplan” tool through the Ubuntu terminal, as well as the method for modifying the IP address through Ubuntu GUI.