|
| 1 | +--- |
| 2 | +title: DNSMasq Integration |
| 3 | +impact: MEDIUM |
| 4 | +impactDescription: Running DNSMasq alongside NextDNS without proper configuration can result in loss of client reporting and conditional configuration features. This guidance ensures both services work together seamlessly while maintaining full NextDNS functionality. |
| 5 | +type: capability |
| 6 | +tags: dnsmasq, dns, router, client reporting, conditional configuration, port configuration, setup-router |
| 7 | +--- |
| 8 | + |
| 9 | +# DNSMasq Integration |
| 10 | + |
| 11 | +**Impact: MEDIUM** - Enables DNSMasq and NextDNS to run together while preserving client reporting and conditional configuration capabilities |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +DNSMasq is a lightweight DNS forwarder commonly bundled with router firmwares. It is possible to run DNSMasq and NextDNS together on the same system while maintaining full NextDNS functionality, including client reporting and conditional configuration features. |
| 16 | + |
| 17 | +This integration allows DNSMasq to continue handling local DNS resolution and DHCP services while forwarding external DNS queries to NextDNS for filtering and protection. |
| 18 | + |
| 19 | +## Configuration Steps |
| 20 | + |
| 21 | +### Step 1: Configure NextDNS to Listen on Alternative Port |
| 22 | + |
| 23 | +NextDNS must be configured to listen on a different port to avoid conflicts with DNSMasq, which typically uses port 53. |
| 24 | + |
| 25 | +```bash |
| 26 | +# Configure NextDNS to listen on port 5555 on localhost |
| 27 | +nextdns install -listen 127.0.0.1:5555 |
| 28 | +``` |
| 29 | + |
| 30 | +This configuration ensures NextDNS binds to port 5555 instead of the default port 53, allowing DNSMasq to continue operating on port 53. |
| 31 | + |
| 32 | +### Step 2: Configure DNSMasq to Forward to NextDNS |
| 33 | + |
| 34 | +Add the following parameters to your DNSMasq configuration to forward DNS queries to NextDNS while preserving client information: |
| 35 | + |
| 36 | +```conf |
| 37 | +# Forward DNS queries to NextDNS on port 5555 |
| 38 | +--server=127.0.0.1#5555 |
| 39 | +
|
| 40 | +# Include client MAC address in DNS queries |
| 41 | +--add-mac |
| 42 | +
|
| 43 | +# Include client subnet information (IPv4: /32, IPv6: /128) |
| 44 | +--add-subnet=32,128 |
| 45 | +``` |
| 46 | + |
| 47 | +These parameters ensure that: |
| 48 | + |
| 49 | +- `--server=127.0.0.1#5555`: All DNS queries are forwarded to NextDNS running on port 5555 |
| 50 | +- `--add-mac`: Client MAC addresses are included in DNS queries, enabling device identification |
| 51 | +- `--add-subnet=32,128`: Client subnet information is added for IPv4 (/32) and IPv6 (/128), supporting conditional configuration |
| 52 | + |
| 53 | +## Automatic Configuration for Router Firmwares |
| 54 | + |
| 55 | +On router firmwares that ship with DNSMasq pre-installed, the above configuration can often be handled automatically. |
| 56 | + |
| 57 | +When running NextDNS installation on such routers, use the `-setup-router` parameter: |
| 58 | + |
| 59 | +```bash |
| 60 | +# Automatic router setup (handles DNSMasq configuration) |
| 61 | +nextdns install -setup-router |
| 62 | +``` |
| 63 | + |
| 64 | +The `-setup-router` flag automatically detects DNSMasq and configures both services to work together without manual intervention. This is the recommended approach for router environments. |
| 65 | + |
| 66 | +## Best Practices |
| 67 | + |
| 68 | +- **Use alternative port**: Always configure NextDNS to use a non-standard port (e.g., 5555) when running alongside DNSMasq |
| 69 | +- **Preserve client information**: Ensure `--add-mac` and `--add-subnet` parameters are set to maintain client reporting features |
| 70 | +- **Prefer automatic setup**: On router firmwares, use `-setup-router` parameter for automatic configuration |
| 71 | +- **Verify forwarding**: Test DNS resolution after configuration to ensure queries are properly forwarded to NextDNS |
| 72 | +- **Check logs**: Monitor both DNSMasq and NextDNS logs to verify proper operation and client identification |
| 73 | + |
| 74 | +## Troubleshooting |
| 75 | + |
| 76 | +### Port Conflicts |
| 77 | + |
| 78 | +If you encounter port binding errors, verify that: |
| 79 | + |
| 80 | +- DNSMasq is running on port 53 |
| 81 | +- NextDNS is configured to use an alternative port (e.g., 5555) |
| 82 | +- No other services are using the chosen alternative port |
| 83 | + |
| 84 | +```bash |
| 85 | +# Check which service is using port 53 |
| 86 | +netstat -tulpn | grep :53 |
| 87 | + |
| 88 | +# Verify NextDNS is listening on the configured port |
| 89 | +netstat -tulpn | grep :5555 |
| 90 | +``` |
| 91 | + |
| 92 | +### Client Reporting Not Working |
| 93 | + |
| 94 | +If client devices are not appearing correctly in NextDNS analytics: |
| 95 | + |
| 96 | +- Verify `--add-mac` parameter is enabled in DNSMasq configuration |
| 97 | +- Check that `--add-subnet` parameter is properly configured |
| 98 | +- Ensure DNS queries are being forwarded to NextDNS (check DNSMasq logs) |
| 99 | + |
| 100 | +### Router Firmware Issues |
| 101 | + |
| 102 | +If `-setup-router` fails or doesn't configure properly: |
| 103 | + |
| 104 | +- Fall back to manual configuration using Steps 1 and 2 |
| 105 | +- Check router firmware documentation for DNSMasq configuration location |
| 106 | +- Ensure you have appropriate permissions to modify DNSMasq configuration |
| 107 | + |
| 108 | +## Reference |
| 109 | + |
| 110 | +- [NextDNS CLI Wiki](https://github.com/nextdns/nextdns/wiki) |
| 111 | +- [DNSMasq Documentation](https://thekelleys.org.uk/dnsmasq/doc.html) |
| 112 | +- [NextDNS Setup Guide](https://help.nextdns.io) |
0 commit comments