12 November 2026 · DMARC Engine · 11 min read
- Use IP address ranges to reduce updates
- Automate SPF record updates
- Utilise third-party services for management
- Regularly review aggregate reports
The Challenge of Dynamic IP Infrastructures
Domains with frequent IP changes pose a significant challenge for maintaining accurate SPF records. A common pattern is for organisations to utilise cloud services or content delivery networks (CDNs) that frequently rotate IP addresses, making it difficult to keep SPF records up to date. For example, a domain using Amazon Web Services (AWS) may have an SPF record that includes a large number of IP addresses, as shown in the following example:
v=spf1 include:_spf.amazonaws.com -allThis can lead to issues with SPF record size limits, as some DNS providers impose strict limits on the size of TXT records. Receivers typically enforce a 255-character limit for TXT records, which can be easily exceeded when including multiple IP addresses or subnets.
A list of strategies to mitigate this issue includes:
- utilising IP address ranges and CIDR notation to reduce the number of IP addresses included in the SPF record
- implementing automated SPF record updates to ensure that the record remains accurate and up to date
- using a third-party service to manage SPF records and handle IP address changes
import ipaddress
# example of using CIDR notation to reduce IP address range
ip_network = ipaddress.ip_network('192.0.2.0/24')
print(ip_network)
Warning: failing to maintain accurate SPF records can lead to email delivery issues, as receivers may reject emails that fail SPF checks. It is essential to carefully manage SPF records and implement strategies to mitigate the challenges posed by dynamic IP infrastructures.
Strategies for Maintaining Accurate SPF Records
A common pattern is for organisations to use third-party services, such as email marketing platforms or cloud-based email services, which can lead to frequent changes in the IP addresses used to send email. Receivers typically cache DNS records for a period of time, so any changes to the SPF record may not be immediately visible. The aggregate reports will show authentication failures due to outdated SPF records, highlighting the need for regular maintenance.
v=spf1 include:_spf.example.com ip4:192.0.2.1 ip4:198.51.100.1 -allThis example SPF record includes two IP addresses and an include statement for a subdomain. If the IP addresses change, the record needs to be updated to reflect this. A hosted or managed setup may provide tools to automate this process, but it is still crucial to understand the underlying mechanics.
For domains with frequent IP changes, using include statements can simplify the maintenance process. By including a subdomain that contains the IP addresses, changes can be made to the subdomain record without affecting the main domain's SPF record. This approach allows for more flexibility and reduces the risk of authentication failures due to outdated records.
v=spf1 include:_spf.example.com -allv=spf1 ip4:192.0.2.1 ip4:198.51.100.1In this example, the main domain's SPF record includes the subdomain _spf.example.com, which contains the IP addresses. Changes to the IP addresses can be made to the subdomain record, and the main domain's record remains unchanged.
A key consideration when maintaining SPF records is the DNS lookup limit. Receivers typically have a limit on the number of DNS lookups they will perform when evaluating an SPF record. Exceeding this limit can lead to authentication failures. Using include statements and keeping the number of IP addresses to a minimum can help mitigate this issue.
> Tip: Regularly review aggregate reports to identify any authentication failures due to outdated SPF records, and update the records accordingly to prevent future failures.
When implementing SPF record maintenance, it is essential to consider the trade-offs between security and complexity. A more complex SPF record with multiple include statements and IP addresses may provide greater flexibility but also increases the risk of errors and authentication failures. A simpler record with fewer IP addresses may be easier to maintain but may not provide the same level of security. Ultimately, the approach will depend on the specific requirements of the organisation and the email infrastructure in place.
Using IP Address Ranges and CIDR Notation
When dealing with domains that have frequent IP changes, using IP address ranges and CIDR notation in SPF records can be an effective way to simplify maintenance. This approach allows you to specify a range of IP addresses, rather than individual IPs, which can reduce the number of updates required to your SPF record. For example, if you have a mail server with a dynamic IP address that falls within the range 192.0.2.0/24, you can include this range in your SPF record using the following syntax:
v=spf1 ip4:192.0.2.0/24 -allThis record will match any IP address that falls within the specified range, which can help to reduce the administrative burden of maintaining your SPF record. However, it is essential to be cautious when using IP address ranges, as overly broad ranges can increase the risk of spam and abuse. A common pattern is to use smaller, more specific ranges to minimise this risk.
v=spf1 ip4:192.0.2.128/25 -allIn a hosted or managed setup, the process of updating SPF records to use IP address ranges and CIDR notation may vary. Some providers may offer automated tools or scripts to simplify this process, while others may require manual updates via a control panel or API.
> Tip: When using IP address ranges and CIDR notation, it is crucial to carefully plan and test your SPF record updates to avoid inadvertently blocking legitimate email traffic or leaving your domain vulnerable to spam and abuse.
Receivers typically handle SPF records with IP address ranges and CIDR notation in a standard way, according to the RFC. The aggregate reports will show the IP addresses that were tested against your SPF record, allowing you to monitor and troubleshoot any issues that may arise. By using IP address ranges and CIDR notation effectively, you can help to ensure the integrity and deliverability of your email traffic, even in the face of frequent IP changes.
Implementing Automated SPF Record Updates
To mitigate the issues associated with frequent IP changes, implementing automated SPF record updates is crucial. This can be achieved by utilising scripts or tools that monitor IP address changes and update the SPF record accordingly. For instance, a script can be written to query the IP addresses of mail servers at regular intervals and update the SPF record with the new IP addresses.
A common pattern is to use a combination of DNS management APIs and scripting languages, such as Python or Bash, to automate SPF record updates. The DNS management API can be used to retrieve the current SPF record and update it with new IP addresses.
v=spf1 ip4:192.0.2.1 ip4:198.51.100.1 -allIn a hosted or managed setup, the process of automated SPF record updates may vary. Some providers may offer automated SPF record management as part of their service, while others may require manual updates. It is essential to consult the provider's documentation to determine the best approach.
import dns.resolver
# Define the domain and SPF record
domain = 'example.com'
spf_record = 'v=spf1 ip4:192.0.2.1 ip4:198.51.100.1 -all'
# Update the SPF record using the DNS management API
def update_spf_record(new_ip_addresses):
# Retrieve the current SPF record
current_spf_record = dns.resolver.resolve(domain, 'TXT')
# Update the SPF record with new IP addresses
new_spf_record = 'v=spf1 '
for ip_address in new_ip_addresses:
new_spf_record += 'ip4:' + ip_address + ' '
new_spf_record += '-all'
# Update the SPF record using the DNS management API
# API call to update the SPF record
print('SPF record updated successfully')
> Tip: When implementing automated SPF record updates, it is crucial to ensure that the script or tool used can handle errors and exceptions properly, such as network connectivity issues or DNS resolution failures, to prevent unintended SPF record updates.
Lists of IP addresses can be maintained in various formats, such as text files or databases, to facilitate easy updates. The script or tool can then read the list of IP addresses and update the SPF record accordingly.
For example, a text file can be used to store the list of IP addresses:
192.0.2.1
198.51.100.1
203.0.113.1The script can then read the text file and update the SPF record with the new IP addresses.
The key to successful automated SPF record updates is to ensure that the script or tool used is reliable, efficient, and can handle errors and exceptions properly. By automating SPF record updates, domains with frequent IP changes can ensure that their SPF records remain accurate and up-to-date, reducing the risk of email delivery issues.
Monitoring and Troubleshooting with Aggregate Reports
Receivers typically send aggregate reports to the email address specified in the rua tag of a domain's DMARC record, which can be used to monitor and troubleshoot SPF record issues. A common pattern is for these reports to show authentication results for a domain, including SPF, DKIM, and DMARC alignment. The aggregate reports will show the number of messages that passed or failed SPF authentication, as well as the IP addresses that were used to send the messages.
For example, a domain with the following DMARC record:
_dmarc.example.com. IN TXT "v=DMARC1; p=none; rua=mailto:aggrep@example.com; ruf=mailto:forensics@example.com; fo=1"will receive aggregate reports at the aggrep@example.com email address. These reports can be used to identify IP addresses that are being used to send messages on behalf of the domain, but are not included in the domain's SPF record.
A list of common issues that can be identified using aggregate reports includes:
- IP addresses that are not included in the domain's SPF record
- IP addresses that are included in the SPF record, but are not authorised to send messages on behalf of the domain
- Messages that are being sent from IP addresses that are not aligned with the domain's DMARC policy
import xml.etree.ElementTree as ET
# parse the aggregate report XML
tree = ET.parse('aggregate_report.xml')
root = tree.getroot()
# extract the IP addresses that were used to send messages
ip_addresses = []
for record in root.findall('.//record'):
for row in record.findall('.//row'):
ip_address = row.find('source_ip').text
ip_addresses.append(ip_address)
# print the IP addresses
print(ip_addresses)
Warning: it is essential to monitor aggregate reports regularly, as they can provide critical information about the authenticity of messages sent on behalf of a domain. Failure to monitor these reports can lead to undetected SPF record issues, which can result in messages being blocked or marked as spam.
In a hosted or managed setup, the process of monitoring and troubleshooting with aggregate reports may be handled differently. For example, some hosted email providers may automatically parse and analyse aggregate reports, and provide a user-friendly interface for viewing the results. However, it is still important for domain owners to understand how to monitor and troubleshoot SPF record issues using aggregate reports, in order to ensure the authenticity and deliverability of their messages.
Trade-offs and Considerations for Large-Scale Deployments
When managing SPF records for domains with frequent IP changes in large-scale deployments, a common pattern is to utilise IP address ranges and CIDR notation to simplify record maintenance. For example, a domain may have an SPF record that includes a range of IP addresses, such as:
v=spf1 ip4:192.0.2.0/24 -allThis approach allows for easier management of IP addresses, as it eliminates the need to update the SPF record for every individual IP address change. However, receivers typically apply a lookup limit to DNS queries, which can lead to issues if the SPF record is too complex or includes too many IP address ranges.
A hosted or managed setup may handle this by automatically splitting the SPF record into multiple records, or by using a dedicated DNS service that can handle a high volume of queries.
v=spf1 include:_spf.example.com -allIn this example, the _spf.example.com record would contain the IP address ranges, allowing the domain owner to manage the records separately.
Warning: when using automated SPF record updates, it is crucial to ensure that the update process does not inadvertently introduce errors or inconsistencies in the record, which can lead to email delivery issues.
Best Practices for Minimising DNS Lookup Limits
To avoid exceeding DNS lookup limits, it is crucial to optimise SPF records, particularly for domains with frequent IP changes. A common pattern is to include multiple IP addresses in a single SPF record, which can lead to DNS lookup limits being reached quickly.
v=spf1 ip4:192.0.2.1 ip4:192.0.2.2 ip4:192.0.2.3 -all
Receivers typically enforce a limit of 10 DNS lookups per SPF record. To minimise the risk of exceeding this limit, it is recommended to use IP address ranges and CIDR notation where possible, as this reduces the number of lookups required.
v=spf1 ip4:192.0.2.0/24 -all
In a hosted or managed setup, the provider may handle SPF record maintenance, but it is still essential to understand the underlying mechanics to ensure optimal configuration.
> Tip: Regularly review and update SPF records to ensure they remain within the DNS lookup limit, and consider implementing automated updates to simplify the process.