Cisco Switch Macros (2960S/X 3750,etc…)

Cisco has built in port macros where it will automatically assign specific commands to a port based on the macro you choose.

Below is a macro used often for a port with a PC/Laptop and Cisco IP Phone. I’m assigning an access VLAN 10 and a voice VLAN 20 to the macro.

int gig1/0/1
macro apply cisco-phone $access_vlan 10 $voice_vlan 20

You can change the default VLANs. Below are the defaults VLANs for this macro:

TPA-SW01# show macro auto device phone
Device:phone
Default Macro:CISCO_PHONE_AUTO_SMARTPORT
Current Macro:CISCO_PHONE_AUTO_SMARTPORT
Configurable Parameters:ACCESS_VLAN VOICE_VLAN
Defaults Parameters:ACCESS_VLAN=1 VOICE_VLAN=2
Current Parameters:ACCESS_VLAN=1 VOICE_VLAN=2

Here’s how you would change the defaults:

(config)macro auto device phone VOICE_VLAN=4
(config)macro auto device phone ACCESS_VLAN=4

Here’s the cisco-phone macro. You will see all the commands that the macro will configure:

TPA-SW01# show parser macro name cisco-phone

Macro name : cisco-phone
Macro type : default interface
# Cisco IP phone + desktop template

# macro keywords $access_vlan $voice_vlan

# VoIP enabled interface - Enable data VLAN
# and voice VLAN
# Recommended value for access vlan should not be 1
switchport access vlan $access_vlan
switchport mode access

# Update the Voice VLAN value which should be
# different from data VLAN
# Recommended value for voice vlan should not be 1
switchport voice vlan $voice_vlan

# Enable port security limiting port to a 2 MAC
# addressess -- One for desktop on data vlan and
# one for phone on voice vlan
switchport port-security
switchport port-security maximum 2

# Ensure port-security age is greater than one minute
# and use inactivity timer
switchport port-security violation restrict
switchport port-security aging time 2
switchport port-security aging type inactivity

# Enable auto-qos to extend trust to attached Cisco phone
auto qos voip cisco-phone

# Configure port as an edge network port
spanning-tree portfast
spanning-tree bpduguard enable

IMPORTANT:
You may get an error about your Service Policy NOT getting re-applied to the interface like the one below:

AutoQoS Error: ciscophone input service policy was not properly applied policy map AutoQoS-Police-CiscoPhone not configured

If this happens, enter the “no auto qos voip cisco-phone” interface command on ALL interface with this configuration to delete it. Then enter the “auto qos voip cisco-phone” command on each of these interfaces to reapply the configuration.