Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

Examples: Configuring Static Routes

Understanding Basic Static Routing

Routes that are permanent fixtures in the routing and forwarding tables are often configured as static routes. These routes generally do not change, and often include only one or very few paths to the destination.

To create a static route in the routing table, you must, at minimum, define the route as static and associate a next-hop address with it. The static route in the routing table is inserted into the forwarding table when the next-hop address is reachable. All traffic destined for the static route is transmitted to the next-hop address for transit.

You can specify options that define additional information about static routes that is included with the route when it is installed in the routing table. All static options are optional.

Example: Configuring a Basic Set of Static Routes

This example shows how to configure a basic set of static routes.

Requirements

In this example, no special configuration beyond device initialization is required.

Overview

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.

Figure 1: Customer Routes Connected to a Service Provider

Customer Routes
Connected to a Service Provider

Configuration

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 [edit] hierarchy level.

Device B

set interfaces ge-1/2/0 unit 0 description B->Dset interfaces ge-1/2/0 unit 0 family inet address 172.16.1.1/24set interfaces lo0 unit 57 family inet address 10.0.0.1/32set interfaces lo0 unit 57 family inet address 10.0.0.2/32set routing-options static route 192.168.47.0/24 next-hop 172.16.1.2

Device D

set interfaces ge-1/2/0 unit 1 description D->Bset interfaces ge-1/2/0 unit 1 family inet address 172.16.1.2/24set interfaces lo0 unit 2 family inet address 192.168.47.5/32set interfaces lo0 unit 2 family inet address 192.168.47.6/32set routing-options static route 0.0.0.0/0 next-hop 172.16.1.1

Step-by-Step Procedure

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:

  1. 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
  2. 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
  3. If you are done configuring Device B, commit the configuration.
    [edit interfaces]user@B# commit
  4. On Device D, configure the interfaces.
    [edit]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
  5. 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
  6. If you are done configuring Device D, commit the configuration.
    [edit]user@D# commit

Results

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.

Device B

user@B# show interfaces
ge-1/2/0 {unit 0 {description B->D;family inet {address 172.16.1.1/24;}}}
lo0 {unit 57 {family inet {address 10.0.0.1/32;address 10.0.0.2/32;}}}
user@B# show routing-options
static {route 192.168.47.0/24 next-hop 172.16.1.2;}

Device D

user@D# show interfaces
ge-1/2/0 {unit 1 {description D->B;family inet {address 172.16.1.2/24;}}}
lo0 {unit 2 {family inet {address 192.168.47.5/32;address 192.168.47.6/32;}}}
user@D# show routing-options
static {route 0.0.0.0/0 next-hop 172.16.1.1;}

Verification

Confirm that the configuration is working properly.

Checking the Routing Tables

Purpose

Make sure that the static routes appear in the routing tables of Device B and Device D.

Action

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

Meaning

The static routes are in the routing tables.

Pinging the Remote Addresses

Purpose

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.

Action

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

Example: Configuring IPv6 Static Routes

This example shows how to configure static routes when the interfaces have IPv6 addresses.

Requirements

In this example, no special configuration beyond device initialization is required.

Overview

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 a static default route of ::/0, using a next-hop address 2001:db8:0:1:2a0:a502:0:1da.

For demonstration purposes, some loopback interfaces are configured on Device A and Device E. These loopback interfaces provide addresses to ping and thus verify that the static routes are working.

Figure 2 shows the sample network.

Figure 2: Customer Routes Connected to a Service Provider

Customer Routes
Connected to a Service Provider

Configuration

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 [edit] hierarchy level.

Device A

set interfaces fe-1/2/0 unit 1 description to-Eset interfaces fe-1/2/0 unit 1 family inet6 address 2001:db8:0:1:2a0:a502:0:1da/64set interfaces lo0 unit 1 family inet6 address 2001:db8::1/128 primaryset interfaces lo0 unit 1 family inet6 address 2001:db8::2/128set interfaces lo0 unit 1 family inet6 address 2001:db8::3/128set routing-options rib inet6.0 static route 2001:db8::5/128 next-hop 2001:db8:0:1:2a0:a502:0:19da

Device E

set interfaces fe-1/2/0 unit 25 description to-Aset interfaces fe-1/2/0 unit 25 family inet6 address 2001:db8:0:1:2a0:a502:0:19da/64set interfaces lo0 unit 5 family inet6 address 2001:db8::5/128set routing-options rib inet6.0 static route ::/0 next-hop 2001:db8:0:1:2a0:a502:0:1da

Step-by-Step Procedure

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:

  1. On Device A, configure the interfaces.
    [edit interfaces]set interfaces fe-1/2/0 unit 1 description to-Eset interfaces fe-1/2/0 unit 1 family inet6 address 2001:db8:0:1:2a0:a502:0:1da/64
    set interfaces lo0 unit 1 family inet6 address 2001:db8::1/128 primaryset interfaces lo0 unit 1 family inet6 address 2001:db8::2/128set interfaces lo0 unit 1 family inet6 address 2001:db8::3/128
  2. On Device A, create a static route to Device E’s loopback address and set the next-hop address.

    This ensures that Device A has a route back to Device E.

    [edit routing-options]set rib inet6.0 static route 2001:db8::5/128 next-hop 2001:db8:0:1:2a0:a502:0:19da
  3. If you are done configuring Device A, commit the configuration.
    [edit interfaces]user@A# commit
  4. On Device E, configure the interfaces.
    [edit]set interfaces fe-1/2/0 unit 25 description to-Aset interfaces fe-1/2/0 unit 25 family inet6 address 2001:db8:0:1:2a0:a502:0:19da/64set interfaces lo0 unit 5 family inet6 address 2001:db8::5/128
  5. On Device E, create a static default route and set the next-hop address.
    [edit routing-options]set routing-options rib inet6.0 static route ::/0 next-hop 2001:db8:0:1:2a0:a502:0:1da
  6. If you are done configuring Device E, commit the configuration.
    [edit]user@E# commit

Results

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.

Device A

user@A# show interfaces
fe-1/2/0 {unit 1 {description to-E;family inet6 {address 2001:db8:0:1:2a0:a502:0:1da/64;}}}
lo0 {unit 1 {family inet6 {address 2001:db8::1/128 {primary;}address 2001:db8::2/128;address 2001:db8::3/128;}}}
user@A# show routing-options
rib inet6.0 {static {route 2001:db8::5/128 next-hop 2001:db8:0:1:2a0:a502:0:19da;}}

Device E

user@E# show interfaces
fe-1/2/0 {unit 25 {description to-A;family inet6 {address 2001:db8:0:1:2a0:a502:0:19da/64;}}}
lo0 {unit 5 {family inet6 {address 2001:db8::5/128;}}}
user@E# show routing-options
rib inet6.0 {static {route ::/0 next-hop 2001:db8:0:1:2a0:a502:0:1da;}}

Verification

Confirm that the configuration is working properly.

Checking the Routing Tables

Purpose

Make sure that the static routes appear in the routing tables of Device A and Device E.

Action

user@A> show route protocol static
inet6.0: 9 destinations, 9 routes (9 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

2001:db8::5/128    *[Static/5] 00:27:46
                    > to 2001:db8:0:1:2a0:a502:0:19da via fe-1/2/0.1
user@E> show route protocol static
inet6.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

::/0               *[Static/5] 00:19:11
                    > to 2001:db8:0:1:2a0:a502:0:1da via fe-1/2/0.25

Meaning

The static routes are in the routing tables.

Pinging the Remote Addresses

Purpose

Verify that the static routes are working.

From Device A, ping one of the loopback interface addresses on Device E.

From Device E, ping one of the loopback interface addresses on Device A.

Action

user@A> ping 2001:db8::5
PING6(56=40+8+8 bytes) 2001:db8:0:1:2a0:a502:0:1da --> 2001:db8::5
16 bytes from 2001:db8::5, icmp_seq=0 hlim=64 time=1.790 ms
16 bytes from 2001:db8::5, icmp_seq=1 hlim=64 time=1.529 ms
16 bytes from 2001:db8::5, icmp_seq=2 hlim=64 time=1.531 ms
user@E> ping 2001:db8::3
PING6(56=40+8+8 bytes) 2001:db8:0:1:2a0:a502:0:19da --> 2001:db8::3
16 bytes from 2001:db8::3, icmp_seq=0 hlim=64 time=2.146 ms
16 bytes from 2001:db8::3, icmp_seq=1 hlim=64 time=1.964 ms
16 bytes from 2001:db8::3, icmp_seq=2 hlim=64 time=1.550 ms

Published: 2013-07-23

Published: 2013-07-23