In this guide of Different ways of Configuring Static routes in Linux, we’re going to learn on different ways to configure static routes on a Linux system,  be it Ubuntu, Kali Linux, CentOS, Fedora, Linux Mint or any other Linux system. If you have a new installation of Linux System, I recommend you read any of below articles depending on the Linux distribution you are running:

Top Things to do after fresh installation of CentOS 7 minimal

Top things to do after Fresh Installation of Fedora 23

What to Do after Installing Ubuntu 14.04, 12.04, 13.0

A static route can be defined as a pre-determined path that network information must follow to reach a specific host or network. The static route is normally important for traffic that must pass through an encrypted VPN tunnel or traffic that should take a specific route for reasons of cost or security.
Mostly default gateway is for any and all traffic which is not destined for the local network and for which no preferred route is specified in the routing table. The default gateway is traditionally a dedicated network router.

You can configure static route by various methods, one of them being manually specifying the route on network configuration script.Other methods include using commands such as:

# route add
# ip route

A point to note on the use of both “route add” and “ip route” commands is that they configure routing on the runtime and doesn’t persist the configuration after a reboot. We are going to talk about different ways to set static route.Both temporarily and setting up the permanent static route. Adding static route with route add command. The syntax is:

route add -net <IP>/<MASK> <GW> dev <ethX>

Let’s add a route for interface eth1, network

# route add -net netmask gw dev eth1

Adding static route with ip route command. The syntax:

ip route add <IP>/<MASK> via <GW> dev <ethX>


# ip route add via dev eth1

Adding Static persistent route

Ubuntu/Debian based Systems:

vim /etc/network/interfaces


auto eth1
iface eth1 inet static
up route add -net netmask gw
up route add -net netmask gw


auto eth1 iface eth1 inet static
up ip route add via || true


To get to network and, use default gw

Static route configuration can be stored per-interface in a /etc/sysconfig/network-scripts/route-interface file. For example, static routes for the eth1 interface would be stored in the /etc/sysconfig/network-scripts/route-eth1

# vim /etc/sysconfig/network-scripts/route-eth1




Save and close the file.

route add 2

Restart networking:

service network restart

You can also use:

ifdown eth1;ifup eth1

NOTE: Subsequent static routes must be numbered sequentially, and must not skip any values. For example, ADDRESS0, ADDRESS1, ADDRESS2, and so on.
Checking static routes:

ip route show
netstat -nr
route -n

route added

We have concluded Different ways of Configuring Static routes on Linux. Let me know if you encounter any issues and I’ll be happy to assist.

Simple way to configure static ip address on CentOS 6.x and CentOS 7 Server

How to Install Latest Kamailio SIP Server on CentOS 7


Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here