O'Reilly logo

JUNOS Cookbook by Aviva Garrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 1. Router Configuration and File Management

Introduction

Juniper Networks routers are specialized network devices that run network operating system software, which is called JUNOS software. In this book, we talk about JUNOS features that run on the J-series, M-series, and T-series router platforms. The M-series and T-series platforms are larger routers typically used by network service providers, telephone companies, large enterprise companies, and universities. The J-series routers are smaller routers designed for use by businesses and other organizations to connect multiple sites or to connect to the Internet. The JUNOS software is pre-installed on a new Juniper Networks routers: when you turn the router on, the software automatically starts running. The first task you have to perform is configuring the router.

JUNOS software is distributed as a set of modular software packages that contain the various components of the software. A given JUNOS software release runs on all J-series, M-series, and T-series routers. The examples in this book are based on the JUNOS 7.4 release of the software on either M20 routers or J2300 routers, but all are applicable for the most recent JUNOS releases and for future releases on the M-, T-, and J-series families of routers.

This chapter discusses basic router configuration, including how to configure the router for the first time, configuring from the command-line interface ( CLI), loading and saving configuration files, and working with the filesystems and files used by the JUNOS software. It also discusses how to upgrade the JUNOS software and how to gather hardware and software inventory information.

When you first start a router, you must configure basic network information, such as the router name, IP address, and domain name, so that the router is reachable on the network. You then configure the desired software features. To configure the router, you generally log in to the router and use the JUNOS CLI. Some routers, including the J-series, also have a web-based interface called J-Web. From the CLI, you specify the configuration in a plain-text (ASCII) configuration file, which you can read from the CLI (on the router) or by using any ASCII text editor (on a server). From J-Web, the configuration is saved in an ASCII file that you can read using J-Web, the CLI, or an ASCII text editor.

JUNOS CLI Modes

Throughout this book, we'll show you how to use the JUNOS CLI to configure and monitor the router. While it is beyond the scope of this book to describe the design of the CLI and all its capabilities, this section gives an overview of the CLI modes and describes a few of the basic features. Throughout the rest of this chapter, we'll give more examples of CLI features. For complete information about the JUNOS CLI, refer to the JUNOS product documentation on the Juniper Networks web site, http://www.juniper.net/techpubs.

The underlying operating system for the JUNOS software is FreeBSD. As we talk about the various CLI commands, if a command is derived from FreeBSD or a standard Unix utility, or is simply the FreeBSD or Unix command packaged with a JUNOS name, we will mention the command it is based on. If you are already familiar with the FreeBSD or Unix equivalent, this will help you understand the JUNOS command.

The CLI has two modes: operational mode and configuration mode. Both modes have distinct commands. In operational mode, you monitor everything about the router's hardware and software and check on network operation. In configuration mode, the commands let you define the behavior of the router, such as indicating what network addresses to use and protocols to run. It is important for you to understand the differences between these two modes, what types of actions you can take in which mode, and how to keep track of which mode you are working in. Throughout the rest of this book, we'll show you how to work in both modes as you configure the router and verify its operation.

On the router, you can identify which mode you are in by looking at the CLI prompt. The base prompt has the format . When you are in operational mode, the prompt ends with a >; when you are in configuration mode, the prompt ends with a #. We follow this same convention throughout this book, so by paying attention to the prompt that precedes each command, you can determine whether you issue the command in operational or configuration mode.

When you first log in to a JUNOS router, you are in operational mode. The commands available in operational mode let you monitor router and network operations. For example, you can get information about the router's hardware and software, the network traffic that is coming to the router, and configured routing protocols. Throughout this book, we'll show you how to use operational mode commands to check what is happening on the router.

You can use a number of operational mode commands, grouped together into related commands, to monitor your router and network. On the router, you can find out what the commands are by typing a question mark ( ?) to activate the online help. If you type a ? at the top level of operational mode, you see the broad types of commands you can use to monitor the router and perform operations not related to configuring the router:

	aviva@router1> ?
	Possible completions:
	   
clear                Clear  
information in the system
	   
configure            Manipulate software configuration information
	   
file                 Perform file operations
	  help                 Provide help information
	  monitor              Show real-time debugging information
	   
mtrace               Trace multicast path from source to receiver
	  ping                 Ping remote target
	   
quit                 Exit the management session
	   
request              Make system-level requests
	   
restart              Restart software process
	   
set                  Set CLI properties, date/time, craft interface message
	  show                 Show system information
	   
ssh                  Start secure shell on another host
	  start                Start shell
	   
telnet               Telnet to another host
	   
test                 Perform diagnostic debugging
	  traceroute           Trace route to remote host

For example, you use the various show commands to display information about the router, router interfaces, and protocol software, and you use the various request commands to perform operations on the router, such as rebooting and downloading and installing software upgrades.

Two commands in operational mode are not designed to monitor the router or the network:

quit

Use to log out of the CLI and the router

configure

Use to enter configuration mode so you can configure the router

When you enter configuration mode, the prompt changes from to , and a line before the prompt, [ edit], indicates that you are in configuration mode. Specifically, [edit] indicates that you are at the top of the configuration hierarchy, which is similar to being at the top of a Unix filesystem (/). A synonym for the configure command is edit. (edit is a hidden command, so you won't see it in the list of possible completions.)

Configuration mode has two basic components:

commands

Use to perform actions within the router's configuration

statements

The actual keywords that define the configuration

To create or modify the router's configuration, use the commands that are available in configuration mode to add statements to the configuration that define the behavior of the router. If you type a ? at the top level of configuration mode, you see the broad types of commands you can use while configuring the router:

	[edit]
	aviva@router1# ?
	Possible completions:
	  <[Enter]>      Execute this command
	  activate             Remove the inactive tag from a statement
	  annotate             Annotate the statement with a comment
	  commit               Commit current set of changes
	  copy                 Copy a statement
	  deactivate           Add the inactive tag to a statement
	  delete               Delete a data element
	  edit                 Edit a sub-element
	  exit                 Exit from this level
	  help                 Provide help information
	  insert               Insert a new ordered data element
	  load                 Load configuration from ASCII file
	  quit                 Quit from this level
	  rename               Rename a statement
	  rollback             Roll back to previous committed configuration
	  run                  Run an operational-mode command
	  save                 Save configuration to ASCII file
	  set                  Set a parameter
	  show                 Show a parameter
	  status               Show users currently editing configuration
	  top                  Exit to top level of configuration
	   
up                   Exit one level of configuration
	  wildcard             Wildcard operations

When creating or modifying a configuration, you primarily use the edit and set commands to control which configuration statement to include. Use the edit command to move to the portion of the configuration you want to modify (this is similar to using the Unix cd command to move to a different directory) and use the set command to configure a specific item. The up command moves up one hierarchy level, and the top command returns to the top of the hierarchy, [edit] (this command is similar to the Unix cd / command). At the top level, use the exit or quit command to return to operational mode.

The show command displays the items in the configuration, starting at the current hierarchy level. If you start at the [edit] level, you see the entire configuration:

	[edit]
	aviva@router1# show
	version "7.4R1.7";
	groups  
{
	    re0 {
	        system {
	            host-name router1;
	        }
	        interfaces {
	            fxp0 {
	                unit 0 {
	                    family inet {
	…

If you are at a lower level, you see just that portion of the configuration. The following example starts in the OSPF portion of the configuration:

	[edit protocols ospf]
	aviva@router1# show
	export export-statics;
	area 0.0.0.0 {
	    interface fe-0/0/1.0;
	    interface fe-1/0/1.0;
	}

Why are there curly braces here? The JUNOS software uses curly braces to represent the structure of the configuration file, delineating related sections of configuration parameters. If you are a C-language programmer, you will be very familiar with them.

The opposite of the set command is delete, which removes an item from the configuration. You can delete an individual item from the configuration (such as delete interface fe-1/0/1.0 from the OSPF configuration above), or you can delete an entire section—here the area 0.0.0.0 section from the OSPF configuration:

	[edit protocols ospf]
	aviva@router1# delete area 0.0.0.0
	aviva@router1# show
	export export-statics;

Another time-saving command is run, which allows you to issue an operational command from within configuration mode. For example, the run show route command from configuration mode is the same as the show route command from operational mode:

	[edit]
	aviva@router1# run show route <-- # in prompt indicates configuration mode
	inet.0: 20 destinations, 20 routes (19 active, 0 holddown, 1 hidden)
	+ = Active Route, - = Last Active, * = Both
	0.0.0.0/0          *[Static/5] 07:36:18
	                      Discard
	…
	aviva@router> show route <-- > in prompt indicates operational mode
	inet.0: 20 destinations, 20 routes (19 active, 0 holddown, 1 hidden)
	+ = Active Route, - = Last Active, * = Both

	0.0.0.0/0          *[Static/5] 07:36:18
	                      Discard
	…

What does it mean to move to a portion of the configuration? You can think of the JUNOS configuration as a hierarchy of configuration statements and containers, delimited by braces ({}) that define the scope in which those statements apply. This hierarchy provides a way to organize the large number of features and functions that you can configure on the router, grouping related functions together so that you can locate them when configuring the router and when reviewing the configuration. When you first enter configuration mode, you are at the top of the hierarchy. You see your location in the hierarchy in the line that precedes the configuration mode prompt. The line [edit] indicates that you are at the top of the hierarchy. The edit command allows you to move within the configuration hierarchy so that all configuration commands take place within the current container. As you move through the hierarchy, the text in square brackets changes to indicate your location in the hierarchy.

The configuration statements that you use to set the router's behavior are also arranged in a hierarchical fashion. If you type edit ? at the top level of the configuration hierarchy, you see the broad functional JUNOS software areas that you can control through the configuration:

	[edit]
	aviva@router1# edit ?
	Possible completions:
	> access            Network access configuration
	>                   accounting-options Accounting data configuration
	>                   applications Define applications by protocol characteristics
	>                   chassis Chassis configuration
	>                   class-of-service Class-of-service configuration
	>                   firewall Define a firewall configuration
	>                   forwarding-options Configure options to control packet sampling
	>                   groups Configuration groups
	>                   interfaces Interface configuration
	>                   logical-routers Logical routers
	>                   policy-options Routing policy option configuration
	>                   protocols Routing protocol configuration
	>                   routing-instances Routing instance configuration
	>                   routing-options Protocol-independent routing option configuration
	>                   security Security configuration
	>                   services Service PIC applications settings
	>                   snmp Simple Network Management Protocol configuration
	>                   system System parameters

Each listed completion is the configuration statement at the top of a particular configuration hierarchy. For example, the statement protocols is at the top of the hierarchy in which you configure all JUNOS routing protocols:

	[edit]
	aviva@router1# edit protocols  
?
	Possible completions:
	  <[Enter]>         Execute this  
command
	> bfd                  Bidirectional Forwarding Detection (BFD) options
	> bgp                  BGP options
	> connections          Circuit cross-connect configuration
	> dvmrp                DVMRP options
	> igmp                 IGMP options
	> isis                 IS-IS options
	> l2circuit            Configuration for Layer 2 circuits over MPLS
	> ldp                  LDP options
	> link-management      LMP options
	> mld                  MLD options
	> mpls                 Multiprotocol Label Switching options
	> msdp                 MSDP configuration
	> ospf                 OSPF configuration
	> ospf3                OSPFv3 configuration
	> pgm                  PGM options
	> pim                  PIM configuration
	> rip                  RIP options
	> ripng                RIPng options
	> router-advertisement IPv6 router advertisement options
	> router-discovery     ICMP router discovery options
	> rsvp                 RSVP options
	> sap                  Session Advertisement Protocol options
	> vrrp                 VRRP options
	  |                       Pipe through a command

If you move down through the hierarchy—for example, into the protocols portion—the prompt changes to [edit protocols] to show you where you are:

	[edit]
	aviva@router1# edit protocols
	[edit protocols]
	aviva@router1#

Learning About the CLI While on the Router

In some of the command lines in the previous section, we showed how to use the ? to get context-sensitive help about the CLI and the software. This feature is part of the CLI's built-in help, and you will find yourself using it regularly. When you type a ? at a prompt, the CLI shows a list of commands or statements you can use, along with a short description of the command or statement. If you partially type a command or configuration statement name and then type a ?, you see a subset of the available commands or statements.

For example, in operational mode, you can find a subset of the show commands:

	aviva@router1> show r?
	Possible completions:
	  rip                   Show Routing Information Protocol information
	  ripng                 Show Routing Information Protocol for IPv6 information
	  route                 Show routing table information
	  rsvp                  Show Resource Reservation Protocol information
	aviva@router1> show r

The CLI displays the list of available commands and then redisplays the portion of the command you already typed so you do not have to retype it. For example, to show the contents of the routing table, you would now just type oute:

	aviva@router1> show r?
	Possible completions:
	  rip                   Show Routing Information Protocol information
	  ripng                 Show Routing Information Protocol for IPv6 information
	  route                 Show routing table information
	  rsvp                  Show Resource Reservation Protocol information
	aviva@router1> show r
	aviva@router1> show route

In configuration mode, you can list the subset of available configuration statements:

	[edit system]
	aviva@router1# set s?
	Possible completions:
	  saved-core-context     Save context information for core files
	  saved-core-files       Number of saved core files per executable (1..64)
	> services            System services
	> static-host-mapping Static hostname database mapping
	> syslog              System logging facility
	aviva@router1# set s^

To minimize the amount of typing you have to do, press the spacebar or Tab key to have the CLI complete a nonambiguous command or statement name. This is similar to how some Unix shells operate.

	aviva@router1# commit a<space>
	Possible completions:
	  and-quit               Quit configuration mode if commit succeeds
	  at                     Time at which to activate configuration changes
	aviva@router1# commit an<space>
	aviva@router1# command and-quit

The first command above is ambiguous because there are two possible completions. The second command is unique, so when you press the spacebar key (or Tab key), the CLI automatically completes the command. Press the Enter key to execute the command.

After you have typed a complete command (but before pressing Enter), another set of commands becomes available to allow you to control the format of the output. To access these commands, you first type a | (pipe), which directs the output from the command on the left side of the pipe into the command on the right side of the pipe, in exactly the same way that a Unix pipe works. The following commands are available:

	aviva@router1> show route | ?
	Possible completions:
	  count                Count occurrences
	  display              Show additional kinds of information
	  except               Show only text that does not match a pattern
	  find                 Search for first occurrence of pattern
	  hold                 Hold text without exiting the --More-- prompt
	  last                 Display end of output only
	  match                Show only text that matches a pattern
	  no-more              Don't paginate output
	  request              Make system-level requests
	  resolve              Resolve IP addresses
	  save                 Save output text to file
	  trim                 Trim specified number of columns from start of line

Another way to minimize typing is to use keyboard sequences. The simplest are the up and down arrows, which scroll through the most recent commands you typed. (The JUNOS software maintains a command history similar to Unix shell history.) If you want to modify rather than retype a command, you can use the left and right arrows and the Backspace and Delete keys. There are also a number of keyboard sequences that are similar or identical to Emacs commands that you can use to move around on a command line and edit it. Table 1-1 lists some common keystrokes.

Table 1-1. Keystroke sequences

Keystroke sequence

Action

Ctrl-p

Display previous command history line

Ctrl-n

Display next command history line

Ctrl-a

Move to beginning of line

Ctrl-e

Move to end of line

Ctrl-b

Move back one character

Ctrl-f

Move forward one character

Esc-b

Move back one word

Esc-f

Move forward one word

Ctrl-k

Delete everything from cursor to end of line

Esc-d

Delete one word forward (the word after the cursor)

Esc-Backspace

Delete one word backward (the word before the cursor)

Ctrl-y

Paste the deleted word or text at the cursor

Another aspect of the CLI help is online documentation, which is installed on the router's hard disk. This documentation is taken from the JUNOS product configuration guides. You can use the online documentation to get information about configuration statements while you are logged in to the router. To get high-level information about a configuration statement, you can use the help topic command. The following example shows how to get high-level help about configuring the domain name on the router:

	aviva@router1> help topic system domain-name
	Configuring the Router's Domain Name
	   For each router, you should configure the name of the domain in which the
	   router is located. This is the default domain name that is appended to
	   hostnames that are not fully qualified. To configure the domain name,
	   include the domain-name statement at the [edit system] hierarchy level:
	     [edit system]
	     domain-name domain-name;
	Example: Configuring the Router's Domain Name
	 Configure the router's domain name:
	   [edit]
	   user@host# set system domain-name company.net
	   [edit]
	   user@host# show
	   system {
	       domain-name company.net;
	   }

Use the help reference command to get help about the syntax and options of a configuration statement, similar to Unix manpages. The following shows the reference help that is displayed for the domain-name configuration statement:

	aviva@router1> help reference system domain-name
	domain-name
	 Syntax
	  domain-name domain-name;
	 Hierarchy Level
	  [edit system]
	 Description
	  Configure the name of the domain in which the router is located. This is
	  the default domain name that is appended to hostnames that are not fully
	  qualified.
	 Options
	  domain-name--Name of the domain.
	 Usage Guidelines
	  See "Configuring the Router's Domain Name".
	 Required Privilege Level
	  system--To view this statement in the configuration.
	  system-control--To add this statement to the configuration.

How We Show Commands and Configurations in This Book

In the explanation of the JUNOS CLI so far, we have described the different types of commands and illustrated what they look like when you type them on the router. Because it can be a bit confusing for newcomers, this section summarizes how we show the commands in this book.

Here is an operational mode command:

	aviva@router1> show route table inet.0

The > tells you that you are in operational mode, and the bold font shows what you type. The command is show route. The word table is an option for this command, and inet.0 is a variable (the name of a specific routing table) that is required to complete the table option. The table name is italicized because you can substitute the desired routing-table name.

Here are two configuration mode commands:

	[edit]
	aviva@router1 
# edit system
	[edit system]
	aviva@router1#  
set login user aviva class operator

You know you are in configuration mode because of the # after the prompt and because the CLI shows your location in the hierarchy of configuration statements by displaying the [edit] and [edit system] lines. edit and set are configuration mode commands. system, login, user, and class are configuration statements. aviva is a variable required for the user statement, and operator is an option required for the class statement. Again, what you type is shown in bold. The commands and statements, which you have to type exactly as shown, are in bold, and the variables, which you substitute with the proper values for your network, are italicized.

In this book, when we show how to configure the router, we generally show just the commands that you type and the configuration hierarchy level at which you type them, as shown above. Sometimes, however, if you have to type several commands to configure a feature or if you type a command that results in a multilevel hierarchy, we'll show you what the resulting configuration looks like. The configuration commands that we typed above result in the following configuration:

	[edit system]
	aviva@router1# show
	login {
	    user aviva {
	        class operator;
	    }
	}

When viewed from the top level of the statement hierarchy, it looks like this:

	[edit]
	aviva@router1# show
	system {
	    login {
	        user aviva {
	            class operator;
	        }
	    }
	}

We show this format for a couple of reasons. When you are on the router and configuring it, you might get lost or forget what you have already configured. The text in square brackets above the prompt (here, [edit]) is your road map to your location in the configuration statement hierarchy, and the show command displays what's already in the configuration. Another reason is that a JUNOS configuration is, in reality, just a text file. The format of the file is the same as what you see when you type the show command. The indentions indicate the configuration hierarchy levels, the curly braces ({ and }) indicate related groups of configuration statements, and a semicolon marks the end of an individual statement. In the book, we'll sometimes use this format as a way to summarize all the statements you need to include to configure a particular feature. You can compare what's in the book with what you have configured on the router to make sure that you have included everything.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required