Monday, November 23, 2015

Cisco - Linux Commands on IOS

Today we’re going to go over a little known shell in IOS that gives us some bash like functionality! It is called

We can enable this little known functionality with the terminal shell command, like the rest of the terminal commands this only enables for the current terminal session.

R1#terminal shell

If you want to have the shell enabled permanently with the following global command

R1(config)#shell processing full

R1#show terminal | in Shell
Shell: enabled
Shell trace: off

Now is enabled! Awesome! But what does it do?
The simple answer is it makes IOS more like a Linux shell, it allows us to create variables, make loops, and use some linux utilities like grep or wc on the shell.


Using GREP

One of the neatest features of is the ability to use the grep utility to filter output. Let’s start by looking at the manpage for Grep, yes there are manpages!

R1#man grep
grep - get regular expression

    grep [OPTIONS] <Regular Expression> [<file>...]

    The 'grep' command matches lines in the given files
    with the supplied regular expression, and prints matching
    lines. There are lots of options
    -b              - match everything in a file after pattern
    -c              - print a count of lines instead of matched lines
    -e <pat>    - use &lt;pat&gt; as the pattern (it may have a leading minus)
    -h             - do not print filename for each match (default)
    -H             - print filename for each match
    -i              - ignore case
    -l              - print only files with match
    -L             - print only files without match
    -m            - match everything in a matching mode
    -n             - print line numbers along with matches
    -q             - quiet, only set status
    -s             - supress printing errors
    -u             - match everything in a file until pattern
    -v             - invert match, print non-matching lines

Part of the power of this command is because you can be more flexible than the standard include pipe command because you can do things like combine include and exclude like statements in the same line.

R1#show ip route | grep (150) | grep (10003)    
O [110/10003] via, 15:51:41, GigabitEthernet1.146
O [110/10003] via, 15:51:41, GigabitEthernet1.146
O IA [110/10003] via, 1d11h, GigabitEthernet1.146

R1#show ip route | grep (150) | grep -v (10003) is subnetted, 11 subnets
C is directly connected, Loopback0
O [110/2] via, 15:51:57, GigabitEthernet1.146
O [110/3] via, 15:51:57, GigabitEthernet1.146
O [110/2] via, 1d12h, GigabitEthernet1.146
O IA [110/3] via, 1d12h, GigabitEthernet1.146
O IA [110/4] via, 15:52:07, GigabitEthernet1.146
O IA [110/4] via, 1d12h, GigabitEthernet1.146
O IA [110/5] via, 15:52:07, GigabitEthernet1.146

R1#show ip route | grep 150 | grep -v 10003 | grep 6\.6
O [110/2] via, 00:35:18, GigabitEthernet1.146
O IA [110/3] via, 00:35:08, GigabitEthernet1.146
O IA [110/4] via, 00:35:08, GigabitEthernet1.146



WC can be used to count the number of things in the output.

R1#man wc

    wc [OPTION]... [FILE]...

    Print newline, word, and byte counts for each FILE, and a total line if
    more than one FILE is specified. Read pipe input if no files are given
    -c print the byte counts
    -m print the character counts
    -l print the newline counts
    -L print the length of the longest line
    -w print the word counts

R1#show run | wc -l


Heads and Tails

These commands can be used to show the top x or bottom x lines of output, this can be handy with trying to see the latest logs.

R1#man head
    head - print the first lines in the input

    head [<n>]

    The 'head' program will print the first lines in
    its input. If given a numeric argument, it will
    print that many lines. The default number of lines
    is 10.

R1#man tail
    tail - print the last lines in the input

    tail [<n>]

    The 'tail' program will print the last lines
    in its input. If given a numeric argument, it
    will print that many lines. The default number
    of lines is 10.

R1#show run | head 10
Building configuration...

Current configuration : 2844 bytes
! Last configuration change at 18:14:38 UTC Tue Nov 17 2015
version 15.5
no service timestamps debug uptime
no service timestamps log uptime
no platform punt-keepalive disable-kernel-core

R1#show run | tail 10
exec-timeout 0 0
privilege level 15
logging synchronous
stopbits 1
line vty 0 4
privilege level 15
no login



Ok fine, we can use the cat command to view text files on the Cisco device.

R1#man cat
    cat - write files or standard input to output

    cat [<file>...]

    The cat command writes whatever it sees to its output

    R1#copy running-config flash:cat.test
    Destination filename [cat.test]?
    2844 bytes copied in 0.463 secs (6143 bytes/sec)

R1#cat flash:cat.test
! Last configuration change at 18:14:38 UTC Tue Nov 17 2015
version 15.5
no service timestamps debug uptime
no service timestamps log uptime
no platform punt-keepalive disable-kernel-core
platform console serial



Lets start with making variables by first looking at the variables

R1#man variables
    variables - describe the usage of variables

    Variables can be used in any context except single quotes. Variables
    can either be named, or numbered parameters to functions. Setting a
    named variable can be accomplished using an assignment statement.
    Assignment statments have a specific form, which is that the name of
    the variable must be immediately followed by an '=' sign. There can be
    no whitespace between the name and the '=':

    router> MYVAR='abc'

    The right side of the assignment is any string, but can also be the
    result of execution of a backquote expression, or the evaluation of a
    variable expansion.

    Variables may be used anywhere in subsequent input lines. One could,
    for example, create a shortcut for an interface name, and use it in
    config mode, or create a variable containing a number, and increment
    its value using arithmetic expression syntax (see man expressions).

    The main issue here is that the variable introduction character may
    conflict with existing usages, and so must be escaped in situations
    where a compatibility issue may arise. Please see man compatibility
    for more information.

To make a variable you simply have to enter VariableName=VariableValue


We can view the contents with the echo command

R1#echo $VAR1 $VAR2
Value1 Value2

You can also use variables in your commands


R2#ping $var1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 71/100/167 ms


Conditions and Loops

Following comparison operators can be used for working with integer values:
Operators   Characteristics
-eq               ==
-ne               !=
-lt                 <
-gt                >
-ge               >=
-le                =<

For working with files following conditions are available:

Operator    Characteristics
-a  or –e      True if file exists
-d               True if file exist and it is a directory
-f                True if file exists and is a regular file
-r                True if file exists and is readable
-s               True if file exists and has a size greater than zero
-w               True if file exists and is executable
-nt              Test if file1 is newer than file2. The modification date on the file is used for this comparison
-ot              Test if file1 is older than file2

Loops are very powerful (and dangerous if you don’t terminate them correctly) tools that allow you to carry out complex tasks.

R1#for x in 1 2 3 4 5 6 7 8 9
do..done>;ping 150.1.$x.$x

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 5/13/39 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 64/140/228 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 52/91/186 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 31/61/117 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 42/73/117 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 34/51/93 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 53/73/97 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 67/98/116 ms
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 78/98/122 ms



Lastly for this blog entry, you can define functions to make repeated tasks easier.

R1#function test-r1() {
{..} >ping
{..} >}

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to, timeout is 2 seconds:
Success rate is 100 percent (5/5), round-trip min/avg/max = 26/39/63 ms

You can see the functions defined on the system with show shell function

R4#show shell functions
User defined functions:

Function namespace: DEFAULT
    R1#function test-r1()


Taken From:

Sunday, November 15, 2015

Networking - Structured Cabling


Structured Cabling

Although the physical layout of a network will to some extent be determined by its size and the type of networking technology chosen, the cabling system is a critical element of any network. It is generally accepted that a significant number of network failures are caused primarily by cable-related problems. Getting the cabling system right, therefore, is essential for an effective data communications system. With this need in mind, the development of industry standards for cabling standards has accompanied developments in network and communication technology. National and international telecommunications cabling standards have been widely adopted, all of which are based on the American ANSI/TIA/EIA cabling standards. The standards have been evolving since the mid-1980s, with the aim of creating a structured system for data communications cabling systems used in buildings that would support multi-vendor networking products and environments. The result was the TIA/EIA 568 Commercial Building Telecommunication Cabling standard, released in 1991. The ISO/IEC-11801 Generic Customer Premises Cabling standard is an international cabling standard based on the ANSI/TIA/EIA-568 cabling standard. Related European standards include EN 50173 and EN 50174.

The standards define how to design, build, and manage a cabling system that is structured, meaning that the system consists of a number of discrete sub-systems or blocks, each of which has specific performance characteristics. The blocks are organised hierarchically within a unified communication system. A workgroup LAN block, for example, has lower-performance requirements than a network backbone block, which usually requires high-performance fibre-optic cable. The standards have evolved to support high-speed networking technologies such as Gigabit Ethernet, and advanced cable types such as Category 6 and Category 7 twisted pair cable.

Structured cabling (sometimes referred to as premise wiring) defines a generic telecommunication wiring system for commercial buildings, and comprises the cabling, connectors and accessories used to connect local area network and telephone system equipment within a building. It breaks cabling systems down into two main elements, horizontal wiring and vertical (or backbone) wiring. Structured cabling standards define the media, topology, termination and connection points, and administrative practice to be used.
Some terms of reference are defined below:

  • Horizontal wiring - all cabling between the telecommunications outlet in a work area and the horizontal cross-connect (also known as a floor distributor) in the telecommunications closet, including the telecommunications outlet itself, an optional consolidation point (or transition point) connector, and the horizontal cross-connect. Horizontal wiring, as the name suggests, usually runs horizontally (e.g. above suspended ceilings or below computer flooring) and does not go up or down between floors in a building. The maximum distance allowed between the telecommunications closet and the communication outlets is 90 metres, regardless of cable type. An additional 6 meters is allowed for patch cables at the telecommunication closet and in the work area, but the combined length of these patch cables cannot exceed 10 meters. The horizontal cable should be four-pair 100Ω UTP cable (the latest standards specify Category 5E as a minimum), two-fibre 62.5/125-mm fibre-optic cable, or 50/125-mm multimode fibre-optic cable.
  • Vertical (or backbone) wiring - runs up through the floors of a building (risers) or across a campus, and is the cable used between telecommunications closets, entrance facilities, equipment rooms and buildings, including all cables, cable terminations, and intermediate and main cross connects. Backbone wiring runs between telecommunications closets, equipment rooms and entrance facilities on the same floor, from floor to floor, and even between buildings. The standards specify a hierarchical star topology for backbone cabling, in which all wiring radiates from a central location called a main cross-connect (usually the telecommunications closet). Each telecommunications closet or entrance facility is either cabled directly to the main cross-connect, or via intermediate cross connects. The distance limitations for this cabling depend on the type of cable used and the facilities it connects (twisted pair cable is limited to 90 meters).
  • Work area - a building space in which operatives utilise telecommunications equipment. It includes all cable components between communication outlets (wall sockets) and end-user telecommunications equipment, such as telephones, workstations and printers, including the communication outlet itself. Work area cabling systems are designed to be flexible, but still require careful management. Standard structured cabling installation procedures should be observed when installing work area outlets, and cable terminations should be carried out using the same standard (T568A or T568B) throughout the system to avoid problems like crossed pairs which may arise if standards are mixed. T568B is the more commonly used standard in data applications. The standard requires that two outlets should be provided at each wall plate - one for voice, and one for data.
  • Telecommunications  room/closet (or wiring) - an enclosed area, such as a room or a cabinet, for housing telecommunications equipment, distribution frames, cable terminations and cross connects. In other words, all the hardware required to connect horizontal wiring to vertical wiring. This area will often also house auxiliary equipment, including network file servers. Every building must have at least one wiring closet, and the standard recommends one per floor. Specific closet sizes are also recommended, depending on the size of the service area. There must be sufficient space for service personnel to perform maintenance and carry out other duties, as well as for all of the required hardware. Lighting, power supplies and environmental conditions should also meet the requirements specified by the standard.
  • Equipment room - the space that houses building telecommunications systems such as PBXs, servers, switches etc., and the mechanical terminations of the telecommunications wiring system. It is considered to be different from a telecommunications closet because of the complexity of the components it houses. An equipment room can either take the place of a telecommunications closet or be a separate facility. The functions of an equipment room may even be incorporated in a wiring closet. The equipment room provides a termination point for vertical (backbone) cabling that is connected to one or more telecommunication closets. It may also be the main cross-connection point for the entire facility. In a campus environment, each building may have its own equipment room, to which telecommunication closet equipment is connected, and the equipment in this room may then be connected to a central campus facility that provides the main cross-connect for the entire campus.
  • Entrance facility - contains the telecommunication service entrance to the building, and may also contain campus-wide backbone connections. It also contains the network demarcation point, which is the interconnection to the local exchange carrier's telecommunication facilities. The demarcation point is typically 12 inches from where the carrier's facilities enter the building, but the carrier may designate otherwise.
  • Cabling administration - this is a process that includes all aspects of premise wiring activities related to documenting, managing, and testing the system, as well as compiling and maintaining the architectural plans for the system.





Structured cabling elements

The diagrams below show the relationship between the horizontal cabling elements in a structured cabling system for both a cross-connect and aninterconnect arrangement. In both cases, the permanent link is the telecommunications outlet (TO), the horizontal cabling, and the horizontal interconnect (patch panel). An optional transition point (TP) is allowed within the 90 metres of horizontal cabling.




Horizontal cabling elements

The channel is the work area cable (the patch lead) from the terminal equipment into the terminal outlet, the permanent link as already described, a patch cord linking two patch panels, and a final equipment cable into the LAN equipment. The use of two patch panels (a cross-connect) is optional. In many systems, only one is used (an interconnect). Note that in the interconnect version, the maximum combined length of patch cords A and B is 10 metres. In the cross-connect arrangement, the maximum combined length of patch cords A, B and C is also 10 metres.

Some requirements and recommendations

  • Permanent links must not exceed 90 metres.
  • The combined length of patch cords in any channel must not exceed 10 metres.
  • There should be no more than two levels of cross-connect in the backbone. This allows a horizontal cross-connect between the horizontal cabling and the building backbone, and an intermediate cross-connect between the building backbone and a campus backbone, with all campus cables terminating in the main cross-connect.
  • A total of 2000 metres of backbone cabling may be employed, consisting of up to 500 metres of building backbone and 1500 metres of campus backbone.
  • Campus cabling links communications facilities in different buildings and is likely to be optical fibre.
  • A minimum of one horizontal cross connect (or floor distributor) should be provided for every floor (one per 1000 m2 of office space is recommended). One telecommunications outlet should be provided at each work area. A minimum of two per 10 m2 of floor space is recommended.


Backbone cabling (including campus cabling) and horizontal cabling

Recommended Cabling



100Ω 4-pair UTP cabling is recommended, as it has a relatively low cost and supports a range of applications. Enhanced Category 5 (Cat5E) is the suggested minimum specification, as it will support data rates of up to 1 Gbps. Many new installations are now employing Category 6 cabling to support current and future high-bandwidth applications.

150Ω 2-pair STP is generally used for Token Ring applications, although due to its extended bandwidth it can also be used for broadband video applications up to 300 MHz, or for 155-Mbps ATM.

Coaxial cable is not recommended for horizontal wiring.

Fibre optic cable, although both more expensive more difficult to install than other types of cable, is the recommended transmission medium for backbone cabling, because it offers high speed transmission, high bandwidth, and carries data over much greater distances than copper cable. It is also immune to electromagnetic interference, and less likely to require replacement (fibre can also be used for horizontal wiring runs exceeding 100 metres).

100Ω 4-pair UTP cabling can also be used in short-to-medium distance vertical cabling in voice and data networks.
150Ω 2-pair STP can be used for Token Ring networks.

50Ω 10Base2 coaxial cable is recognised by the TIA/EIA standard as a suitable choice for economical vertical wiring, but it is rarely, if ever, used in new installations.

Based On

Sunday, November 1, 2015

Cisco - Port Mirror (SPAN / RSPAN / ERSPAN)


Switch port Analyzer (SPAN) is an efficient, high performance traffic monitoring system. It duplicated network traffic to one or more monitor interfaces as it transverse the switch. SPAN is used for troubleshooting connectivity issues and calculating network utilization and performance, among many others. There are three types of SPANs supported on Cisco products, which are illustrated in below diagram.

Types of SPAN:




Local SPAN: Mirrors traffic from one or more interface on the switch to one or more interfaces on the same switch.
Remote SPAN (RSPAN): An extension of SPAN called remote SPAN or RSPAN. RSPAN allows you to monitor traffic from source ports distributed over multiple switches, which means that you can centralize your network capture devices. RSPAN works by mirroring the traffic from the source ports of an RSPAN session onto a VLAN that is dedicated for the RSPAN session. This VLAN is then trunked to other switches, allowing the RSPAN session traffic to be transported across multiple switches. On the switch that contains the destination port for the session, traffic from the RSPAN session VLAN is simply mirrored out the destination port.
Encapsulated remote SPAN (ERSPAN): encapsulated Remote SPAN (ERSPAN), as the name says, brings generic routing encapsulation (GRE) for all captured traffic and allows it to be extended across Layer 3 domains.

ERSPAN is a Cisco proprietary feature and is available only to Catalyst 6500, 7600, Nexus, and ASR 1000 platforms to date. The ASR 1000 supports ERSPAN source (monitoring) only on Fast Ethernet, Gigabit Ethernet, and port-channel interfaces.

Configuration Example:
Configuring Local SPAN: Local SPAN configures using “monitor session” command specifying source and destination on the same switch.

Switch1# configure terminal
Switch1(config)# monitor session 1 source interface fastEthernet0/2
Switch1(config)# monitor session 1 destination interface fastEthernet0/24

Local SPAN configuration syntax on Cisco IOS release 12.2(33)SXH and beyond as shown below.

monitor session 1 type local
source int fa0/2
destination int fa0/24



Step1: In order to configure RSPAN you need to have an RSPAN VLAN, those VLANs have special properties and can’t be assigned to any access ports. To create a VLAN for RSPAN on Cisco IOS, you must create the VLAN via the config-vlan configuration mode, as opposed to using the older VLAN database configuration mode. During the process of defining VLAN parameters, you must specify that the new VLAN is an RSPAN VLAN by configuring the remote-span VLAN configuration command.

Switch1# configure terminal
Switch1(config)# vlan 200
Switch1(config-vlan)# remote-span
Switch1(config-vlan)# end
Switch1# show vlan remote-span

Switch2# configure terminal
Switch2(config)# vlan 200
Switch2(config-vlan)# remote-span
Switch2(config-vlan)# end
Switch2# show vlan remote-span

Step2: Then configure the RSPAN on Source switch: Unlike SPAN, where the source and destination ports exist on the same switch, the source and destination ports for an RSPAN session reside on different switches. This requires a separate RSPAN source session to be configured, as well as a separate RSPAN destination session to be configured.

Switch1# configure terminal
Switch1(config)# monitor session 1 source interface fastEthernet0/2 rx
Switch1(config)# monitor session 1 destination remote vlan 200
reflector-port fastEthernet0/24
Switch1(config)# exit

Switch1# show monitor
Session 1
Type                 : Remote Source Session
Source Ports     :
   Rx                 : Fa0/2
Reflector Port    : Fa0/24
Dest RSPAN VLAN  : 200

Step3: Configure the RSPAN on destination switch:
Switch2# configure terminal
Switch2(config)# monitor session 1 source remote vlan 200
Switch2(config)# monitor session 1 destination interface fastEthernet0/3
Switch2(config)# exit

The RSPAN VLAN should be allowed in ALL trunks between the involved switches (Source and Destination switches in this case); if you have enabled "pruning" in your network, remove the RSPAN VLAN from the pruning, with the command: “switchport trunk pruning vlan remove <RSPAN VLAN ID>” under the interface configure as trunk.



In this example we will capture received traffic on the ASR 1002 (GigabitEthernet0/1/0) and send to Catalyst 6509 Gig2/2/1. This traffic will simply be captured, encapsulated in GRE by ASR 1002 natively by the QFP chipset and routed over to the Catalyst 6509. A sniffing station on the 6500 attached to GE2/2/1 will see the complete Ethernet frame (L2 to L7) information.
Configuring source interface, direction of traffic, and ERSPAN session ID on the ASR 1002.

ASR1002(config)# monitor session 1 type erspan-source
ASR1002(config-mon-erspan-src)# source interface gig0/1/0 rx
ASR1002(config-mon-erspan-src)# no shutdown
ASR1002(config-mon-erspan-src)# destination
ASR1002(config-mon-erspan-src-dst)# erspan-id 101
ASR1002(config-mon-erspan-src-dst)# ip address
ASR1002(config-mon-erspan-src-dst)# origin ip address

Configuring Catalyst 6509 to receive traffic from the source session on the ASR 1002

SW6509(config)# monitor session 2 type erspan-destination
SW6509(config-mon-erspan-dst)# destination interface gigabitEthernet2/2/1
SW6509(config-mon-erspan-dst)# no shutdown
SW6509(config-mon-erspan-dst)# source
SW6509(config-mon-erspan-dst-src)# erspan-id 101
SW6509(config-mon-erspan-dst-src)# ip address

You can use the show monitor session command to verify the configuration:

ASR1002#sh monitor session 1
Session 1
Type                             : ERSPAN Source Session
Status                           : Admin Enabled
Source Ports                  :
RX Only                         : Gi0/1/0
Destination IP Address   :
MTU                              : 1464
Destination ERSPAN ID  : 101
Origin IP Address           :

To monitor the statistics of monitored traffic, you need to use "show platform hardware qfp active feature erspan state" command:

ASR1002#show platform hardware qfp active feature erspan state
Status                : Active
Complexes         : 1
CPPs                 : 1
Capabilites          :
Max sessions      : 1024
Max outputs        : 128
Encaps type        : ERSPAN type-II
GRE protocol       : 0x88BE
MTU                    : 1464
IP TOS                : 0
IP TTL                 : 255
COS                   : 0
System Statistics:
DROP src session replica :                  0 /                 0
DROP term session replica:                 0 /                 0
DROP receive malformed   :                 0 /                 0
DROP receive invalid ID  :                    0 /                 0
DROP recycle queue full  :                   0 /                 0
DROP no GPM memory       :               0 /                 0
DROP no channel memory   :               0 /                 0
Client Debug Config:
Enabled: Info, Warn
Data Path Debug Config:

Note: is SW6509’s loopback. Is ASR1002's loopback. ip address in destination session and ip address in source session should match. If they don't- that is causing the drops you see.

Taken From: