How to add a Static route in Linux?

Its very easy to add a static route in windows, its straight forward and will not disturb you more. But in linux the syntax is little different .

Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]

       inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]

                              [netmask N] [mss Mss] [window W] [irtt I]

                              [mod] [dyn] [reinstate] [[dev] If]

       inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject

       inet_route [-FC] flush      NOT supported

Dont be confused by the above syntax , It is simple as below mentioned 

route add -net 192.168.1.0 gw 172.16.2.254 netmask 25.255.255.0

where 192.168.1.0 is the destination network

and 172.16.2.254 is the gateway to reach 192.168.1.0 network

if tou want to show the route just type route in the terminal, it will give the below listed output

[root@st1 /]# route

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     172.16.2.254    255.255.255.0   UG    0      0        0 eth0

172.16.2.0      *               255.255.255.0   U     0      0        0 eth0

169.254.0.0     *               255.255.0.0     U     0      0        0 eth0



Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>