Remove subnet mask from IP Addresses #9053

Closed
opened 2025-12-29 20:44:50 +01:00 by adam · 6 comments
Owner

Originally created by @llamafilm on GitHub (Jan 7, 2024).

NetBox version

v3.7.0

Feature type

Change to existing functionality

Proposed functionality

Currently the subnet mask length is an attribute of each IP address. I think it would make more sense for this to be an attribute of the prefix instead. I propose these changes:

  • Add a mandatory "parent prefix" field for IP addresses. This means you must create the Prefix before creating a new IP Address.
  • IP addresses are always entered in dotted notation without mask (e.g. 10.1.2.3)
  • Add a user preference to display IP addresses in CIDR notation based on its parent prefix. (I would never use this, I just mention it to avoid breaking anyone's workflow.) Otherwise they will be displayed in dotted notation.
  • A one-time upgrade script modifies all existing addresses and creates any missing prefixes.

Use case

The current model is redundant, and there is a risk that users enter the wrong mask length when creating a new IP Address, as described here: https://github.com/netbox-community/netbox/discussions/8731#discussioncomment-2242315.
One way to avoid this risk is by instructing users to always use /32, which effectively makes that mask_length attribute useless, so in that case you would still need to refer to the IP Prefix to find it.
Moving the mask length to be an attribute of the Prefix would reduce the operational burden for data entry, and it would align better with the single source of truth concept. As a general rule, all IP addresses under the same parent prefix should share the same same mask length. I can't think of any exceptions to that.
This would also make it easier on the eyes when looking at big lists of addresses

Database changes

My best guess, not knowing Netbox very well:

  • add mandatory prefix_id field to ipam_ipaddress

External dependencies

none

Originally created by @llamafilm on GitHub (Jan 7, 2024). ### NetBox version v3.7.0 ### Feature type Change to existing functionality ### Proposed functionality Currently the subnet mask length is an attribute of each IP address. I think it would make more sense for this to be an attribute of the prefix instead. I propose these changes: - Add a mandatory "parent prefix" field for IP addresses. This means you must create the Prefix before creating a new IP Address. - IP addresses are always entered in dotted notation without mask (e.g. `10.1.2.3`) - Add a user preference to display IP addresses in CIDR notation based on its parent prefix. (I would never use this, I just mention it to avoid breaking anyone's workflow.) Otherwise they will be displayed in dotted notation. - A one-time upgrade script modifies all existing addresses and creates any missing prefixes. ### Use case The current model is redundant, and there is a risk that users enter the wrong mask length when creating a new IP Address, as described here: https://github.com/netbox-community/netbox/discussions/8731#discussioncomment-2242315. One way to avoid this risk is by instructing users to always use `/32`, which effectively makes that mask_length attribute useless, so in that case you would still need to refer to the IP Prefix to find it. Moving the mask length to be an attribute of the Prefix would reduce the operational burden for data entry, and it would align better with the _single source of truth_ concept. As a general rule, all IP addresses under the same parent prefix should share the same same mask length. I can't think of any exceptions to that. This would also make it easier on the eyes when looking at big lists of addresses ### Database changes My best guess, not knowing Netbox very well: - add mandatory `prefix_id` field to `ipam_ipaddress` ### External dependencies none
adam added the type: feature label 2025-12-29 20:44:50 +01:00
adam closed this issue 2025-12-29 20:44:50 +01:00
Author
Owner

@llamafilm commented on GitHub (Jan 7, 2024):

It's already possible to create an IP Address with no mask, and if you do this, Netbox automatically turns it into a /32 for display. Example from nbshell:

>>> ip = IPAddress(address='192.168.5.1')
>>> ip.save()
>>> IPAddress.objects.last()
<IPAddress: 192.168.5.1/32>

The Postgres data is stored like this:

netbox=> SELECT address FROM ipam_ipaddress ORDER BY id DESC LIMIT 2;
     address     
-----------------
 192.168.5.1
 10.37.163.37/24

Apparently the mask requirement is only here in the GUI form:
c78a792ccc/netbox/ipam/formfields.py (L53-L56)

@llamafilm commented on GitHub (Jan 7, 2024): It's already possible to create an IP Address with no mask, and if you do this, Netbox automatically turns it into a /32 for display. Example from `nbshell`: ```py >>> ip = IPAddress(address='192.168.5.1') >>> ip.save() >>> IPAddress.objects.last() <IPAddress: 192.168.5.1/32> ``` The Postgres data is stored like this: ```sql netbox=> SELECT address FROM ipam_ipaddress ORDER BY id DESC LIMIT 2; address ----------------- 192.168.5.1 10.37.163.37/24 ``` Apparently the mask requirement is only here in the GUI form: https://github.com/netbox-community/netbox/blob/c78a792cccfdbe6f373c0d474b1620e56e5f9cf8/netbox/ipam/formfields.py#L53-L56
Author
Owner

@kkthxbye-code commented on GitHub (Jan 7, 2024):

It's already possible to create an IP Address with no mask, and if you do this, Netbox automatically turns it into a /32 for display. Example from nbshell:

>>> ip = IPAddress(address='192.168.5.1')
>>> ip.save()
>>> IPAddress.objects.last()
<IPAddress: 192.168.5.1/32>

You have to call full_clean() on the object before saving, otherwise no validation is executed.

@kkthxbye-code commented on GitHub (Jan 7, 2024): > It's already possible to create an IP Address with no mask, and if you do this, Netbox automatically turns it into a /32 for display. Example from `nbshell`: > > ```python > >>> ip = IPAddress(address='192.168.5.1') > >>> ip.save() > >>> IPAddress.objects.last() > <IPAddress: 192.168.5.1/32> > ``` You have to call full_clean() on the object before saving, otherwise no validation is executed.
Author
Owner

@llamafilm commented on GitHub (Jan 7, 2024):

otherwise no validation is executed.

@kkthxbye-code I don't think that's accurate. See my other question #14718.

Anyway, in this example, full_clean does not make any difference, it still passes validation.

@llamafilm commented on GitHub (Jan 7, 2024): > otherwise no validation is executed. @kkthxbye-code I don't think that's accurate. See my other question #14718. Anyway, in this example, full_clean does not make any difference, it still passes validation.
Author
Owner

@kkthxbye-code commented on GitHub (Jan 7, 2024):

Anyway, in this example, full_clean does not make any difference, it still passes validation.

Regardless, being able to do something in nbshell has no bearing on how netbox is designed and as such should not be used as arguments in feature requests. nbshell and custom scripts are "power user" features, and requires knowledge of django to use.

@kkthxbye-code commented on GitHub (Jan 7, 2024): > Anyway, in this example, full_clean does not make any difference, it still passes validation. Regardless, being able to do something in nbshell has no bearing on how netbox is designed and as such should not be used as arguments in feature requests. nbshell and custom scripts are "power user" features, and requires knowledge of django to use.
Author
Owner

@ITJamie commented on GitHub (Jan 8, 2024):

this feels like it would be dependent on https://github.com/netbox-community/netbox/issues/7845

@ITJamie commented on GitHub (Jan 8, 2024): this feels like it would be dependent on https://github.com/netbox-community/netbox/issues/7845
Author
Owner

@jeremystretch commented on GitHub (Jan 8, 2024):

Netbox automatically turns it into a /32 for display.

Which is a subnet mask, albeit likely not the correct one for the IP address.

This discussion has run its course and we will not be making any changes.

@jeremystretch commented on GitHub (Jan 8, 2024): > Netbox automatically turns it into a /32 for display. Which is a subnet mask, albeit likely not the correct one for the IP address. This discussion has run its course and we will not be making any changes.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9053