Cannot set the port security mode

Symptom

Cannot set the port security mode.

[Device-Ethernet1/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 a port operating in a port security mode other than noRestrictions, you cannot change the port security mode by using the port-security port-mode command directly.

Solution

Set the port security mode to noRestrictions first.

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