Thursday, March 20, 2014

How to Add / Change / Delete route in solaris10 on different methods

This article will explain about to add type of routes in Solaris10 .

Static and Dynamic routes:

The static routes are added by using the route command either by a script or by using command line. Dynamic routes are added by default routing daemons.These are the deamons /usr/sbin/in.routed (Routing Information Protocol(RIP) and /usr/sbin/in.rdisc (Router Network Discovery Protocol) which are responsible for adding dynamic routes that are inbuilt with Solaris OS it self. 

Pre-request tasks:
1). Take backup of current configuration file as well as screenshot
2). Check whether your able to ping and trace route IP which your going to add or change
3). Take console access before changing default router, it may cause to not allow ssh some time

The various flags in routes :

U – The route is up.
G – The route uses a gateway.
H – The target is a host route.
D – The route was added dynamically by ICMP redirect.
M - The flag signifies that this route is modified by a redirect.

My Server Current Setup:
bash-3.2# netstat -rn
Routing Table: IPv4
Destination        Gateway           Flags  Ref     Use     Interface
-------------------- -------------------- ----- -- ---------- ---------
192.168.10.0      192.168.10.21        U         1         25 e1000g0
224.0.0.0         192.168.10.21        U         1          0 e1000g0
127.0.0.1         127.0.0.1            UH        6         67 lo0
bash-3.2# cat /etc/inet/static_routes
# File generated by route(1M) - do not edit.
bash-3.2#
Here I am adding, changing and deleting route aka default gateway in two method.
1). Generally adding, changing and deleting default route without specifying interface
2). Adding , changing and deleting default route with specifying interface

To add default router persistently : (if your using route command with -p option then not require to put entry to /etc/defaultrouter file, instead it will add entry 
automatically to /etc/inet/static_routes file which will take care across reboot. 
bash-3.2# route -p add default 192.168.10.1
add net default: gateway 192.168.10.1
add persistent net default: gateway 192.168.10.1
bash-3.2# cat /etc/inet/static_routes
# File generated by route(1M) - do not edit.
default 192.168.10.1
bash-3.2# netstat -rn
Routing Table: IPv4
Destination           Gateway         Flags  Ref     Use     Interface
-------------------- ----------------- ----- ----- ---------- ---------
default              192.168.10.1         UG        1          0
192.168.10.0         192.168.10.21        U         1         57 e1000g0
224.0.0.0            192.168.10.21        U         1          0 e1000g0
127.0.0.1            127.0.0.1            UH        4        133 lo0
bash-3.2#
Note - We can't change persistent route using -p , we have to delete it and add it.
bash-3.2# route -p change default 192.168.10.10
change net default: gateway 192.168.10.10
route: change command not supported with -p
bash-3.2#
To delete persistent default route:
bash-3.2# route -p delete default 192.168.10.1
delete net default: gateway 192.168.10.1
delete persistent net default: gateway 192.168.10.1
bash-3.2# netstat -rn
Routing Table: IPv4
Destination         Gateway           Flags  Ref     Use     Interface
----------------- -------------------- ----- ----- ---------- ---------
192.168.10.0         192.168.10.21        U         1         25 e1000g0
224.0.0.0            192.168.10.21        U         1          0 e1000g0
127.0.0.1            127.0.0.1            UH        4        131 lo0
bash-3.2# cat /etc/inet/static_routes
# File generated by route(1M) - do not edit.
bash-3.2#
To add "default" router without and with specifying interface:
bash-3.2# route add default 192.168.10.10
add net default: gateway 192.168.10.10
bash-3.2# route add default 192.168.10.1 -ifp e1000g0
add net default: gateway 192.168.10.1
bash-3.2# netstat -rn
Routing Table: IPv4
  Destination           Gateway        Flags  Ref     Use     Interface
-------------------- ----------------- ----- ----- ---------- ---------
default              192.168.10.10        UG        1          0
default              192.168.10.1         UG        1          0 e1000g0
192.168.10.0         192.168.10.21        U         1         32 e1000g0
224.0.0.0            192.168.10.21        U         1          0 e1000g0
127.0.0.1            127.0.0.1            UH        4        133 lo0
bash-3.2#
To change "default" router without and with specifying interface:
bash-3.2# route change default 192.168.10.5
change net default: gateway 192.168.10.5
bash-3.2# route change default 192.168.10.21 -ifp e1000g0
change net default: gateway 192.168.10.21
bash-3.2# netstat -rn
Routing Table: IPv4
  Destination           Gateway       Flags  Ref     Use     Interface
-------------------- ----------------- ----- ----- ---------- ---------
default              192.168.10.5         UG        1          0
default              192.168.10.21        UG        1          0 e1000g0
192.168.10.0         192.168.10.21        U         1         32 e1000g0
224.0.0.0            192.168.10.21        U         1          0 e1000g0
127.0.0.1            127.0.0.1            UH        4        133 lo0
bash-3.2# 
To delete"default" router without and with specifying interface:
bash-3.2# route delete default 192.168.10.5
delete net default: gateway 192.168.10.5
bash-3.2# route delete default 192.168.10.21 -ifp e1000g0
delete net default: gateway 192.168.10.21
bash-3.2# netstat -rn
Routing Table: IPv4
  Destination           Gateway        Flags  Ref     Use     Interface
-------------------- ----------------- ----- ----- ---------- ---------
192.168.10.0         192.168.10.21        U         1         32 e1000g0
224.0.0.0            192.168.10.21        U         1          0 e1000g0
127.0.0.1            127.0.0.1            UH        4        133 lo0
bash-3.2#
To make this changes effect across reboot we have put entry to /etc/defaultrouter file.Usually and by Default /etc/defaultrouter file will not be there , we have to create it manually. 

To set static routes: Use route command to add static route on fly (dynamic modification of routing table). We have two option to add static routes, persistent and non-persistent. To add static routes persistent: we have to use -p option with route command or we can create rc script and put the entry to the script which will add it across reboot. 

Adding route using -p option(/etc/inet/static_routes):
bash-3.2#route -p add net 192.168.10.0/24 gateway 192.168.10.10
add persistent net 192.168.10.0/24: gateway 192.168.10.10
bash-3.2# route -p add 192.168.10.0 -netmask 255.255.255.0 192.168.10.1
add net 192.168.10.0: gateway 192.168.10.1
add persistent net 192.168.10.0: gateway 192.168.10.1
bash-3.2# netstat -rnv
IRE Table: IPv4
  Destination             Mask           Gateway          Device Mxfrg Rtt   Ref Flg  Out  In/Fwd
-------------------- --------------- -------------------- ------ ----- ----- --- --- ----- ------
192.168.10.0         255.255.255.0   192.168.10.21      e1000g0  1500*    0   1 U       51      0
192.168.10.0         255.255.255.0   192.168.10.10              1500*    0   1 UG       0      0
192.168.10.0         255.255.255.0   192.168.10.1               1500*    0   1 UG       0      0
224.0.0.0            240.0.0.0       192.168.10.21      e1000g0  1500*    0   1 U        0      0
127.0.0.1            255.255.255.255 127.0.0.1          lo0     8232*    0   4 UH     133      0
bash-3.2# cat /etc/inet/static_routes
# File generated by route(1M) - do not edit.
192.168.10.0/24 192.168.10.10
192.168.10.0 -netmask 255.255.255.0 192.168.10.1
bash-3.2#
To add non-persistent route which will flushed if you reboot:
bash-3.2# route add 192.168.10.0 -netmask 255.255.255.0 192.168.10.1
add net 192.168.10.0: gateway 192.168.10.1
bash-3.2# route add 192.168.10.0/24 192.168.10.10
add net 192.168.10.0/24: gateway 192.168.10.10
bash-3.2# netstat -rnv
IRE Table: IPv4
  Destination             Mask           Gateway          Device Mxfrg Rtt   Ref Flg  Out  In/Fwd
-------------------- --------------- -------------------- ------ ----- ----- --- --- ----- ------
192.168.10.0         255.255.255.0   192.168.10.21      e1000g0  1500*    0   1 U       49      0
192.168.10.0         255.255.255.0   192.168.10.1               1500*    0   1 UG       0      0
192.168.10.0         255.255.255.0   192.168.10.10              1500*    0   1 UG       0      0
224.0.0.0            240.0.0.0       192.168.10.21      e1000g0  1500*    0   1 U        0      0
127.0.0.1            255.255.255.255 127.0.0.1          lo0     8232*    0   4 UH     133      0
bash-3.2#
To get information about a specific route :
bash-3.2# route -p get 192.168.10.10
   route to: 192.168.10.10
destination: 192.168.10.0
       mask: 255.255.255.0
  interface: e1000g0
      flags: 
recvpipe  sendpipe  ssthresh  rtt,ms rttvar,ms  hopcount   mtu     expire
       0      0      0      0      0         0      1500         0
get persistent host 192.168.10.10: not in file
bash-3.2# 
To see the persistent routes added in the system :
bash-3.2# route -p show
persistent: route add default 192.168.10.1
bash-3.2#
To use rc script to add route: 
The -p option will not work earlier solaris verion as well as some earlier patch level of solaris 10. To avoid this we have a another optin to create a rc script under /etc/rc2.d/. 

Add the route add command in this script :
i.e /etc/rc2.d/S90route
bash-3.2# cat /etc/rc2.d/S90route
/usr/sbin/route add 192.168.10.0 -netmask 255.255.255.0 192.168.10.1
bash-3.2#
To flush (remove) the routing table of all gateway entries, use the route flush command:
bash-3.2# route flush
default              192.168.10.10        done
bash-3.2#
To add a route manually to the multicast address for range of 192-254:
bash-3.2# route add 224.0/24 `uname -n`
add net 224.0/24: gateway techpanel
bash-3.2# netstat -rn
Routing Table: IPv4
Destination           Gateway           Flags  Ref     Use     Interface
----------------- -------------------- ----- ----- ---------- ---------
192.168.10.0         192.168.10.21        U         1         26 e1000g0
224.0.0.0            192.168.10.21        UG        1          0
224.0.0.0            192.168.10.21        UG        1          0
127.0.0.1            127.0.0.1            UH        4        131 lo0
bash-3.2#
You can refer multicast address range here as well as in this link Netmask:

Net ClassAddr RangeNetMaskNet Addr BitsHost Addr BitsTotal Number of hostsExample Range
A0-127255.0.0.082416777216(i.e. 114.0.0.0)
B128-191255.255.0.0161665536(i.e. 150.0.0.0)
C192-254255.255.255.0248256(i.e. 199.0.0.0)
D224-239(multicast)
E240-255(reserved)
F208-215255.255.255.24028416
G216/8ARIN North America
G217/8RIPE NCC Europe
G218-219/8APNIC
H220-221255.255.255.2482938(reserved)
K222-223255.255.255.2543112(reserved)
We can also use /etc/gateways file to add static routes. The /etc/gateways file is used by the routing daemon in.routed when the daemon starts,it reads /etc/gateways to find such distant gateways. The /etc/gateways file consists of a series of lines. i.e Blank lines and lines starting with "#" are treated as comments. Generally /etc/gateways files not there, we need to create it manually.
bash-3.2# cat /etc/gateways
net 192.168.10.0 gateway 192.168.10.1
bash-3.2#
Thanks for reading this article...

1 comment: