Allow MAC addresses to be added to multiple interfaces #10792

Closed
opened 2025-12-29 21:35:59 +01:00 by adam · 4 comments
Owner

Originally created by @leomarssilva on GitHub (Feb 21, 2025).

NetBox version

v4.2.3

Feature type

Change to existing functionality

Proposed functionality

Before the https://github.com/netbox-community/netbox/issues/4867 change, multiple interfaces can have the same MAC address - an example attached on https://github.com/netbox-community/netbox/issues/18689. To add this feature we need to change MACAddress model's relation with the Interface model to many-to-many. Also, the create/edit screens for MACAddress need to allow multiple selection.

Use case

This is required by devices where multiple physical interfaces can have the same MAC addresses, such as some switches and devices with floating MAC addresses. An example is available on https://github.com/netbox-community/netbox/discussions/7706

Database changes

Change MACAddress model's relation with the Interface model to many-to-many

External dependencies

None needed

Originally created by @leomarssilva on GitHub (Feb 21, 2025). ### NetBox version v4.2.3 ### Feature type Change to existing functionality ### Proposed functionality Before the https://github.com/netbox-community/netbox/issues/4867 change, multiple interfaces can have the same MAC address - an example attached on https://github.com/netbox-community/netbox/issues/18689. To add this feature we need to change `MACAddress` model's relation with the `Interface` model to many-to-many. Also, the create/edit screens for MACAddress need to allow multiple selection. ### Use case This is required by devices where multiple physical interfaces can have the same MAC addresses, such as some switches and devices with floating MAC addresses. An example is available on https://github.com/netbox-community/netbox/discussions/7706 ### Database changes Change MACAddress model's relation with the Interface model to many-to-many ### External dependencies None needed
adam added the type: feature label 2025-12-29 21:35:59 +01:00
adam closed this issue 2025-12-29 21:36:00 +01:00
Author
Owner

@ITJamie commented on GitHub (Feb 21, 2025):

Would allowing duplicates (similar to how ips with the VIP or Anycast) be a better path forward?

@ITJamie commented on GitHub (Feb 21, 2025): Would allowing duplicates (similar to how ips with the VIP or Anycast) be a better path forward?
Author
Owner

@leomarssilva commented on GitHub (Feb 24, 2025):

Hi @ITJamie! You mean multiple MACAddress rows with the same address linked to the interfaces, right? I'll check tomorrow. If it's a simpler solution then I think it would be good.

I'm open to suggestions since this MAC change broke the network infrastructure setup I had on Netbox :)

@leomarssilva commented on GitHub (Feb 24, 2025): Hi @ITJamie! You mean multiple MACAddress rows with the same address linked to the interfaces, right? I'll check tomorrow. If it's a simpler solution then I think it would be good. I'm open to suggestions since this MAC change broke the network infrastructure setup I had on Netbox :)
Author
Owner

@sleepinggenius2 commented on GitHub (Feb 24, 2025):

Duplicates are already allowed. There is no uniqueness constraint on the mac_address field of the MACAddress model. That was an intentional design consideration made when this change was implemented. We have many devices in our network that share the same MAC address across multiple interfaces, so we just have a separate MACAddress object associated with each individual interface that captures that interface's primary MAC address, whether it is a duplicate or not. This is exactly what the migration does as well, if you upgrade from a pre-v4.2 release.

@sleepinggenius2 commented on GitHub (Feb 24, 2025): Duplicates are already allowed. There is no uniqueness constraint on the `mac_address` field of the `MACAddress` model. That was an intentional design consideration made when this change was implemented. We have many devices in our network that share the same MAC address across multiple interfaces, so we just have a separate `MACAddress` object associated with each individual interface that captures that interface's primary MAC address, whether it is a duplicate or not. This is exactly what the migration does as well, if you upgrade from a pre-v4.2 release.
Author
Owner

@leomarssilva commented on GitHub (Feb 25, 2025):

Hi @ sleepinggenius2, you are absolute right! Somehow I confused the MACAddress source with another model and thought there is an unique constraint somewhere. Also, my implementation was throwing exceptions due to a get_or_create that searched for existing MACAddresses... I guess that's a sign to drink less coffee, or more 🤦🏻‍♂️

Thank you all for the replies and insights!

@leomarssilva commented on GitHub (Feb 25, 2025): Hi @ sleepinggenius2, you are absolute right! Somehow I confused the `MACAddress` source with another model and thought there is an unique constraint somewhere. Also, my implementation was throwing exceptions due to a `get_or_create` that searched for existing MACAddresses... I guess that's a sign to drink less coffee, or more 🤦🏻‍♂️ Thank you all for the replies and insights!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10792