Network Enhancers - "Delivering Beyond Boundaries" Headline Animator

Sunday, April 3, 2011

JUNOS Configuration Manipulation - TIPS

Background


Junos has lots of cool tricks that performed on the configuration such as deleting entire stanzas, wildcard deletes, renaming (such as renaming a physical interface), apply groups for inheritances so that you can trim down you config file and remove repetitive statements. Maybe tricks is a bad word in that it implies that it might be something that this is not obvious, these operations are common place in Junos.

Configuration Manipulation


Note: Junos has two modes operational (denoted by the > prompt) and config (denoted by the # prompt). When you type > configure from the operational prompt, you are in a candidate config which is a config that must be commited before it becomes the running configuration.


Rollback to previous config


[edit]admin@router# rollback <previous config number>

where <config number> is the number of the rollback which you want to revert to
you can view the rollbacks by

[edit]admin@router# rollback ?


Compare current candidate config to a rollback

[edit]admin@router# show | compare rollback <previous config number>



Commiting a config and have it revert if it has not been confirmed


This is the famous commit confirmed, useful if you are remoting in and dont want to lock yourself out.

[edit]
admin@router# commit confirmed <number of minutes>

The way this works is if you type commit confirmed 1, Junos will commit the configuration to the running state for a minute. Junos will revert the config back to the previous state if commit is not typed again. If you don't type commit, Junos within the number of minutes specified, Junos assumed you cannot reach the router.


Wildcard delete


Lets say you want to delete all interfaces that begin with a certain string, ge-0/0, in your configuration

[edit]admin@router# wildcard delete interface ge-0/0/*

Junos will prompt for confirmation of the parts of the config it will delete to make sure you don't accidentally delete a part of the config you did want to get deleted.
This works on all parts of the config not just interfaces, interfaces is just a common example.


Interface Range


As of Junos 10.0 you can specify an interface range to apply a similar config to multiple interfaces.
e.g. This config makes the interfaces listed members of the vlan vlan-trust. I know this is supported on Jseries, SRX and EX, I have not verified if it supported on M, MX or T.

  interfaces {
   interface-range interfaces-trust {
       member ge-0/0/1;
       member fe-0/0/2;
       member fe-0/0/3;
       member fe-0/0/4;
       member fe-0/0/5;
       member fe-0/0/6;
       member fe-0/0/7;
       unit 0 {
           family ethernet-switching {
               vlan {
                   members vlan-trust;
               }
           }
       }
   }




Copy config to another part of the config


Say all your interfaces were configured the same, eg a switch. You can copy the interface settings to another interface. Once again applies to other parts of the configuration, interfaces just a common example.

[edit]admin@router# copy interfaces ge-0/0/0 to ge-0/0/1

Rename a interface or user defined variable

You can rename an interface

[edit]
admin@router@ rename interface ge-0/0/0 to egress


Now ge-0/0/0 will be referred to as egress in your configuration.

Another example
Rename ospf area 0.0.0.0 to area 0.0.0.1

[edit]
admin@router# rename protocols ospf area 0.0.0.0 to area 0.0.0.1




Display specific parts of the configuration


Say you just wanted to see the interfaces

admin@router# show interfaces


or bgp

admin@router# show protocols bgp



Save configuration

Saves your entire configuration to a filename.

admin@router# save <configuration file name>



to see what has been saved

[edit interfaces]
admin@router# show <configuration file name>



Save specific section of the configuration

Note to get to get into a section, type edit <section name>

Saves everything in the section you are in to a filename. Interfaces just an example.

[edit interfaces}
admin@router# save <configuration file name>


to see what has been saved

[edit interfaces]
admin@router# show <configuration file name>




Save time by editing configuration from specific section


Say you were just editing the interfaces and did not want to type

[edit]
admin@router# set interface blah blah

you can jump to that part of the configuration
admin@router# edit interfaces
 [edit interfaces]
admin@router# set ge-0/0/0 unit 0 family inet address 1.1.1.1/24


you can jump down as far as you need, just type edit then where you want to go.


Edit another section while you are in a different section


Say you wanted to configure OSPF real quick, but you were in the interface section and did not want to leave it. Just use top in front of your set commands and Junos treats it as you were at the root of the config.

[edit interfaces]
admin@router# top edit protocols ospf area 0.0.0.0




Display Junos configuration in XML


Remember all queries and responses are xml based, that goes for the configuration format itself and queries about interfaces, snmp, ospf, bgp, etc.

[edit]
admin@router# show | display xml

To show bgp summary in xml

[edit]
admin@router# run show bgp summary | display xml


Useful when you begin junoscript, it is xml based.



Find what you are looking for


Say you want to find all lines in the configuration that match a certain pattern, an IP address for example.
[edit]
admin@router# show | match 192.168.0.1
You can also look for the first occurrence. Use find instead of match and note that the remaining configuration following the first found item will be displayed as well.


See how to reproduce a configuration


If you want to recreate a configuration by hand, you can see the commands needed by passing a | display set command
[edit]
admin@router# show | display set
set version 9.0R3.6
set system host-name router
set system domain-name example.com
set system time-zone PST8PDT
set system arp passive-learning
set system name-server 4.2.2.2
[...]

Note that the resulting output will always be printed as if to be re-entered at the top level of the configuration:
[edit interfaces]
admin@router# show ge-0/0/0 | display set

set interfaces ge-0/0/0 description "Out of band Management"
set interfaces ge-0/0/0 unit 0 family inet address 192.168.0.251/24
[...]


Emacs style cursor movement


Remember Junos is heavily influenced by Unix, afterall it does sit on top of FreeBSD. You can use EMACS commands for cursor movement, which include:

Ctrl-a  Moves the cursor to the beginning of the command line, back to the prompt
Ctrl-e Moves the cursor to the end of the command line
Ctrl-b Moves the cursor back one character
Ctrl-k Delete everything from the current cursor position to the end of the line
Ctrl-x Delete the entrie line.
Ctrl-l Bring back the current line
Ctrl-p Scroll back through command history (analogous to up arrow)
Ctrl-n Scroll forward through command history (analogous to down arrow)
Ctrl-r Search command history for a string


Page manipulation


Just like in GNU less you can

say you run a show, this has been pageanated, that is split into pages if the output of the command shows more than one screen. You can go all the way to end by hitting
G
similarly you can return to the first of the output by typing
g

You can also search for a string in the page by
/(your search string)

No comments:

Post a Comment

My Blog List

Networking Domain Jobs