diff --git a/server/model/monitor.js b/server/model/monitor.js index eaafb7755..fbc5d48a2 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -330,7 +330,7 @@ class Monitor extends BeanModel { let startTime = dayjs().valueOf(); let dnsMessage = ""; - let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.dns_resolve_type); + let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.port, this.dns_resolve_type); bean.ping = dayjs().valueOf() - startTime; if (this.dns_resolve_type === "A" || this.dns_resolve_type === "AAAA" || this.dns_resolve_type === "TXT") { diff --git a/server/util-server.js b/server/util-server.js index 54974e148..db7f525c7 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -176,12 +176,16 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) { * Resolves a given record using the specified DNS server * @param {string} hostname The hostname of the record to lookup * @param {string} resolverServer The DNS server to use + * @param {string} resolverPort Port the DNS server is listening on * @param {string} rrtype The type of record to request * @returns {Promise<(string[]|Object[]|Object)>} */ -exports.dnsResolve = function (hostname, resolverServer, rrtype) { +exports.dnsResolve = function (hostname, resolverServer, resolverPort, rrtype) { const resolver = new Resolver(); - resolver.setServers([ resolverServer ]); + // Remove brackets from IPv6 addresses so we can re-add them to + // prevent issues with ::1:5300 (::1 port 5300) + resolverServer = resolverServer.replace("[", "").replace("]", ""); + resolver.setServers([`[${resolverServer}]:${resolverPort}`]); return new Promise((resolve, reject) => { if (rrtype === "PTR") { resolver.reverse(hostname, (err, records) => { diff --git a/src/languages/en.js b/src/languages/en.js index af6ec32b3..d634e5456 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -13,6 +13,7 @@ export default { pauseDashboardHome: "Pause", deleteMonitorMsg: "Are you sure want to delete this monitor?", deleteNotificationMsg: "Are you sure want to delete this notification for all monitors?", + dnsPortDescription: "DNS server port. Defaults to 53. You can change the port at any time.", resolverserverDescription: "Cloudflare is the default server. You can change the resolver server anytime.", rrtypeDescription: "Select the RR type you want to monitor", pauseMonitorMsg: "Are you sure want to pause?", diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 9ae474ed1..1cb3684be 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -94,6 +94,15 @@ + +
+ + +
+ {{ $t("dnsPortDescription") }} +
+
+
@@ -469,6 +478,15 @@ export default { this.monitor.pushToken = genSecret(10); } } + + // Set default port for DNS if not already defined + if (! this.monitor.port || this.monitor.port === "53") { + if (this.monitor.type === "dns") { + this.monitor.port = "53"; + } else { + this.monitor.port = ""; + } + } } },