I have two Pi-Hole instances deployed in my home network. One IP address is used for the DNS server using the VRRP protocol. Both instances synchronized with each other. But, if the hardware servers are unavailable or virtualization fails, the DNS will be Mikrotik, which is also part of this VRRP group.
The script solves one task - exporting local DNS records from Pi-Hole to Mikrotik ROS 7.x
A huge thank you to https://github.com/netspeedy for the static record synchronization script!
!!! Script works only with Pi-Hole 5.x !!!
First - edit creditionals in config.ini
Second -
chmod +x update.sh
Third - Just run
./update.sh
crontab -e
0 * * * * /bin/bash /opt/MiPiSync/update.sh
[+] Converter.sh by NoID
Conert stanart Pi-Hole Local DNS List to config.ini format MikroTik-Static-DNS-Syncronizer.
Source code https://github.com/netspeedy/MikroTik-Static-DNS-Synchronizer
[!] File config.head must be exist and contains creditional data like this:
[Router]
address = <Router IP address>
username = <Router username>
password = <Router password>
[DNSRecords][!] Usage:
./converter.sh [domain-list-file] [output-file]
https://github.com/netspeedy/MikroTik-Static-DNS-Synchronizer
MikroTik Static DNS Synchronizer is a Python script designed to automate the synchronization of static DNS entries between a configuration file (config.ini) and a MikroTik router. It supports both CNAME and A record types and ensures that your MikroTik router's DNS entries reflect the latest configuration defined in the config.ini file.
- Two-way Synchronization: Adds new DNS entries from
config.inito the router and deletes entries from the router that are missing inconfig.ini. - Supports CNAME and A Records: Automatically identifies and handles CNAME (domain name) and A (IP address) record types.
- Debugging Mode: Provides optional debugging output for detailed insight into synchronization actions.
- Clear Summary: Displays a summary after synchronization, showing added and deleted records.
The script operates in the following steps:
- Load Configuration: Reads the
config.inifile for router connection details (address,username,password) and DNS records to synchronize. - Retrieve Existing Records: Queries the MikroTik router for existing static DNS records.
- Synchronize Records:
- Add New Records: Adds DNS records from
config.inithat are not present on the router. - Delete Missing Records: Deletes DNS records from the router that are not defined in
config.ini. - Update Changed Records: Updates IP addresses or CNAMEs for existing records if they have changed in
config.ini.
- Add New Records: Adds DNS records from
- Summary: Prints a summary of added and deleted records after synchronization.
- Python 3.x installed on your system.
requestslibrary for Python. Install it using:
Create a config.ini file in the script's directory with the following structure:
[Router]
address = <Router IP address>
username = <Router username>
password = <Router password>
[DNSRecords]
<hostname> = <IP address or CNAME>To specify multiple IP addresses for Round Robin DNS (RRDNS) or dual stacked IPv4 and IPv6 records, use comma-separated values.
Replace < Router IP address > < Router username > and < Router password > with your MikroTik router's details. Add DNS records under [DNSRecords] section where < hostname > is the DNS hostname and < IP address(es) or CNAME > is the corresponding IP address or CNAME.
Example config.ini:
[Router]
address = 192.168.88.1
username = autodns
password = dnsrocks
[DNSRecords]
ns.example.com = 198.51.100.1, 203.0.113.1, 2001:DB8::1
v6.example.com = 2001:DB8::2
myrecord.example.com = router.example.com
Run the script using Python:
python3 mikrotik-dns-sync.py --address <Router IP> --user <Router username> --password <Router password>
Alternatively, you can set these parameters directly in the script or use environment variables:
MIKROTIK_ADDRESS: Router IP address
MIKROTIK_USER: Router username
MIKROTIK_PASS: Router password
Enable debug mode to see detailed logging of synchronization actions:
python3 mikrotik-dns-sync.py --address <Router IP> --user <Router username> --password <Router password> --debug
Contributions are welcome! Fork the repository, make your changes, and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.