---
title: Port Security
slug: enterprise-v6p1/port-security
createdAt: 2025-12-04T07:39:15.587Z
---

## <font color="#1d50a2">Port Security</font>

### <font color="#1d50a2">show port-security</font>

**\[Command]**
**show** **port-security \[\{ethernet|link-aggregation}]** \[*interface\_num|lag\_id*]

**\[Purpose]**
Display Port Security configuration

**\[Parameter]**

| **Parameter**    | **Description**                  |
| ---------------- | -------------------------------- |
| *interface\_num* | Ethernet name                    |
| *lag\_id*        | Aggregate group id, range 1-9999 |

**\[View]**
System view

```text
sonic# show port-security
Interface  Port-Security Sticky-Mac Max-Secure-Addr Violation-Action
--------------- --------------- --------------- --------------------- ------------------
Ethernet1    enable  enable  1       restrict
PortChannel0020 enable  enable  1       restrict
```

### <font color="#1d50a2">show port-security address</font>

**\[Command]**
**show port-security address \[\{ethernet|link-aggregation}]** \[*interface\_num|lag\_id*]

**\[Purpose]**
Display specific security MAC information

**\[Parameter]**

| **Parameter**    | **Description**                  |
| ---------------- | -------------------------------- |
| *interface\_num* | Ethernet name                    |
| *lag\_id*        | Aggregate group id, range 1-9999 |

**\[View]**
System view

```text
sonic# show port-security address ethernet 1
No.      VLAN          MAC Address                Port         Type
----- ---------- ------------------------- ------------- ------
1          Vlan100     00:00:01:02:03:04         Ethernet1     static
Total number of entries 1
```

###

**\[Command]**
**port-security enable**
**no port-security enable**

**\[Purpose]**
Enable port security function

**\[View]**
Interface view

**\[Comment]**
Before enabling port security, you need to add the interface to a VLAN first.

```text
sonic# configure        
sonic(config)# interface ethernet 1
sonic(config-if-1)# port-security enable
```

### <font color="#1d50a2">port-security address</font>

**\[Command]**
**port-security address** *nn\:nn\:nn\:nn\:nn*:nn **vlan** *vlan\_id*
**no port-security address** *nn\:nn\:nn\:nn\:nn*:nn **vlan** *vlan\_id*

**\[Purpose]**
Configure static security MAC address

**\[View]**
Interface view

**\[Comment]**
Before configuring a static security MAC address, you need to enable the port security function first.

```text
sonic# configure
sonic(config)# interface ethernet 1
sonic(config-if-1)# port-security address 00:00:01:02:03:05 vlan 100
```

### <font color="#1d50a2">port-security maximum</font>

**\[Command]**
**port-security maximum** *max\_num*
**no port-security maximum**

**\[Purpose]**
Configure the maximum limit of secure MAC addresses for the interface. The default value is 1. Static secure MAC addresses, dynamic secure MAC addresses, and sticky MAC addresses share this maximum limit.

**\[Parameter]**

| **Parameter** | **Description**                                                                |
| ------------- | ------------------------------------------------------------------------------ |
| *max\_num*    | The maximum number of interface security MAC addresses, ranging from 1 to 1024 |

**\[View]**
Interface view

```text
sonic# configure
sonic(config)# interface ethernet 1
sonic(config-if-1)# port-security maximum 10
```

### <font color="#1d50a2">port-security sticky</font>

**\[Command]**
**port-security sticky**
**no port-security sticky**

**\[Purpose]**
Enable sticky mac function

**\[View]**
Interface view

```text
sonic# configure
sonic(config)# interface ethernet 1
sonic(config-if-1)# port-security sticky
```

### <font color="#1d50a2">port-security violation</font>

**\[Command]**
**port-security violation \{protect|restrict|shutdown}**
**no port-security violation**

**\[Purpose]**
Configure security MAC protection actions. When the number of security MAC addresses reaches the set maximum, the default protection action is "restrict".

**\[Parameter]**

| **Parameter** | **Description**                                                                 |
| ------------- | ------------------------------------------------------------------------------- |
| protect       | Discard packets with source addresses not in the MAC table.                     |
| restrict      | Discard packets with source addresses not in the MAC table and issues an alert. |
| shutdown      | The interface performs a shutdown operation and issues an alert.                |

**\[View]**
Interface view

```text
sonic# configure
sonic(config)# interface ethernet 1
sonic(config-if-1)# port-security violation protect
```

### <font color="#1d50a2">clear port-security address</font>

**\[Command]**
**clear port-security address** **\[ethernet|link-aggregation]** \[*interface\_num|lag\_id*]
**clear port-security address \[static|dynamic|sticky]**

**\[Purpose]**
Delete entries from the security MAC table

**\[Parameter]**

| **Parameter**    | **Description**                  |
| ---------------- | -------------------------------- |
| *interface\_num* | Ethernet name                    |
| *lag\_id*        | Aggregate group id, range 1-9999 |
| static           | Static security MAC address      |
| dynamic          | Dynamic security MAC address     |
| sticky           | Sticky security MAC address      |

**\[View]**
System view

```text
sonic# clear port-security address
```

###

**\[Command]**
**mac-learning priority \{low|high}**
**no mac-learning priority**

**\[Purpose]**
Configure the learning priority for mac. The default is low. FDBs learned from high-priority interfaces are not allowed to drift to low-priority interfaces; FDBs learned from low-priority interfaces are allowed to drift to high-priority interfaces.

**\[View]**
Interface view

```text
sonic# configure 
sonic(config)# interface ethernet 1
sonic(config-if-1)# mac-learning priority high
```

### <font color="#1d50a2">mac-learning group</font>

**\[Command]**
**mac-learning group** *group\_id*
**no mac-learning group**

**\[Purpose]**
Configure MAC learning groups, allowing MAC migration between interfaces within the same learning group.

**\[Parameter]**

| **Parameter** | **Description**                                |
| ------------- | ---------------------------------------------- |
| *group\_id*   | Mac learning group name, range 0-15, default 0 |

**\[View]**
Interface view

```text
sonic# configure 
sonic(config)# interface ethernet 1
sonic(config-if-1)# mac-learning group 10
```

### <font color="#1d50a2">show mac-learning priority</font>

**\[Command]**
**show mac-learning priority \[\{ethernet|link-aggregation}]** \[*interface\_num|lag\_id*]

**\[Purpose]**
Displays MAC learning priority configuration.

**\[Parameter]**

| **Parameter**    | **Description**                  |
| ---------------- | -------------------------------- |
| *interface\_num* | Ethernet name                    |
| *lag\_id*        | Aggregate group id, range 1-9999 |

**\[View]**
System view

```text
sonic# show mac-learning priority ethernet 5
Interface  Priority
-------------  ----------
Ethernet5  low
```

### <font color="#1d50a2">show mac-learning group</font>

**\[Command]**
**show mac-learning group \[\{ethernet|link-aggregation}]** \[*interface\_num|lag\_id*]

**\[Purpose]**
Displays MAC learning group configuration.

**\[Parameter]**

| **Parameter**    | **Description**                  |
| ---------------- | -------------------------------- |
| *interface\_num* | Ethernet name                    |
| *lag\_id*        | Aggregate group id, range 1-9999 |

**\[View]**
System view

```text
sonic# show mac-learning group ethernet 6
Interface   Group-Id
----------- ----------
Ethernet6       0
```

