Setting Static Routes in Linux

in linux •  7 years ago  (edited)

Linux Set Static Route




Linux


Description:


This article will go through the proper way to set a static route on Linux.


RHEL RHEL   &   CentOS CentOS Installations:


1.    Get Interface Name:

Run an ifconfig or ip addr in order to grab the interface name, that you want to set the route traffic to go through.


ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:40:78:ec
          inet addr:10.0.0.24  Bcast:10.79.0.255  Mask:255.255.255.0
          inet6 addr: 2606:a000:4f85:ac00:a00:27ff:fe40:78ec/64 Scope:Global
          inet6 addr: fe80::a00:27ff:fe40:78ec/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:177 errors:0 dropped:30 overruns:0 frame:0
          TX packets:82 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:17929 (17.5 KiB)  TX bytes:9417 (9.1 KiB)


2.    Create Route File:

Create a new file named /etc/sysconfig/network-scipts/route-eth0
This file is titled route-eth0 to correspond to the adapter that we want to send the
through in order to get to the selected route.

  • The contents of the file will simply be the ip subnet that you want to get to, and the
    IP address of the interface that you want to send the traffic to in order to get to the
    specified subnet.
10.2.0.0/16 via 10.0.0.24


3.    Restart the Network Services:

systemctl restart network.service


4.    Verify the route:

route -n


Debian Debian   &   Ubuntu Ubuntu Installation:


1.    Get Interface Name:

Run an ifconfig or ip addr in order to grab the interface name, that you want to set the route traffic to go through.


ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:40:78:ec
          inet addr:10.0.0.24  Bcast:10.79.0.255  Mask:255.255.255.0
          inet6 addr: 2606:a000:4f85:ac00:a00:27ff:fe40:78ec/64 Scope:Global
          inet6 addr: fe80::a00:27ff:fe40:78ec/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:177 errors:0 dropped:30 overruns:0 frame:0
          TX packets:82 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:17929 (17.5 KiB)  TX bytes:9417 (9.1 KiB)


2.    Edit the interfaces file:

Open the /etc/network/interfaces file, and add the route statements to the end
of the interface block.

auto eth0
iface eth0 inet Static
address 10.0.0.24
netmask 255.255.0.0
gateway 10.0.0.1
up route add -net 10.2.0.0 netmask 255.255.0.0 gw 10.0.0.24


3.    Restart the Network Services:

systemctl restart networking.service


4.    Verify the route:

route -n


References:


clusterfrak.com

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

meep

Congratulations @rnason! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of posts published

Click on any badge to view your own Board of Honnor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Copying/Pasting full texts without adding anything original is frowned upon by the community.

Some tips to share content and add value:

  • Using a few sentences from your source in “quotes.” Use HTML tags or Markdown.
  • Linking to your source
  • Include your own original thoughts and ideas on what you have shared.

Repeated copy/paste posts could be considered spam. Spam is discouraged by the community, and may result in action from the cheetah bot.

Thank You! ⚜

The articles I post are from my blog cluterfrak.com, I am just adding them to steemit for the community to absorb.. They are all my own original articles. I am literally copy and pasting my own works from one venue to another to share with the steemit community.

Great article!