How to add static route on CentOS 7 and RHEL 7

In this tutorial, we will see how to add static route on CentOS 7 and RHEL 7. We will also know what is static route? And why we need to add static route? So first of all we should know what is static route?

What is static route?

Static routing is a form of routing that occurs when a router uses a manually-configured routing entry, rather than information from a dynamic routing traffic. Network administrator can manually configured static routes by adding in entries into a routing table.

Static routes are fixed and do not change if the network is changed or reconfigured. Static routing and dynamic routing are not mutually exclusive.

Dynamic routing and static routing are usually used on a router to maximize routing efficiency and to provide backups in the event that dynamic routing information fails to be exchanged.

For more details about static route you can Click Here

Why we use static route?

  1. Static routing can be used to define an exit point from a router when there is no any other routes are available or necessary. This is called a default route.
  2. Static routing can be used for small networks which require only one or two routes.
  3. Static routing is often used as a complement to dynamic routing to provide a failsafe backup in the event that a dynamic route is unavailable.

Now let’s start static route configuration. We can check our IP table with below commands like below:-

[root@urclouds ~]# ip route show
default via dev enp0s3 dev enp0s3  scope link  metric 1002 dev enp0s3  proto kernel  scope link  src dev virbr0  proto kernel  scope link  src
[root@urclouds ~]#

In the above screen shot you can see that any packets to reach a destination network ID should travel via enp0s3 interface with and any other destination network not implicitly defined should use a default gateway

Now I am going to add one static route where we can define Network as well as specify via which IP address and interface the packet should travel through in order to reach its destination.

For example, let’s add a static route to destination network via ip address and enp0s3 interface.

To do this we need to create a new file route-enp0s3 in a /etc/sysconfig/network-scripts/ directory.

We can define an above mentioned persistent static route add a following line into our route-enp0s3 file. Like below:-

[root@urclouds network-scripts]# cat route-enp0s3 via dev enp0s3
[root@urclouds network-scripts]#

After entry into the file we need to restart network service. Like below:-

[root@urclouds ~]# service network restart
Restarting network (via systemctl):                        [  OK  ]
[root@urclouds ~]#

we need to check our new static route has been correctly defined or not.

[root@urclouds ~]# ip route show
default via dev enp0s3 via dev enp0s3 dev enp0s3  scope link  metric 1002 dev enp0s3  proto kernel  scope link  src dev virbr0  proto kernel  scope link  src
[root@urclouds ~]#

That’s all you can see we have successfully added one static route on CentOS 7.

You can also see Network configuration after CentOS 7 minimal installation.

This Post Has 10 Comments

  1. short term loans no credit check no brokers

    I like this, but I do have a question. Do you mind answering?

  2. oprolevorter

    You made some clear points there. I looked on the internet for the topic and found most persons will approve with your blog.

  3. Crave Freebies

    Someone essentially help to make severely articles I’d state. That is the very first time I frequented your web page and to this point? I amazed with the research you made to create this actual put up amazing. Excellent activity!

  4. Karl

    Very rapidly this website will be famous amid all blogging and site-building visitors, due to it’s nice content

  5. watch

    This blog was… how do I say it? Relevant!! Finally I have found something that helped me. Appreciate it!

  6. card game baccarat -

    I loved this post! I read your blog fairly often and you
    are always coming out with some great stuff. I will shares this on my facebook, instagram and some of my loyalty followers.
    Great jobs! Keep work it with it.

  7. Rosendo Aures

    I just want to say I am beginner to blogging and absolutely loved you’re web page. Probably I’m going to bookmark your website . You actually come with excellent articles and reviews. Thanks a bunch for revealing your blog.

  8. Wilbur

    Thanks very nice blog!

  9. Marisol

    I’m really impressed with your writing skills as well as with the layout on your blog.
    Is this a paid theme or did you modify it yourself?
    Either way keep up the nice quality writing,
    it’s rare to see a great blog like this one these days.

Leave a Reply