Go to main content

Configuring and Managing Network Components in Oracle® Solaris 11.3

Exit Print View

Updated: December 2017
 
 

Creating Persistent (Static) Routes

You use the route command to manually manipulate the network routing tables. Because the /etc/defaultrouter file is deprecated in Oracle Solaris 11.3, you can no longer manage routes (default or otherwise) by using this file. Using the route command is the only way that you can manually make routes persistent across system reboots. To make the changes persist across system reboots, use the –p option with the route command.

In this release, naming of persistent static routes is also supported. Use the –name option with the route command to add, change, delete, and display information about persistent (static) routes. This support is limited to persistent static routes only. For more complete details about this option see the route(1M) man page.

When adding routes persistently make sure that routes that you add do not already exist in the persistent configuration. If these routes already exist in the persistent configuration, the network routing tables could change without updating the persistent route. An example would be a situation where the system's default route is mapped to the system's primary interface (which is frequently the case after an Oracle Solaris installation). If you subsequently change the system's primary interface to another interface, then the system's default route should also be updated persistently. A best practice is to delete the persistent route configuration prior to adding the new route. For more information, see Troubleshooting Issues When Adding a Persistent Route in Troubleshooting Network Administration Issues in Oracle Solaris 11.3.

    Note the following additional information about creating and displaying information about persistent routes:

  • Use the route command with the –p option to add a persistent route:

    # route -p add default ip-address
  • Use the route command with the –name option to add a persistent route by specifying a name rather than destination and gateway:

    # route -p add  destination-address gateway-address -name name
  • For routes that are created by using the route command, use the route –p show command to display all of the persistent static routes:

    # route -p show
  • To display the currently active routes on a system, use the netstat command with the following options:

    # netstat -rn

For more information, see the netstat(1M) and route(1M) man pages.

How to Add a Persistent Static Route by Specifying Destination and Gateway

  1. View the current state of the routing table by using your regular user account.
    % netstat -rn

    The output would be similar to the following:

    Routing Table: IPv4
      Destination          Gateway            Flags  Ref     Use     Interface 
    -------------------- -------------------- ----- ----- ---------- ---------
    192.0.2125        192.0.2.10         U     1     5879       net0
    224.0.0.0            198.0.2.10         U     1     0          net0
    default              192.0.2.10         UG    1     91908
    127.0.0.1            127.0.0.1            UH    1     811302     lo0
    
    Routing Table: IPv6
      Destination/Mask            Gateway                   Flags Ref   Use    If
    --------------------------- --------------------------- ----- --- ------- -----
    ::1                         ::1                         UH      2       0 lo0
    
  2. Become an administrator.
  3. (Optional) Flush the existing entries in the routing table.
    # route flush
  4. Add a persistent route.
    # route -p add -net network-address -gateway gateway-address
    –p

    Creates a route that persists across system reboots. If you want the route to persist only for the current session, do not use the –p option.

    –net network-address

    Specifies that the route goes to the network with the address that is specified in network-address.

    –gateway gateway-address

    Indicates that the gateway system for the specified route has the IP address gateway-address.

Example 10  Adding a Persistent (Static) Route by Specifying a Destination

The following example shows how to add a static route to a router (Router 2). The static route is needed for the AS's border router, 203.0.113.150. See Autonomous System With Multiple IPv4 Routers for an illustration of this particular setup.

You would view the routing table on Router 2 as follows:

# netstat -rn
Routing Table: IPv4
Destination           Gateway           Flags  Ref   Use   Interface
-------------------- -------------------- ----- ----- ------ ---------
default              198.51.100.10          UG        1    249 ce0
224.0.0.0            198.51.100.10          U         1      0 ce0
203.0.113.0             203.0.113.20            U         1     78 bge0
127.0.0.1            127.0.0.1            UH        1     57 lo0

Routing Table: IPv6
  Destination/Mask            Gateway                   Flags Ref   Use    If
--------------------------- --------------------------- ----- --- ------- -----
::1                         ::1                         UH      2       0 lo0

The routing table indicates that there are two routes that Router 2 knows about. The default route uses Router 2's 198.51.100.10 interface as its gateway. The second route, 203.0.113.0, was discovered by the in.routed daemon that is running on Router 2. The gateway for this route is Router 1 and it has the IP address 203.0.113.20.

You would add a second route to network 203.0.113.0, which has its gateway as the border router, as follows:

# route -p add -net 203.0.113.0/24 -gateway 203.0.113.150
add net 203.0.113.0: gateway 203.0.113.150

The routing table now has a route for the border router, which has the IP address 203.0.113.150.

# netstat -rn
Routing Table: IPv4
Destination           Gateway           Flags  Ref   Use   Interface
-------------------- -------------------- ----- ----- ------ ---------
default              198.51.100.10          UG        1    249 ce0
224.0.0.0            198.51.100.10          U         1      0 ce0
203.0.113.0             203.0.113.20            U         1     78 bge0
203.0.113.0             203.0.113.150           U         1    375 bge0
127.0.0.1            127.0.0.1            UH        1     57 lo0

Routing Table: IPv6
  Destination/Mask            Gateway                   Flags Ref   Use    If
--------------------------- --------------------------- ----- --- ------- -----
::1                         ::1                         UH      2       0 lo0

How to Specify a Name for a Persistent Static Route

When you add a persistent static route, you can provide a name for the route by using the –name option. You can specify any name other than the name, default, as this name has a special meaning within the context of routing configuration. See the route(1M) man page for more information.

If you create a persistent route by specifying the –name option, you can display information about the route by specifying its name rather than the destination. You can also modify and delete the route by specifying its name. Note that you cannot use the –name option to name an existing route. Nor can you change the name of a route that you previously named by using this option. To assign a name to an existing route or to modify the name of an existing route that you previously named, first delete that route and then add the route again by specifying the –name option.

  1. Become an administrator.
  2. Add a persistent route by specifying a name.
    # route -p add  destination-address gateway-address -name name

    where –name is the name that you refer to the persistent route by instead of its destination and gateway. The –name option is ignored for non-persistent routes.

  3. Display information about the route.
    # route get -name route-name

    You can also display information about the route as follows:

    # route -p show
Example 11  Adding a Persistent (Static) Route by Specifying a Name

The following example shows how you would add a persistent static route (route1) by specifying a name.

# route -p add 9.9.9.9 3.3.3.9 -name route1
persistent: route add 9.9.9.9 3.3.3.9 -name route1
# route get -name route1
    route to : 9.9.9.9
        name : route1
 destination : 9.9.9.9
        mask : 255.255.255.25     
     gateway : 3.3.3.9
   interface : net0
       flags : <UP,GATEWAY,HOST,DONE,STATIC>
recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu expire
0 0 0 0 0 0 1500 0
Example 12  Changing Information for a Persistent (Static) Route by Specifying the Route's Name

The following example shows how to modify information for a persistent route by specifying its name. In this example, the gateway information is changed. Note that the persistent route must have been added by specifying a name initially.

# route -p show
persistent: route add 9.9.9.9 3.3.3.9 -name route1
# route change -name route1 9.9.8.8
change host -name route1 9.9.9.9: gateway 9.9.8.8
Example 13  Deleting a Persistent (Static) Route by Specifying the Route's Name

The following example shows how you would delete a persistent route by specifying its name. Note that the persistent route must have been added by specifying a name initially.

# route -p delete -name route1     
delete host -name route1 9.9.9.9: gateway 3.3.3.9: not in table
delete persistent host -name route1 9.9.9.9: gateway 3.3.3.9

If you do not speicfy the –p option with the –name option, the route is removed from the routing tables only, as shown in the following example:

# route delete -name route1
delete host -name route1 9.9.9.9: gateway 3.3.3.9