How to Set Static IP Address and Modifying Routing Table on Linux

Here’s how to get networking all the way up in a matter of seconds using just a few commands.

How To Manually Set Static IP Address And Route On Linux

This article will show you how to configure a static IP address from the command line on Linux and how to modifying routing table.

Configuring IP address and routes from the command line is one of the mandatory skill that every Linux administrator should learn. In this article we are going to review how we can assign a static IP address using ip and ifconfig commands. In addition to, we will discuss how we can use ip route command to create a static route and to change the default gateway for the Linux system.

Set static IP address using ifconfig command (deprecated)

Nowadays ifconfig command is deprecated and replaced by ip command in Linux. However, ifconfig command is still works and available for most of the Linux distributions. It is used to configure the network interfaces.

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.

ifconfig eth0

With -a argument added, the command displays the status of all interfaces, even those that are down.

ifconfig -a

To configure temporary IP address, use the following command syntax:

ifconfig <interface> <ipv4address> netmask <subnetmask>

Assuming you want to make the following changes:

  • Network device name is eth0
  • Change the IP address to the static value
  • Set the subnet mask to
ifconfig eth0 netmask

On success, the command will not show any output. However, the IP address configured this way is not permanent and will be lost after a reboot. To make permanent changes to IP address you need to edit configuration file according to your Linux distribution.

Set static IP address using ip command

To find your current IP address, you can use the ip command with the a option for address.

ip a

To add address with netmask to device eth0, you would type:

ip address add dev eth0

To delete all addresses from an interface eth0:

ip address flush dev eth0 

To bring interfaces up or down, use the ip link set dev followed by the device name and the desired state. For example, to bring the interface eth0 online, you would type:

ip link set dev eth0 up

And to bring it offline:

ip link set dev eth0 down

Displaying and altering the Linux routing table

We basically use the ip route command to create static routes in Linux to specific hosts or to change the default gateway for the Linux system. 

To display Linux routing table type the following command:

ip route show

To add a new entry to the routing table, use the ip route add command followed by network or device name.

Add a route to via the gateway at

ip route add via

To add a default route, use the keyword default. All network packets that cannot be sent according to the previous entries of the routing table are sent through the following default gateway:

ip route add default via dev eth0

To delete the default route:

ip route del default

The syntax for deleting a route is the same as when adding. The following command will delete a route for via the gateway at

ip route add via

Leave a Reply

Your email address will not be published.

Latest from Linux Knowledge