Add DMARC to all domains except existing records and external MX

Richard G

Verified User
Joined
Jul 6, 2008
Messages
14,705
Location
Maastricht
It seems that both Google and Yahoo now require a DMARC record by default for mass mailing by februari 2024 (>5000 mails).

Now our customers do not use mass mailing as far as I now, but it's better to be prepared, than to run behind the facts.
So jus to be sure I want to add them everywhere -except- for domains which already have a DMARC record!

Now for new domains I can create a custom dns template called dns_txt.conf and add a DMARC line in there, shouldn't be that difficult.

However, I also need to add this DMARC record with only p=none (which is sufficient) to all existing domains, but except domains with external MX present and except domains which already have a DMARC record present. Because I most certainly wouldn't like to overwrite some users well setup DMARC settings.

I found some script to put in an A record, which I have used once for imap, which was not present anywhere in DNS. But there was no example in the docs as to how to do this with a DMARC record and exclude the ones that I want exclusion for.

But I'm no scripter and now I need a script or some way to fix this.

So how can I do this?
 
I just played with chatgpt a little. Now I know this is an old post but I just wanted it here for the record. I used this which seems to work as it skips zones/domains that have dmarc already:

for ZONE in /var/named/*.db; do
if ! grep -qi "_dmarc" "$ZONE"; then
echo "_dmarc 3600 IN TXT \"v=DMARC1; p=reject; sp=none;\"" >> "$ZONE"
echo "[ADD ] DMARC added to $(basename "$ZONE" .db)"
else
echo "[SKIP] DMARC already exists for $(basename "$ZONE" .db)"
fi
done

# Reload DNS to apply changes
echo "action=restart&value=named" >> /usr/local/directadmin/data/task.queue
/usr/local/directadmin/dataskq d2000

Tested it using DMARC tester on mxtoolbox.com and the result as per below:

dmarc.png
 
Last edited:
Back
Top