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:
- When creating a macro, all CLI commands should be in the same configuration mode.
- When a macro is applied globally to a switch or to a switch interface, all existing configuration on the interface is retained. This is helpful when applying an incremental configuration.
- If you modify a macro definition by adding or deleting commands, the changes are not reflected on the interface where the macro was originally applied. You need to reapply the updated macro on the interface to apply the new or changed commands.
The switches that support macros also have a few already built in, which may do everything you need. The six default macros are:
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.