In this post we will try to change the IP address of a Ubuntu based Linux system from the command line. Though we will be using Ubuntu 16.04 but the steps should work for any version of Ubuntu.
Listing Network Interfaces
We will start by listing all network interfaces for your system. We are doing this so that we know the name of the network for which we want to modify the IP address. Now, go on and run the following command:
Once we run this command, we will see something like:
So, we have two networks mentioned here with much more metadata. To change settings of a network, we will make use of the same command with few more parameters.
Additional parameters with ifconfig
Let’s write a command using ifconfig which will change the IP address of the network ‘enp0s3’ to 192.168.0.1 and also changes the subnet mask 255.255.255.0:
When we run this, we don’t get anything back:
This time, when we again run the ifconfig command, we will see that IP address have changed:
Changing the Default Gateway
We can also modify a network’s gateway with simple command as:
Of course, no output is returned. But we can check the settings with this command:
Let’s run this now:
That’s all. It was super easy to change your IP from the command line. Do check out other linux based lessons as well!