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
    
    e.g
    default via 192.168.1.1
    10.10.10.0/24 via 192.168.1.2
    
  • 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:
    ADDRESS<N>=X.X.X.X
    NETMASK<N>=Y.Y.Y.Y
    GATEWAY<N>=Z.Z.Z.Z
    
    e.g.
    ADDRESS0=10.10.10.0
    NETMASK0=255.255.255.0
    GATEWAY0=192.168.1.2
    ADDRESS1=20.20.20.0
    NETMASK1=255.255.255.0
    GATEWAY1=192.168.1.2
    
  • 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).

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.