A Python script to bulk create static DNS records in UniFi Network using the API. Works with UDM, UDM Pro, and UDM SE running UniFi OS.
- 🚀 Bulk create DNS records from CSV file
- 🔒 Secure API token authentication (no password storage)
- ✅ Support for A and CNAME records
- 🎯 Configurable TTL and enable/disable status
- 🐛 Optional debug mode for troubleshooting
- 💯 Rate limiting to avoid API throttling
This script updates the DNS Records policy in UniFi Network, allowing you to:
- Add records for external networks: Create DNS entries for clients not managed by your UniFi console (e.g., devices on external networks, VPN clients, remote sites)
- Create aliases: Add CNAME records to create easy-to-remember aliases for existing hosts
- Bulk management: Import dozens or hundreds of DNS records at once instead of adding them manually one by one through the UI
View your DNS records in the UniFi Console at:
https://<your-unifi-controller-ip>/network/default/settings/policy-table?preset=dns-records
(Replace <your-unifi-controller-ip> with your controller's IP address)
- Python 3.6+
- UniFi Dream Machine (UDM), UDM Pro, or UDM SE with UniFi OS
- API Token from UniFi Console
- Clone this repository:
git clone https://github.com/denisvinciguerra/unifi-bulk-dns.git
cd unifi-bulk-dns- Install dependencies:
pip install -r requirements.txt- Log in to your UniFi OS Console
- Navigate to Settings → Admins
- Click Create API Token
- Copy the generated token (you'll need it when running the script)
python unifi_bulk_create_dns_records.py dns_records.csvThe script will prompt you for your API token securely (input won't be displayed).
# Custom UDM IP address
python unifi_bulk_create_dns_records.py dns_records.csv --udm-ip 192.168.1.254
# Custom site name
python unifi_bulk_create_dns_records.py dns_records.csv --site custom_site
# Enable debug output
python unifi_bulk_create_dns_records.py dns_records.csv --debugCreate a CSV file with the following columns:
key,value,record_type,ttl,enabled
nas.home.lan,192.168.1.10,A,3600,true
plex.home.lan,nas.home.lan,CNAME,0,true
backup.home.lan,192.168.1.20,A,3600,true
media.home.lan,192.168.1.30,A,3600,falseColumns:
key: DNS hostname (FQDN)value: IP address (for A records) or target hostname (for CNAME records)record_type: Record type (AorCNAME)ttl: Time to live in seconds (use0for default)enabled:trueorfalseto enable/disable the record
See example.csv for a complete example.
If you get a 403 error, make sure:
- Your API token is valid and hasn't expired
- Your account has admin permissions
- You're using an API token (not username/password authentication)
- Verify your UDM IP address is correct
- Ensure you can access the UniFi Console from your computer
- Check that port 443 is accessible
Run with --debug flag to see detailed information:
python unifi_bulk_create_dns_records.py dns_records.csv --debugThis script uses the UniFi Network v2 API:
- Endpoint:
/proxy/network/v2/api/site/{site}/static-dns - Authentication: API Token via
X-API-Keyheader - Method: POST for creating records
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - See LICENSE file for details
This script is not officially supported by Ubiquiti Networks. Use at your own risk.
This project was developed with assistance from Claude (Anthropic AI). The initial concept, requirements, and testing were done by the maintainer, with AI assistance for code structure, error handling, and documentation.
Created by @denisvinciguerra