How to Change Your IP Address From the Command Line in Linux

Manostaxx

The text that follows is owned by the site above referred.

Here is only a small part of the article, for more please follow the link

SOURCE: https://www.howtogeek.com/118337/stupid-geek-tricks-change-your-ip-address-from-the-command-line-in-linux/

image

Almost everybody can figure out how to change their IP address using an interface, but did you know you can set your network card’s IP address using a simple command from the command line?

This trick should work on all Debian-based Linux distros, including Ubuntu. To get started, typeifconfig into the terminal and hit Enter, take note of the name of the interface that you want to change the settings for.

image

To change the settings, you also use the ifconfig command, this time with a few parameters:

sudo ifconfig eth0 192.168.0.1 netmask 255.255.255.0

That’s about all all you need to do to change your IP. Of course, the above command assumes a few things:

  • The interface that you want to change the IP for is eth0
  • The IP you want to give the interface is 192.168.0.1
  • The Subnet Mask you want to set for the interface is 255.255.255.0

image

If you run ifconfig again, you will see that your interface has now taken on the new settings you assigned to it.

image

If you wondering how to change the Default Gateway, you can use the route command.

sudo route add default gw 192.168.0.253 eth0

This will set your Default Gateway on the eth0 interface to 192.168.0.253.

image

To see your new setting, you will need to display the routing table.

route -n

image

That’s all there is to it.

Leave a Reply

Your email address will not be published. Required fields are marked *