Example: Configuring a Basic Set of Static Routes for Connecting to Stub Networks
This example shows how to configure a basic set of static routes.
In this example, no special configuration beyond device initialization is required.
There are many practical applications for static routes. Static routing is often used at the network edge to support attachment to stub networks, which, given their single point of entry and egress, are well suited to the simplicity of a static route. In Junos OS, static routes have a global preference of 5. Static routes are activated if the specified next hop is reachable.
In this example, you configure the static route 192.168.47.0/24 from the provider network to the customer network, using the next-hop address of 172.16.1.2. You also configure a static default route of 0.0.0.0/0 from the customer network to the provider network, using a next-hop address of 172.16.1.1.
For demonstration purposes, some loopback interfaces are configured on Device B and Device D. These loopback interfaces provide addresses to ping and thus verify that the static routes are working.
Figure 1 shows the sample network.
CLI Quick Configuration
To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the  hierarchy level.
The following example requires you to navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode in the CLI User Guide.
To configure basic static routes:
- On Device B, configure the interfaces.[edit interfaces]user@B# set ge-1/2/0 unit 0 description B->Duser@B# set ge-1/2/0 unit 0 family inet address 172.16.1.1/24user@B# set lo0 unit 57 family inet address 10.0.0.1/32user@B# set lo0 unit 57 family inet address 10.0.0.2/32
- On Device B, create a static route and set the next-hop
address.[edit routing-options]user@B# set static route 192.168.47.0/24 next-hop 172.16.1.2
- If you are done configuring Device B, commit the configuration.[edit interfaces]user@B# commit
- On Device D, configure the interfaces.[edit interfaces]user@D# set ge-1/2/0 unit 1 description D->Buser@D# set ge-1/2/0 unit 1 family inet address 172.16.1.2/24user@D# set lo0 unit 2 family inet address 192.168.47.5/32user@D# set lo0 unit 2 family inet address 192.168.47.6/32
- On Device D, create a static route and set the next-hop
address.[edit routing-options]user@D# set static route 0.0.0.0/0 next-hop 172.16.1.1
- If you are done configuring Device D, commit the configuration.user@D# commit
Confirm your configuration by issuing the show interfaces and show routing-options commands. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.
Confirm that the configuration is working properly.
Checking the Routing Tables
Make sure that the static routes appear in the routing tables of Device B and Device D.
user@B> show route
inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 10.0.0.1/32 *[Direct/0] 00:29:43 > via lo0.57 10.0.0.2/32 *[Direct/0] 00:29:43 > via lo0.57 172.16.1.0/24 *[Direct/0] 00:34:40 > via ge-1/2/0.0 172.16.1.1/32 *[Local/0] 00:34:40 Local via ge-1/2/0.0 192.168.47.0/24 *[Static/5] 00:31:23 > to 172.16.1.2 via ge-1/2/0.0
user@D> show route
inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both 0.0.0.0/0 *[Static/5] 00:31:24 > to 172.16.1.1 via ge-1/2/0.1 172.16.1.0/24 *[Direct/0] 00:35:21 > via ge-1/2/0.1 172.16.1.2/32 *[Local/0] 00:35:21 Local via ge-1/2/0.1 192.168.47.5/32 *[Direct/0] 00:35:22 > via lo0.2 192.168.47.6/32 *[Direct/0] 00:35:21 > via lo0.2
The static routes are in the routing tables.
Pinging the Remote Addresses
Verify that the static routes are working.
From Device B, ping one of the loopback interface addresses on Device D.
From Device D, ping one of the loopback interface addresses on Device B.
user@B> ping 192.168.47.5
PING 192.168.47.5 (192.168.47.5): 56 data bytes 64 bytes from 192.168.47.5: icmp_seq=0 ttl=64 time=156.126 ms 64 bytes from 192.168.47.5: icmp_seq=1 ttl=64 time=120.393 ms 64 bytes from 192.168.47.5: icmp_seq=2 ttl=64 time=175.361 ms
user@D> ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1): 56 data bytes 64 bytes from 10.0.0.1: icmp_seq=0 ttl=64 time=1.315 ms 64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=31.819 ms 64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=1.268 ms