Score:-2

Unable to change TTL value on local DNS Ubuntu 18.04

de flag

I have configured local dns with mailserver, while checking the dns using dig default ttl is always 0.

How can i set TTL 60 ? Can you please advise me ?

root@mx:/etc/bind# uname -a
Linux mx.mailserver.local 4.15.0-147-generic #151-Ubuntu SMP Fri Jun 18 19:21:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
root@mx:/etc/bind# dig localhost

; <<>> DiG 9.11.3-1ubuntu1.15-Ubuntu <<>> localhost
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 886
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;localhost.                     IN      A

;; ANSWER SECTION:
localhost.              **0**       IN      A       127.0.0.1

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Aug 10 15:06:14 IST 2021
;; MSG SIZE  rcvd: 54
root@mx:/etc/bind# dig mx.mailserver.local

; <<>> DiG 9.11.3-1ubuntu1.15-Ubuntu <<>> mx.mailserver.local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55910
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;mx.mailserver.local.             IN      A

;; ANSWER SECTION:

mx.mailserver.local.      **0**       IN      A       192.168.1.55

mx.mailserver.local.      **0**       IN      A       192.168.1.66

mx.mailserver.local.      **0**       IN      A       192.168.1.77

mx.mailserver.local.      **0**       IN      A       192.168.1.88


;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Aug 10 15:06:34 IST 2021
;; MSG SIZE  rcvd: 110

Here is the my zone files.

root@mx:/etc/bind# cat mailserver.local.db
;
; BIND data file for local loopback interface
;
$TTL    14400
@       IN      SOA     ns1.mailserver.local. root.mailserver.local. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.mailserver.local.
ns1.mailserver.local.     IN      A       192.168.1.55
localhost       60      IN      A       127.0.0.1
;
@       60      IN      A       192.168.1.55
@       60      IN      CNAME   mx.mailserver.local.
;
@      300      IN      MX      5       mx.mailserver.local.
;
mx     60      IN      A       192.168.1.55
mx     60      IN      A       192.168.1.66
mx     60      IN      A       192.168.1.77
mx     60      IN      A       192.168.1.88


root@mx:/etc/bind# cat db.local
;
; BIND data file for local loopback interface
;
$TTL    2419200
@       IN      SOA     localhost. root.localhost. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       60      IN      NS      localhost.
@       60      IN      A       127.0.0.1
@       60      IN      AAAA    ::1

This is my primary issue, not changed the ip address and keep on 192.168.1.55 only pinging.

root@mx:/etc/bind# for i in {1..6};do ping -c 1 mx.mailserver.local|grep ^PING;sleep 1;done
PING mx.mailserver.local (192.168.1.55) 56(84) bytes of data.
PING mx.mailserver.local (192.168.1.55) 56(84) bytes of data.
PING mx.mailserver.local (192.168.1.55) 56(84) bytes of data.
PING mx.mailserver.local (192.168.1.55) 56(84) bytes of data.
PING mx.mailserver.local (192.168.1.55) 56(84) bytes of data.
PING mx.mailserver.local (192.168.1.55) 56(84) bytes of data.
Carles Mateo avatar
cn flag
Can you show your zone files?. If you set 1000 seconds as TTL, does it resolve as it should? Does it work if you flush your local dns resolver caches? ```$ sudo systemd-resolve --flush-caches $ sudo resolvectl flush-caches``` Cheers
Dilli Ganesh avatar
de flag
Thanks for the update, yes i tried to flush the caches but same issues.
Score:0
cn flag

If you want the Ip's to be rotated I think you need to define different A registers with the same name and different Ip addresses, then you should define the MX registers with the same priority, typically 10, and different Ip's. So to be clear, you need to have two registers: one of the type A another of the type MX.

Maybe you can launch several Docker instances and ping from inside to catch what they resolve?.

ru flag
This will only be handled on a DNS "Round Robin" type scenario. I.E. first address it sees will be the one used, even if a DNS request sends all 4 addresses. And `ping` etc. won't obey the MX records.
Dilli Ganesh avatar
de flag
Thanks for the update.
Score:0
ru flag

The TTL value won't really help you here.

What you're seeing on your single machine is Standard Behavior for DNS, ping, etc. If there are multiple addresses returned for a hostname, services will default to using the first one served in the DNS response.

Let me explain in an example.

Let's say I have a hostname with three A records. Those A records point to 192.168.10.1, 192.168.10.2, and 192.168.10.3 respectively for the same domain.

The DNS response will have any one of those addresses in the response. I.E. the actual DNS "Answer" could give them in the following order:

192.168.10.2
192.168.10.1
192.168.10.3

The same three records in a separate DNS query could return in this order too:

192.168.10.1
192.168.10.3
192.168.10.2

Therefore, when you're doing DNS resolution on a single hostname for the purposes of ping and such, it has zero priority functionality, and the 'last response' it got will be 'cached' and that 'first' address used for the purposes of ping, web requests, initializing connections to a hostname, etc.

There is no concept in ping, etc. of "Test all IPs with different requests" - for that, you have to manually override the address at the /etc/hosts level or ping the IP(s) directly. Typically speaking, if you have three addresses for a single domain record, you should be pinging the IP addresses independently, and not trust the 'hostname' resolution to be proper.

Further, unless you've removed systemd-resolved from the equation, that's a caching resolver on your end, and will 'cache' that initial IP response for the mail server (in my example, .2 was the first address in the response, so it caches that one. if I restart that process on system and flush its cache and the DNS server it queries returns .1 first, then .1 gets cached as the 'result' for the first DNS hostname, as well as the other three entries.)

Dilli Ganesh avatar
de flag
Thanks for the brief explanation.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.