On my previous tutorial How to configure Linux static IP address on Debian / Ubuntu, we configure IP Address from the configuration file in /etc/network/interfaces and editing some lines for configuring the IP Address. but in this tutorial we will learn How to change ip address in linux directly by using the command line. You can change your interface IP Address just with a simple command, it’s more faster than editing the interfaces configuration files.
This method useful when you need to change your IP address in a hurry, but this method isn’t save your IP configuration as the previous method do, this method just save your configuration until you restart your PC and the configuration will be revert back to default. So How to change ip address in linux using command line ? Follow my instruction below.
Note : This tutorial works on all Debian based distribution !
How to change ip address in linux using command line ?
Check the interface
To get started, check which interface you want to change the ip address is by using command ifconfig.
Change the Interface IP Address from command line
After check which interface you want to configure, now it’s time to change ip address, to change ip address just like before use the ifconfig command.
$ sudo ifconfig eth0 192.168.1.1 netmask 255.255.255.0
That’s all about you need to do to change your IP address via command line, of course the above command assumes a few things:
- eth0 : the name of interface you want to configure
- 192.168.1.1 : IP Address you want to give to the interface
- netmask 255.255.255.0 : Subnet mask for the IP Address.
Execute those command and after that check again your interface with ifconfig, you will see now the settings has taken the settings you assigned to it.
Add Default Gateway
Now you are wondering How do I add Default gateway ? so I can connect to the other network, such as internet. It’s easy to add default gateway, just by using route command.
$ sudo route add default gw 192.168.1.254 eth0
Here is some explanations the command above :
- 192.168.1.254 : Your gateway IP address.
- eth0 : the interface you want to assign default gateway.
Now check your new settings on the routing table :
$ route -n
That’s all for my tutorial How to change ip address in linux using command line, If you have some suggestion or other methods to change ip address, just leave a comment below. Thank You !