DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.

How to add a new network gateway or static route on Red Hat Enterprise Linux host?

To add a static route or gateway on Red Hat Enterprise Linux host, such as when adding for a second (or tertiary) interface, use the /etc/sysconfig/network-scripts/route-<interface> files. These configuration filesare read during network service initialization. For example to add static route for eth0, create a file /etc/sysconfig/network-scripts/route-eth0 and add the routes as explained below.

There are two possible formats for this file. The first is with ip command arguments and the second is with network/netmask directives.

Format 1:
  • For ip commands, the ifup-route script supplies ip route add and the contents of the file are all parameters necessary to set up the route. For example, to set up a default route, the file would contain the following:
    default via X.X.X.X
    Y.Y.Y.Y via Z.Z.Z.Z
    default via via
  • In the above, X.X.X.X is the gateway IP address. The second line adds another static route where Y.Y.Y.Y is the network, Z.Z.Z.Z is the gateway IP address. Multiple lines will be parsed as individual routes.

Format 2:
  • The alternative format is as follows:
  • This format deals with three fields: GATEWAY, NETMASK, and ADDRESS. Each field should have a number appended to it indicating which route it relates to.
  • In the above example, Z.Z.Z.Z is the gateway IP address. Subsequent entries must be numbered sequentially (for example ADDRESS1=, NETMASK1=, GATEWAY1=). Note, that multiple entries must be sequentially numbered and must not skip a value (0 must be followed by 1, not a number greater than 1).

Do you like this story?

No comments:

Post a Comment