×
Create a new article
Write your page title here:
We currently have 3,187 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,187Articles
    (Redirected from Static Routes (Solaris 10))

    Solaris[edit]

    Solaris 10 Update 3 and Later[edit]

    From Solaris 10 Update 3 these is in built support for storing static routes. To add a route persistently add a '-p' switch when specifying the route, this will make the route active and persistent across reboots.

    'route -p add -net 192.168.24.0/24 10.10.10.1'

    This will be saved in /etc/inet/static_routes eg:

    # File generated by route(1M) - do not edit.
    -net 192.168.128.0/22 192.168.136.1
    -net 192.168.138.0/24 192.168.136.1
    -net 172.31.68.0/24 192.168.149.253
    -net 172.31.69.0/24 192.168.149.253
    

    To delete a route and remove it from static_routes do:

    'route -p delete -net ....'

    Solaris 10 Update 2 and Earlier[edit]

    Solaris 10u2 and earlier don't have support for static routes.

    Using the old S99static trick doesn't work as the rc2 scripts won't run if the system doesn't reach milestone/multiuser which can happen if a service (such as rpcbind) fails to start.

    As such a new SMF service is required.

    Put this in /var/svc/manifest/network/RKstatic-routes.xml:-

    <?xml version="1.0"?>
    <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
    <!--
            Static Route SMF Manefest
    
            To be replaced by official Sun mechanism in next solaris release
    
    -->
    <service_bundle type='manifest' name='RKstatic-routes'>
    
    <service
      name='network/RKstatic-routes'
      type='service'
    
      version='1'>
        <create_default_instance enabled='true' />
    
        <single_instance/>
        <dependency name='network'
            grouping='require_any'
            restart_on='error'
            type='service'>
                <service_fmri value='svc:/network/service' />
        </dependency>
    
    
      <exec_method
        type='method'
        name='start'
    
        exec='/lib/svc/method/RKstatic-routes start'
    
        timeout_seconds='60' />
    
      <exec_method
    
        type='method'
        name='stop'
        exec='/lib/svc/method/RKstatic-routes stop'
    
        timeout_seconds='60' />
    
      <property_group name='startd' type='framework'>
    
        <propval name='duration' type='astring' value='transient' />
    
      </property_group>
    
      <stability value='Unstable' />
    
    </service>
    </service_bundle>
    

    Then create the following (with modifications obv) at /lib/svc/method/RKstatic-routes:-

    #!/bin/sh
    
    # RKstatic-routes
    
    # To be called by the network/RKstatic-route SMF service
    
    ACTION=${ACTION:-add}
    
    setup_routes () {
    
    
    #Route to networks.
    /usr/sbin/route $ACTION net 172.1.0.0 -netmask 255.255.0.0 10.1.0.0
    /usr/sbin/route $ACTION net 172.2.0.0 -netmask 255.255.0.0 10.2.0.0
    
    }
    
    case "$1" in
        start)
            echo "${ACTION}ing static routes"
            setup_routes
            ;;
        stop)
            ACTION=delete
            echo "${ACTION}ing static routes"
            setup_routes
            ;;
        *)
            echo "Usage: $0 {start|stop}"
            exit 1
    esac
    

    Then import the service:-

    svccfg -v import /var/svc/manifest/network/RKstatic-routes.xml
    

    Then you can enable and start the service with:-

    svcadm enable network/RKstatic-routes
    

    And remove the routes and disable the service with:-

    svcadm disable network/RKstatic-routes
    

    Enabling or disabling the routes with this method will persist across reboots.

    Solaris 9 and earlier[edit]

    Adding static routes required some fiddling:


    In general people just made a rc script to add the routes:

    RC script to add routes[edit]

    this typical script is not quite right but it works verry well... ($type $route and $gateway and only two values in the routes.conf)

    ln -s /etc/rc2.d/S70staticRoutes /etc/init.d/staticRoutes.sh
    
    cat staticRoutes.sh
    #!/bin/sh
    
    case "$1" in
     
            start)
                    test -f /etc/routes.conf || exit 0
                    while read type route gateway
                    do
                            /usr/sbin/route add $type $route $gateway
                    done < /etc/routes.conf
                    ;;
    
            stop)
                    test -f /etc/routes.conf || exit 0
                    while read type route gateway
                    do
                            /usr/sbin/route delete $type $route $gateway
                    done < /etc/routes.conf
                    ;;
    
            *)
                    echo "Usage: /etc/init.d/routes { start | stop }"
                    ;;
    
    esac
    

    routes.conf[edit]

    #cat /etc/routes.conf
    172.1.2.0/24 172.1.2.4
    172.1.3.0/24 172.1.3.4
    



    But to be clean on Solaris 8, 9 and 10 you can add your static routes at /etc/gateways like this:

    net 100.100.100.0 gateway 192.1.243.1 metric 1
    

    Redhat[edit]

    RHEL 4[edit]

    To add a persistent static route, create the following file for each ethX device.

    /etc/sysconfig/network-scripts/route-ethX

    Every entry or a route has three lines as follows:

    GATEWAY<N>=xxx.xxx.xxx.xxx
    NETMASK<N>=yyy.yyy.yyy.yyy
    ADDRESS<N>=zzz.zzz.zzz.zzz
    

    As the names implies, they are the gateway IP, Netmask and the IP/Network Address.

    Note the <N> next to each of the three entities. This number defines the route entry number and should be the same on all the entities.

    Example:

    GATEWAY0=192.168.1.1
    NETMASK0=255.255.255.0
    ADDRESS0=10.10.10.0
    
    GATEWAY1=192.168.1.1
    NETMASK1=255.255.255.0
    ADDRESS1=20.20.20.2
    

    Restart the network.

    To dynamically add a route execute the following command:

    # ip route add <Net/IP>/Netmask> via <Gateway IP> dev <InterfaceX>
    

    Example:

    # ip route add 10.10.10.0/24 via 192.168.1.1 dev eth0
    

    Confirm with following command:

    # ip route show
    
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.