How-To Geek

Stupid Geek Tricks: Change Your IP Address From the Command Line in Linux


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?

Changing Your IP From the Command Line in Linux

Note: This will work on all Debian based Linux Distro’s.

To get started type ifconfig into the terminal and hit enter, take note of the name of the interface that you want to change the settings for.


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

sudo ifconfig eth0 netmask

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
  • The Subnet Mask you want to set for the interface is


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


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

sudo route add default gw eth0

Will set your Default Gateway on the eth0 interface to


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

route -n


That’s all there is to it.

Taylor Gibb is a Microsoft MVP and all round geek, he loves everything from Windows 8 to Windows Server 2012 and even C# and PowerShell. You can also follow him on Google+

  • Published 07/11/12

Comments (5)

  1. Forqt

    How about setting dhcp?

  2. Bladeservers

    Nice, But how about on windows?

    Is it even possible?

  3. Rich

    Bladeservers: Windows also has a route command. To set the default gateway to, you’d type this:

    route add mask

  4. Rich

    Also, here’s how to set the IP manually in Windows:

  5. markossx

    Eeh, this command is deprecated, we should use ip from iproute or iproute2 package…

Enter Your Email Here to Get Access for Free:

Go check your email!