MACsec Configuration on Enterprise SONiC Switch
1 MACsec Encryption Overview
Media Access Control Security (MACsec) is a link-layer encryption technology standardized by IEEE 802.1AE, designed to provide data confidentiality, integrity, and replay protection over Ethernet links. In the Data Center Interconnect (DCI) context, MACsec establishes secure channels over physical or logical links between different data centers, effectively mitigating common threats such as man-in-the-middle attacks, eavesdropping, and replay attacks, thereby ensuring the security and trustworthiness of critical business data during cross-domain transmission. Learn More→
By deploying MACsec, organizations can achieve high-performance, low-latency encryption protection on inter-data center links, meeting the stringent data security requirements of industries such as finance, government, and telecommunications.
2 Configure MACsec and Status Commands
2.1 Enabling MACsec
Before accessing the MACsec and MKA commands, you must enable the MACsec feature globally.
Command | Purpose |
macsec enable | Enables MACsec |
2.2 Configuring a MACsec Profile
Configure the MKA policy (Connectivity Association, CA) and key information.
Command | Purpose |
macsec profile <profile_name> | Set name of this profile |
mka cipher_suite {GCM-AES-128|GCM-AES-256|GCM-AES-XPN-128|GCM-AES-XPN-256} | Set cryptographic authentication algorithm |
mka policy {integrity_only|security} | Configure the MKA (MACsec Key Agreement) policy, which defines the security level for the link integrity_only: In this mode, traffic is not encrypted, but it is protected by integrity checks to prevent tampering during transmission. Suitable for latency-sensitive environments where encryption is not required security: All MACsec-protected traffic will be encrypted and authenticated. This is suitable for networks that require data confidentiality |
mka priority <0-255> | Configures the key server priority to break the tie between peers during a key exchange. The range is from 0 (highest) and 255 (lowest), and the default value is 255 |
mka psk ckn <password-name> cak <password> | mka psk ckn <password-name> cak <password> <password>: shared key, format: prefix-less hexadecimal number; length: 32 bits for GCM-AES-128/GCM-AES-XPN-128 encryption, 64 bits for GCM-AES-256/GCM-AES-XPN-256 |
mka rekey_period <0-65535> | Configures the length of the key lifetime in seconds |
2.3 Configuring the MACsec Replay Protection Windows Size
Command | Purpose |
macsec profile <profile_name> | Enter the profile configuration view |
mka replay_protection enable | Enable the replay protection function |
mka replay_protection window_size <number> | If the degree of out-of-order delivery is less than or equal to the window size, the packets can be received correctly; if it exceeds the window size, the receiver will treat it as a replay attack and drop the packet |
2.4 Configuring MACsec on an Interface
Command | Purpose |
interface ethernet
<ID> | Enter the interface
configuration view |
macsec bind <profile_name> | Applying a MACsec
profile to an interface |
2.5 Display MACsec Status
Command | Purpose |
show macsec profile | Display all
configured MACsec profiles |
show macsec interface | Display the MACsec
profile applied to the interface |
3 Applications of MACsec
3.1 MACsec in DCI Scenarios
Data Center Interconnect (DCI) often leverages dark fiber infrastructure to establish high-capacity, low-latency physical links between geographically separated data centers. These dark fiber links provide exclusive, dedicated optical channels, minimizing exposure to external network segments. However, even on dark fiber, the risk of unauthorized physical access, fiber tapping, or insider threats still exists, posing confidentiality challenges for sensitive data traversing between data centers.

To address these confidentiality concerns, MACsec is increasingly adopted as an effective Layer 2 encryption and authentication solution within DCI deployments over dark fiber. MACsec provides per-frame encryption directly on Ethernet links, ensuring that all data transmitted between data centers remains confidential and tamper-proof.
By encrypting data at the data link layer, MACsec prevents unauthorized parties from eavesdropping or modifying inter-data center traffic—even if physical access to the fiber is compromised. Since MACsec operates transparently at Layer 2, it requires no changes to higher-layer protocols or applications, facilitating seamless integration into existing DCI architectures.
Moreover, MACsec’s low latency and wire-speed encryption capabilities align perfectly with the stringent performance requirements of DCI links, where high throughput and minimal delay are critical for workloads such as virtual machine migration, real-time data replication, and disaster recovery.
3.1.1 Configuration Example
3.1.1.1 Requirements
To secure data transmission between the two devices by MACsec, perform the following tasks on Switch A and Switch B, respectively:
- Enable MACsec replay protection and configure the replay protection window size to 100;
- Set the MACsec validation mode to strict;
- Set the Switch A as the MACsec Key Server.
3.1.1.2 Topology

3.1.1.3 Configuration Step
Switch A
#Enable MACsec function
sonic# configure
sonic(config)# macsec enable
# Create a MACsec profile
sonic(config)# macsec profile test
sonic(config-macsec-test)# mka cipher_suite GCM-AES-XPN-128
sonic(config-macsec-test)# mka policy security
sonic(config-macsec-test)# mka psk ckn 01000000000000000000000000000000 cak 50b71a8ef0bd5751ea76de6d6c98c03a
sonic(config-macsec-test)# mka priority 0
sonic(config-macsec-test)# mka rekey_period 28800
sonic(config-macsec-test)# mka replay_protection window_size 100
sonic(config-macsec-test)# exit
# Bind the MACsec profile to the interface
sonic(config)# interface ethernet 2
sonic(config-if-2)# ip address 10.0.10.1/30
sonic(config-if-2)# macsec bind test
sonic(config-if-2)# exit
sonic(config)# interface ethernet 1
sonic(config-if-1)# ip address 192.168.1.1/24
sonic(config-if-1)# exit
Switch B
# Enable MACsec function
sonic# configure
sonic(config)# macsec enable
# Create a MACsec profile with key information consistent with SwitchA.
sonic(config)# macsec profile test
sonic(config-macsec-test)# mka cipher_suite GCM-AES-XPN-128
sonic(config-macsec-test)# mka policy security
sonic(config-macsec-test)# mka psk ckn 01000000000000000000000000000000 cak 50b71a8ef0bd5751ea76de6d6c98c03a
sonic(config-macsec-test)# mka priority 10
sonic(config-macsec-test)# mka rekey_period 28800
sonic(config-macsec-test)# mka replay_protection window_size 100
sonic(config-macsec-test)# exit
# Bind the MACsec profile to the interface
sonic(config)# interface ethernet 2
sonic(config-if-2)# ip address 10.0.10.2/30
sonic(config-if-2)# macsec bind test
sonic(config-if-2)# exit
sonic(config)# interface ethernet 1
sonic(config-if-1)# ip address 192.168.2.1/24
sonic(config-if-1)# exit
Display MACsec Configuration information
# Display MACsec profile information
sonic# show macsec profile
Macsec Profile: test
Priority: 30
Cipher Suite : GCM-AES-XPN-128
Primary CAK : 01000000000000000000000000000000
Primary CKN : 50b71a8ef0bd5751ea76de6d6c98c03a
Policy : security
Replay Protect : true
Replay Window : 100
Rekey Period : 28800s
Send Sci : true
# Display the MACsec profile applied to the interface
sonic# show macsec interface
interface profile
Ethernet2 test
3.2 MACsec in 5G Front-haul Network Scenarios
In 5G front-haul networks, security is a critical concern due to the transmission of sensitive control, user, and management plane data between the centralized baseband unit (CU/DU) and remote radio units (RRUs). As 5G deployments increasingly adopt Ethernet-based transport (e.g., eCPRI), these front-haul links are exposed to potential threats such as eavesdropping, frame injection, and man-in-the-middle attacks — particularly when operating over shared or untrusted infrastructure.
C/U/M-Plane Vulnerabilities
If an attacker gains access to the Distributed Unit (DU) or Radio Unit (RU) — either via a man-in-the-middle (MITM) attack or direct physical access — they could impersonate a legitimate RU or DU and inject malicious control messages. This may disrupt the normal operation of upper-layer protocols, manipulate user data flows, or degrade service performance.
MACsec mitigates these risks by enforcing identity authentication through Connectivity Association Keys (CAKs). Only nodes that belong to the same Connectivity Association (CA) are allowed to transmit or receive Ethernet frames. Session Authentication Keys (SAKs), derived from the CAK, are used to encrypt Ethernet frames with strong cryptographic algorithms, ensuring that attackers cannot access payload data. Integrity checks further verify that received frames have not been altered, providing robust protection against injection or modification attacks. Additionally, MACsec leverages incremental Packet Numbers (PNs) within each Secure Association (SA) to track frame sequences, enabling detection of reordering, replay, or delayed transmissions.
S-Plane Vulnerabilities
The synchronization plane (S-plane) must meet stringent latency and timing accuracy requirements, with protocols such as ITU-T G.8275.1 PTP and Synchronous Ethernet. Even microsecond-level delays introduced by an attacker can severely disrupt services. Threats include impersonating grand master clocks, boundary clocks, or slave clocks, and injecting malicious or spoofed synchronization frames. Attackers can also delay, repeat, or offset sync messages, causing misalignment and network-wide timing disruption.
MACsec protects the S-plane by authenticating all participating nodes and encrypting frames to ensure integrity and confidentiality. Its low-latency encryption and replay protection prevent tampering and mitigate timing-based attacks, while implementations must carefully comply with the strict timing requirements to avoid introducing synchronization errors.

3.2.1 Configuration Example
3.2.1.1 Requirements
In a 5G fronthaul deployment, MACsec is implemented to secure all data planes while maintaining minimal latency.
- C/U-Plane uses GCM-AES-XPN-128
- S-Plane uses GCM-AES-128
- M-Plane uses GCM-AES-128
The switch operates as a Transparent Clock (TC) and adopts a two-step time synchronization mechanism to ensure high-precision timing.
3.2.1.1 Topology

4.2.1.3 Configuration Step
Switch A
# Create VLAN
sonic# configure
sonic(config)# vlan 10
sonic(config)# vlan 20
sonic(config)# vlan 30
sonic(config)# interface ethernet 1
sonic(config-if-1) switchport trunk vlan 10
sonic(config-if-1) switchport trunk vlan 20
sonic(config)# interface ethernet 2
sonic(config-if-2)# switchport access vlan 30
sonic(config)# interface ethernet 3
sonic(config-if-3)# switchport access vlan 10
sonic(config)# interface ethernet 4
sonic(config-if-4)# switchport access vlan 20
sonic(config)# interface ethernet 5
sonic(config-if-5)# switchport access vlan 30
# Enable MACsec function
sonic# configure
sonic(config)# macsec enable
sonic(config)# macsec profile cuplane
sonic(config-macsec-cuplane)# mka cipher_suite GCM-AES-XPN-128
sonic(config-macsec-cuplane)# mka policy security
sonic(config-macsec-cuplane)# mka priority 10
sonic(config-macsec-cuplane)# mka rekey_period 86400
sonic(config-macsec-cuplane)# mka send_sci enable
sonic(config-macsec-cuplane)# mka psk ckn 01234567890123456789012345678900 cak 3A9F2C5B1E4D8A76C0B1F3E25A8C7D4E
sonic(config)# macsec profile splane
sonic(config-macsec-splane)# mka cipher_suite GCM-AES-128
sonic(config-macsec-splane)# mka policy security
sonic(config-macsec-splane)# mka priority 10
sonic(config-macsec-splane)# mka rekey_period 300
sonic(config-macsec-splane)# mka send_sci enable
sonic(config-macsec-splane)# mka psk ckn 01234567890123456789012345678900 cak 9B7D1F0E8A3C6B5D4F2E1A9C7B0D5F3A
sonic(config)# macsec profile mplane
sonic(config-macsec-mplane)# mka cipher_suite GCM-AES-128
sonic(config-macsec-mplane)# mka policy security
sonic(config-macsec-mplane)# mka priority 10
sonic(config-macsec-mplane)# mka rekey_period 3600
sonic(config-macsec-mplane)# mka send_sci enable
sonic(config-macsec-mplane)# mka psk ckn 01234567890123456789012345678900 cak 50b71a8ef0bd5751ea76de6d6c98c03a
sonic(config)# interface ethernet 3
sonic(config-if-3) macsec bind cuplane
sonic(config)# interface ethernet 4
sonic(config-if-4) macsec bind splane
sonic(config)# interface ethernet 5
sonic(config-if-5) macsec bind mplane
# Enable PTP function
sonic(config)# ptp enable
sonic(config)# ptp instance 0
sonic(config-ptp-0)# ptp profile g8275.1
sonic(config-ptp-0)# ptp clock-type tc
sonic(config-ptp-0)# ptp clock-step twp_step
sonic(config-ptp-0)# ptp transport-mode ethernet
sonic(config-ptp-0)# ptp delay-mode e2e
sonic(config-ptp-0)# exit
sonic(config)# interface ethernet 2
sonic(config-if-2)# ptp instance 0
sonic(config-if-ptp-0)# ptp enable
sonic(config)# interface ethernet 5
sonic(config-if-5)# ptp instance 0
sonic(config-if-ptp-0)# ptp enable
Switch B
The configuration of Switch B is similar to that of Switch A and will not be elaborated here.
Display MACsec Configuration information
# Display MACsec profile information
sonic# show macsec profile cuplane
Macsec Profile: cuplane
Priority: 10
Cipher Suite : GCM-AES-XPN-128
Primary CAK : 01234567890123456789012345678900
Primary CKN : 3a9f2C5b1e4d8a76c0b1f3e25a8c7d4e
Policy : security
Replay Protect : true
Replay Window : 100
Rekey Period : 86400s
Send Sci : true
# Display the MACsec profile applied to the interface
sonic# show macsec interface
interface profile
Ethernet3 cuplane
Ethernet4 splane
Ethernet5 mplane