How to set a static IP Address from the Command Line in GNU/Linux using ifconfig and route 5

Assuming you want to make the following changes to the network device eth0

  1. Change the IP to the static value
  2. Set the Subnet Mask to
  3. Set the Default Gateway for the device to be

you can perform these changes using the following two commands

sudo ifconfig eth0 netmask;
sudo route add default gw eth0;


ifconfig is an application that allows you to configure a network interface.
It is used to configure the kernel-resident network interfaces. and it is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.
If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.


route is an application that allows you to show and manipulate the IP routing table. The primary use of route is to set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program.
When the add or del options are used, route modifies the routing tables. Without these options, route displays the current contents of the routing tables.