XpressLearn Home

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Switchport Macros

Smartports macros provide a way to save and share common switch port configurations. You can use Smartports macros for repetitive configuration tasks, such as setting up interfaces for use with a particular type of system. Even for seasoned professionals, macros offer advantages such as consistent configuration. Because we are human and prone to mistakes, switchports commonly get configured a little different each time it is performed.

Let’s start with an example macro for the configuration of workstation connected switch ports. This particular macro is called workstation and contains the commands you would typically use on the interface configuration for connecting standard PC’s. The macro can also contain comments, which are defined with the pound sign. Any line starting with # will simply be ignored by the macro, however they can be of big help when reviewing the contents of the macro to understand what each command is intended for. Also, you will notice that the first two lines after the macro name are comments that tells what to use this macro for and how to run it on a switch port

@
macro name workstation
# Configure port for standard workstation connectivity
# Usage: macro apply workstation $vlan "vlan number"
description Accounting Department PC
switchport access vlan $vlan
switchport mode access
# Configure portfast
spanning-tree portfast
# Speed and Duplex
speed auto
duplex auto
# Turn off CDP on user port
no cdp enable
# In case the port is disabled
no shutdown
# Remove the reference to the macro that was ran on this interface
no macro description
@

Let’s say we want to configure a switch port for connecting to a workstation and it will reside in vlan 10. To apply the previous macro, you would do the following:

switch(config)#interface Gig1/0/1
switch(config-if)#macro apply workstation 10

It’s always best practice to have all non-connected ports in a shutdown state. The following macro will reset an interface back to a default state and disable the port.

@
macro name portniu
# Unassign a switch port
# Usage: macro apply portniu
shutdown
description NIU
no switchport
switchport
no spanning-tree portfast
speed auto
duplex auto
no macro description
@

When creating your own macros, keep in mind the following guidelines:

The switches that support macros also have a few already built in, which may do everything you need. The six default macros are:

cisco-global
cisco-desktop
cisco-phone
cisco-switch
cisco-router
cisco-wireless

The default macros will not show up in the running configuration. However, any custom macros that are created will show up near the top of the switch’s running configuration. To view the contents of each default macro, use the following command:

switch#show parser macro

Macros are a huge time saver, consider using them in your next deployment.

Author Info:

 
Scott is the Founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs Xpresslearn.
 

Scott has been working in the networking field for 13 years and has experience in all the areas: Lan, Wan, Security, Optimization, High Availability, Wireless, and others.

When he is not working on further development of Xpresslearn, Scott loves spending time with his family and has such hobbies as Camping, Fishing, Cars, and Woodworking.

Related Posts:


Leave a Reply