BIND 9 – How to enter a DNS record for the main domain

binddomain-name-systeminternal-dns

Let's say I have a domain named example.com.
The subdomains on that work, however I cannot attach example.com to an IP Address of its own.

wifi    IN    A   1.1.1.1     ; -Works (wifi.example.com)
router  IN    A   1.1.1.2     ; -Works (router.example.com)
@       IN    A   1.1.1.3     ; - Doesn't Work (example.com)

named-checkconf and named-checkzone both return nothing. I am rather new at BIND so instead of trouble shooting my zone file. Can you simply provide the instructions for achieving my above question?

Best Answer

To add an address record (A/AAAA) like in your example, regardless if it's at the zone apex or at some other level, you simply need to specify the desired owner name.

An example that doesn't rely on any "tricks":

example.com. IN A 192.0.2.7

What you did is also a potentially working way of doing it but the value of @ is very much context sensitive.
@ expands to the the current origin (can be changed using the $ORIGIN directive).

At a point in the zone file where there have been no $ORIGIN directives the origin is the zone name (example.com. in your example).
If there are $ORIGIN directives you'll have to keep track of what the current origin is to know what @ actually means. (Where you add your line will affect its meaning.)

The same also applies for relative names (which you used for the other records in your example), these are also relative to the current origin.

Eg

wifi.example.com. IN A 192.0.2.8

is using an absolute name and is not context sensitive

while

wifi IN A 192.0.2.8

is context sensitive and will expand to wifi with whatever the current origin is appended to it, with pretty much identical implications as the use of @.

You having different success with eg wifi and @ could be explained by you adding these lines in different positions in a zone file that has $ORIGIN directives.

named-checkconf -zj/named-checkzone not showing any errors supports this theory as it's not an actual error, it's just that you have added the record in a different place than you intended, eg at foo.example.com. instead of at example.com..

To see the actual zone data fully spelled out for you, you may want to format it into its fully expanded form, you can easily get this using eg dig @localhost example.com AXFR (if you allow yourself to AXFR) or named-compilezone -f text -F text -s full -j -o - example.com db.example.com (if you have the file available).

Related Topic