Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to understand DNS a bit better, but I still don't get A and NS records completely.

As far as I understood, the A record tells which IP-address belongs to a (sub) domain, so far it was still clear to me. But as I understood, the NS record tells which nameserver points belongs to a (sub) domain, and that nameserver should tell which IP-address belongs to a (sub) domain. But that was already specified in the A record in the same DNS file. So can someone explain to me what the NS records and nameservers exactly do, because probably I understood something wrong.

edit: As I understand you correctly, a NS record tells you were to find the DNS server with the A record for a certain domain, and the A record tells you which ip-address belongs to a domain. But what is the use of putting an A and an NS record in the same DNS file? If there is already an A record for a certain domain, then why do you need to point to another DNS server, which would probably give you the same information?

share|improve this question
add comment

migrated from stackoverflow.com Jan 20 '11 at 23:10

This question came from our site for professional and enthusiast programmers.

6 Answers

up vote 5 down vote accepted

Some examples out of the fictitious foo.com zone file

 ....... SOA record & lots more stuff .......
 foo.com.      IN        NS        ns1.bar.com.

 foo.com.      IN        A         192.168.100.1
 ....... More A/CNAME/AAAA/etc. records .......

A Record = "The host called foo.com lives at address 192.168.100.1"
NS Record = "If you want to know about hosts in the foo.com zone, ask the name server ns1.bar.com"

share|improve this answer
    
I love foobar references. :D –  JohnThePro Jan 20 '11 at 23:18
1  
@Tiddo a big reason is that slave servers are usually notified of zone changes because they're listed as NS records. Also if you query the authoritative server for ns1.foo.com's address in the process of looking up something else and the record doesn't exist there you'll get NXDOMAIN and Bad Things will happen (but it will work for people who queried the com parent server, since presumably there would be glue A records there) –  voretaq7 Jan 20 '11 at 23:26
1  
@JohnThePro - my other option was example.com, and I hate example.com references :-) –  voretaq7 Jan 20 '11 at 23:29
1  
@voretaq7 so basically the NS records are used as a backup mechanism and to notify those nameservers when the ip-address of the domain changes? –  Tiddo Jan 20 '11 at 23:30
1  
@tiddo and as a signpost as described above & in lots of the other answers. There may be other things that look at NS records that I'm forgetting about, but those are the two big ones that jump to mind. –  voretaq7 Jan 20 '11 at 23:42
show 2 more comments

The NS records specify the servers which are providing DNS services for that domain name.

The A records point host names (such as www, ftp, mail) to one or more IP addresses.

share|improve this answer
add comment

NS records exist SOLELY for the purpose of defining WHICH NAMESERVERS are responsible for a particular domain.

An A record exists to "ADDRESS" a particular machine, or service.

Examples for you:

In your DNS Control Panel, you'll see some NS records, these are your NAMESERVERS, or primary machine responsible for telling the internet where stuff on your domain resides.

NS1.CP.COM NS2.CP.COM

Also inside of your DNS Panel, you'll have a domain that you own (ie. -mikesfunhouse.com) that you need to have some services, like a website on.

So what you'll do is have a Primary A record, pointing "mikesfunhouse.com" to "76.19.87.956" (obviously fake IP).

Then you'll make another record, a www record, which will redirect the subdomain "www." portion to your primary site.

In short, you use A records to convert a namespace to an IP address.

share|improve this answer
add comment

an A record maps a name to an IP address. e.g.

binary.example.com.         IN  A       192.168.1.42

states that binary.example.com. resolves to 192.168.1.42

an NS record maps a name to another nameserver, i.e. another DNS server that serves that domain. i.e. "I've no idea of the IP address of this name, but if you go ask that nameserver over there, it might know"

binary.example.com.            IN      NS      otherbox.example.com
otherbox.example.com.          IN       A      192.168.1.2

If you ask a DNS server that has the above 2 records for binary.example.com. (or www.binary.example.com. or foo.bar.binary.example.com). it'll tell you that you'll have to go ask 192.168.1.2 to translate those names (well, or the dns server could do that for you, or it could have the resolved names cached and return them to you.)

share|improve this answer
    
often you'll see DNS records which specifies NS and A records for the same domains. But if an NS record tells were to find the A record, then what is the use of the NS record in that same file, if the A record is already there? –  Tiddo Jan 20 '11 at 23:25
add comment

It is important to have both NS and A record in zone if you need to delegate sub-zone to different DNS server.

E.g. we have dns server ns1.bar.com authoritative for zone foo.com. And we need to delegate foo.bar.com to ns1.foo.bar.com. So we need to create zone foo.bar.com and put there this records:

foo.bar.com     IN NS ns1.foo.bar.com
ns1.foo.bar.com IN A  10.10.10.10

If we won't have A record delegation won't work. Such record pairs are called glue records.

Glue records is only way for DNS system to find the exact IP of authoritative DNS server for non-root zone. If you check any domain for NS record using dig or see traffic dump with wireshark you'll see that there's 'additional' section in answer.

;; ANSWER SECTION:
foo.bar.com.             10800   IN      NS      ns1.foo.bar.com.

;; ADDITIONAL SECTION:
ns1.foo.bar.com.         7972    IN      A       10.10.10.10

when doing recursive request, e.g. www.foo.bar.com your dns client will ask for DNS authoritative for foo.bar.com zone and get answer ns1.foo.bar.com.

To go further it needs to send A request for ns1.google.com, which is served by .. ns1.foo.bar.com. To break out loop, delegating DNS server should add this additional section, with A record.

Server ns1.foo.bar.com should have same glue records in it's zone, so it can be authoritative for foo.bar.com zone.

share|improve this answer
add comment

The nameserver record tells the Internet which DNS server holds the A records, so to look up an A record for a subdomain it's roughly the following process:

Lookup the nameservers for the domain -> Query the nameserver for the subdomain's A Record

share|improve this answer
    
But if the A records are already in that same file, why should you specify the NS records? –  Tiddo Jan 20 '11 at 23:16
    
It's all about what you're looking for. The NS record is like the starting point. If a server had NEVER EVER visited your domain before, it would first find the NS server respond for your domain. After it identified that server, it would query it for the A record of the domain in question. –  JohnThePro Jan 20 '11 at 23:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.