Cannot set the port security mode

Symptom

Cannot set the port security mode.

[Device-GigabitEthernet1/0/1] port-security port-mode autolearn
 Error:When we change port-mode, we should first change it to noRestrictions, then change it to the other.

Analysis

For ports operating in a port security mode other than noRestrictions, you cannot change the port security mode directly by using the port-security port-mode command.

Solution

First set the port security mode to noRestrictions.

[Device-GigabitEthernet1/0/1] undo port-security port-mode
[Device-GigabitEthernet1/0/1] port-security port-mode autolearn