System Administration Guide: IP Services

Configuring Routes

To implement dynamic routing for an IPv4 network, use the routeadm or svcadm command to start the in.routed routing daemon. For instructions, see How to Configure an IPv4 Router. Dynamic routing is the preferred strategy for most networks and autonomous systems. However, your network topology or a particular system on your network might require static routing. In that case, you must manually edit the system routing table to reflect the known route to the gateway. The next procedure shows how to add a static route.


Note –

Two routes to the same destination does not automatically cause the system to do load balancing or failover. If you need these capabilities, use IPMP, as explained in Chapter 30, Introducing IPMP (Overview).


ProcedureHow to Add a Static Route to the Routing Table

  1. View the current state of the routing table.

    Use your regular user account to run the following form of the netstat command:


    % netstat -rn
    

    Your output would resemble the following:


    Routing Table: IPv4
      Destination           Gateway           Flags  Ref   Use   Interface
    -------------------- -------------------- ----- ----- ------ ---------
    192.168.5.125        192.168.5.10          U      1   5879   ipge0
    224.0.0.0            198.168.5.10          U      1  0       ipge0
    default              192.168.5.10          UG     1  91908
    127.0.0.1            127.0.0.1             UH     1  811302   lo0
  2. Assume the Primary Administrator role or become superuser.

    The Primary Administrator role includes the Primary Administrator profile. To create the role and assign the role to a user, see Chapter 2, Working With the Solaris Management Console (Tasks), in System Administration Guide: Basic Administration.

  3. (Optional) Flush the existing entries in the routing table.


    # route flush
    
  4. Add a route that persists across system reboots.


    # route -p add -net network-address -gateway gateway-address
    
    -p

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

    add

    Indicates that you are about to add the following route.

    -net network-address

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

    -gateway gateway-address

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


Example 5–5 Adding a Static Route to the Routing Table

The following example shows how to add a static route to a system. The system is Router 2, the default router for the 172.20.1.0 network that is shown in Figure 5–3. In Example 5–4, Router 2 is configured for dynamic routing. To better serve as the default router for the hosts on network 172.20.1.0, Router 2 additionally needs a static route to the AS's border router, 10.0.5.150.

To view the routing table on Router 2, you would do the following:


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

The routing table indicates two routes that Router 2 knows about. The default route uses Router 2's 172.20.1.10 interface as its gateway. The second route, 10.0.5.0, was discovered by the in.routed daemon running on Router 2. The gateway for this route is Router 1, with the IP address 10.0.5.20.

To add a second route to network 10.0.5.0, which has its gateway as the border router, you would do the following:


# route -p add -net 10.0.5.0/24 -gateway 10.0.5.150/24
add net 10.0.5.0: gateway 10.0.5.150

Now the routing table has a route for the border router, which has the IP address 10.0.5.150/24.


# netstat -rn
Routing Table: IPv4
  Destination           Gateway           Flags  Ref   Use   Interface
-------------------- -------------------- ----- ----- ------ ---------
default              172.20.1.10          UG        1    249 ce0
224.0.0.0            172.20.1.10          U         1      0 ce0
10.0.5.0             10.0.5.20            U         1     78 bge0
10.0.5.0             10.0.5.150           U         1    375 bge0
127.0.0.1            127.0.0.1            UH        1     57 lo0