Creating Persistent (Static) Routes
You use the route command to manually manipulate the network routing tables. To make the changes persistent across reboots, use the –p option. Because the /etc/defaultrouter file is deprecated in Oracle Solaris 11, 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.
Note - The route command manipulates routes for the active profile only. The default route, as well as all other routes, potentially might be replaced if the active profile changes. However, this is not a concern if you always use the same profile on your system.
When adding routes persistently care should be taken to 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.2 .
-
Use the route command with the –p option to persistently add a route:
# route -p add default ip-address
For routes that are created by using this method, use the route –p show command to display all of the persistent static routes:
# route -p show
-
Display the currently active routes on a system by using the netstat command with the following options:
# netstat -rn
See the netstat (1M) and route (1M) man pages.
Note the following additional information about creating and displaying persistent routes:
For more information, see the netstat (1M) and route (1M) man pages.
For information about creating and displaying default routes when using the reactive mode, see Chapter 5, About Administering Profile-Based Network Configuration in Oracle Solaris.
How to Add a Static Route to the Routing Table
-
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.168.5.125 192.168.5.10 U 1 5879 net0 224.0.0.0 198.168.5.10 U 1 0 net0 default 192.168.5.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
- Become an administrator.
- (Optional)
Flush the existing entries in the routing table.
# route flush
-
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.
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, 10.0.5.150. See Figure 3–1 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 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 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 172.20.1.10 interface as its gateway. The second route, 10.0.5.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 10.0.5.20.
You would add a second route to network 10.0.5.0, which has its gateway as the border router, as follows:
# route -p add -net 10.0.5.0/24 -gateway 10.0.5.150 add net 10.0.5.0: gateway 10.0.5.150
The routing table now has a route for the border router, which has the IP address 10.0.5.150.
# 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 Routing Table: IPv6 Destination/Mask Gateway Flags Ref Use If --------------------------- --------------------------- ----- --- ------- ----- ::1 ::1 UH 2 0 lo0