Minggu, 26 Februari 2023

STATIC ROUTE-rhel7

 

How to add a new static route on RHEL7 Linux

Previously we have talked about how to configure a default gateway on RHEL7 Linux. This time we will talk about how to add a static route on RHEL7 Linux.

Any network we are trying to reach is accessed via default gateway only if it is not implicitly overwritten by another static route definition. Let’s have a look at a current routing table on our Redhat 7 Linux box:

root@rhel7 ~]# ip route show
default via 10.1.1.1 dev enp0s3  proto static  metric 1024 
10.0.0.0/8 dev enp0s3  proto kernel  scope link  src 10.1.1.110

From the above we can see that any packets to reach a destination network ID 10.0.0.0/8 should travel via enp0s3 interface with 10.1.1.110 and any other destination network not implicitly defined should use a default gateway 10.1.1.1.

To add a new static route means to define yet another destination 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 15.15.0.0/24 via 10.1.1.110 ip address and enp0s3 interface. To do this create a new file route-enp0s3 in a /etc/sysconfig/network-scripts/ directory. To define an above mentioned persistent static route add a following line into your enp0s3 file:

15.15.0.0/24 via 10.1.1.110 dev enp0s3

Once done restart your network:

root@rhel7 ~]# systemctl restart network

Next, check whether your new static route was correctly defined:

[root@rhel7 ~]# ip route show

Tidak ada komentar:

Posting Komentar