Understanding DNS

Understanding DNS

When you're browsing megacreations, your computer doesn't send data to www.megacreations.com It sends to 64.179.4.146. You don't have to remember the numerical address - DNS servers do it for you.

This text was written to tell you what DNS is, how it works and how you can use it. It doesn't describe configuration of your own DNS server.

Before I describe how the DNS system works, you need to know about IP adresses and domains.

IP Addresses

64.179.4.146 is an example. IP (Internet protocol) address has a form of four numbers (between 0 and 255), separated by dots. Each machine in the Internet must have an unique IP address. It works as a postal address - no message can reach the machine without a correct address.

Numbers are friendly for machines, but hard to remember for humans. That's why we have hostnames and domains (there are more reasons, for example names allow you to easily change IP addresses of servers - only the DNS entry must be changed).

Hostnames, domains, zones

An example of a hostname: www.megacreations.com It's a part of megacreations.com domain. Last portion of the address (.com) refers to a toplevel domain where the host belongs. Other toplevel domains are: .org, .net, .gov etc. Every country has its own toplevel domain. For example: .fr (France), .de (Germany), .jp (Japan) or .br (Brazilia).

Zone and domain mean nearly the same. There's one difference: zone is delegated to one server. A domain can be diveded into different zones.

How it works?

When you connect to LQ, you send a query to your DNS resolver (more about it later). The server checks if it has needed information cached. If it does, it sends it back to you. The server that stores data from previous queries is called a caching nameserver.

If it doesn't have the information you're searching for, it asks one of the root servers. Root servers are on the top of DNS servers tree (the structure looks like a tree). They contain pointers to name servers for each top level domain.

Now the toplevel domain server for .com is asked about megacreations.com domain, it knows the address of the server containing detailed information about all hosts in the megacreations.com domain.

The last server is asked about the host www.megacreations.com hosts. When your resolver server gets the reply, it sends the result back to you.

Types of DNS servers:

A caching nameserver finds answers to queries and then remembers them. This not only speeds up your response time but helps to keep the load on the root nameservers (which handle thousands of queries per second) as low as possible.

An Authoritative server is a server that can answer queries about a zone without help from any other server. Both primary and secondary servers are authoritative.

Primary server(in terms of specific zone) is a server that reads zone data from its local configuration.

Secondary server(in terms of a specific zone) gets zone data from outside sources (usually from master server).

How to use DNS servers?

The file with IP addresses of your nameservers is /etc/resolv.conf. When the machine is correctly configured, it should look like this:

nameserver 192.168.1.1

nameserver 192.168.1.3

DNS servers are listed in lines beginning with 'nameserver' (there are more things to configure in that file). In the example above there are two DNS servers: 192.168.1.1 and 192.168.1.3 (don't copy them, local addresses are used and it may not work in your network).

There's one more important file - /etc/host.conf. It should look like below:

Quote:

order hosts,bind

multi on

When the file is filled properly, everything should work fine.

Where to get the addresses from?

Your ISP is the best source. Most ISPs have their own DNS servers. They're closest to you (so should be the fastest).

If you're using DHCP (many ADSL connections) or modem, your ISP may pass the information to you when you connect. In such case, you don't need to edit /etc/resolv.conf manually.

How to test it?

You can use 'nslookup' or 'dig'.

First example, using nslookup:

sh-2.05b$ nslookup www.megacreations.com

Note: nslookup is deprecated and may be removed from future releases.

Consider using the `dig' or `host' programs instead. Run nslookup with

the `-sil[ent]' option to prevent this message from appearing.

Server: 192.168.1.1

Address: 192.168.1.1#53

Non-authoritative answer:

Name: www.megacreations.com

Address: 64.179.4.146

As you can see it gives the same answer as we got when ping was used.

Next example, using 'dig'. The command format is:

dig @DNS_server host

It returns more information, so may be harder to read. I'm asking the server 192.168.1.1 about www.linuxquestions.org. You don't need to give the DNS server. If you simply use 'dig.linuxquestions.org', your default DNS server will be used. In the 'ANSWER SECTION' you can see that www.linuxquestions.org is 64.179.4.146. In the line 'Query time' you can see how much time it takes to get an answer. In the example below the time is very short, because I use caching nameserver.

sh-2.05b$ dig @192.168.1.1 www.linuxquestions.org

; <<>> DiG 9.2.2 <<>> @192.168.1.1 www.linuxquestions.org

;; global options: printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28312

;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 0

No comments:

Post a Comment