Typy Rekord贸w DNS

A, AAAA, CNAME, MX, NS i inne typy rekord贸w zasob贸w DNS.

Introduction: The Entries in the Internet's Address Book

The Domain Name System (DNS) acts as the global address book for the internet, translating human-readable domain names like www.google.com into machine-readable IP addresses. However, a physical address book can contain more than just a name and a phone number; it can also have entries for a street address, an email address, or other notes. Similarly, the DNS database is far more versatile than a simple name-to-IP mapping. It stores different kinds of information in structured entries known as or Resource Records (RRs).

Each type of DNS record serves a distinct purpose. One type points a domain to the IP address of its web server, another directs emails to the correct mail server, and yet another can be used to prove ownership of a domain to a third-party service. This variety is what makes DNS a powerful and flexible system that underpins not just web browsing, but email delivery, voice-over-IP (VoIP) services, spam filtering, and countless other internet functions. In this guide, we will explore the structure of these records and delve into the most common types you will encounter.

The Anatomy of a DNS Record

While different record types hold different kinds of data, nearly all of them share a common underlying structure, typically presented in a standard format within a domain's zone file. This structure consists of several key fields:

1. Name (or Hostname)
This is the domain name the record applies to. It can be the root domain itself (e.g., example.com) or a subdomain (e.g., www.example.com, mail.example.com). The ""@"" symbol is often used in zone files as a shorthand to represent the root domain.
2. TTL (Time-To-Live)
is a value in seconds that tells DNS resolvers how long they are allowed to cache (store) this record. After the TTL expires, the resolver must query the authoritative name server again to get a fresh copy. A longer TTL reduces DNS traffic and speeds up lookups, but a shorter TTL allows for faster propagation of changes.
3. Class
This field specifies the protocol family. For the vast majority of internet applications, this will always be IN, which stands for Internet. Other classes exist (e.g., CH for Chaosnet) but are primarily historical or experimental.
4. Type
This is the most important field, as it defines the type of data contained in the record. It determines the record's purpose, such as A, AAAA, MX, or CNAME.
5. Data (or Value)
This is the actual content of the record. Its format depends entirely on the record's Type. For an A record, this will be an IPv4 address. For an MX record, it will be a priority number and a mail server's domain name.
;      Name               TTL   Class Type  Data
www.example.com. 3600 IN A 93.184.216.34

Essential Record Types: The Building Blocks of DNS

The following record types are the most fundamental and commonly used. They are essential for basic web browsing and email functionality.

A Record: The Primary Address (IPv4)

The A record (Address record) is the simplest and most important type of DNS record. Its sole purpose is to map a domain name to a 32-bit IPv4 address. When you type a domain name into your browser, the first thing your computer's DNS resolver does is look for the A record for that domain.

Record Structure:

hostname TTL IN A IPv4-address

Practical Example:

Let's find the IPv4 address for cloudflare.com. We can use a command-line tool like 'nslookup'.

> nslookup cloudflare.com
Server:  one.one.one.one
Address:  1.1.1.1

Non-authoritative answer:
Name:    cloudflare.com
Address: 104.16.132.229
Name:    cloudflare.com
Address: 104.16.133.229

This tells us that the domain cloudflare.com has two A records, pointing to the IP addresses 104.16.132.229104.16.132.229 and 104.16.133.229104.16.133.229. Having multiple A records is a common technique for distributing traffic across multiple servers for load balancing and redundancy.

AAAA Record: The Next Generation Address (IPv6)

The AAAA record (often called a "quad-A" record) serves the exact same purpose as an A record but for the next generation of internet addresses: IPv6. As the world runs out of available IPv4 addresses, IPv6 is becoming increasingly important. An AAAA record maps a domain name to a 128-bit IPv6 address. The name "AAAA" comes from the fact that IPv6 addresses (128 bits) are four times longer than IPv4 addresses (32 bits).

Record Structure:

hostname TTL IN AAAA IPv6-address

Practical Example:

Let's query for the AAAA record of google.com.

> nslookup -type=AAAA google.com
Server:  one.one.one.one
Address:  1.1.1.1

Non-authoritative answer:
Name:    google.com
Address: 2a00:1450:4009:823::200e

A device that supports IPv6 will typically prioritize the AAAA record over the A record if both are present.

CNAME Record: The Alias

A CNAME record (Canonical Name record) acts as an alias, pointing one domain name to another, "canonical" domain name. When a DNS resolver encounters a CNAME record, it stops its current query and starts a new one for the canonical name it was pointed to. This process continues until an A or AAAA record is found. CNAMEs are extremely useful for pointing multiple hostnames to a single server without having to manage A records for each one.

Record Structure:

alias.hostname TTL IN CNAME canonical.hostname

Practical Example:

Many websites point their "www" subdomain to their root domain. Let's look at www.github.com.

> nslookup -type=CNAME www.github.com
Server:  one.one.one.one
Address:  1.1.1.1

Non-authoritative answer:
www.github.com canonical name = github.com.

This shows that www.github.com is an alias for github.com. If you change the IP address for github.com, the 'www' subdomain will automatically point to the new address without any extra work.

Important Restriction:

A CNAME record cannot coexist with any other record type for the same hostname. This is why you generally cannot place a CNAME record on a root domain (like example.com), because the root domain must also have NS and SOA records.

MX Record: The Mail Exchanger

An MX record (Mail Exchanger record) is used exclusively for routing email. It specifies the mail server(s) responsible for accepting email messages on behalf of a domain. When you send an email to [email protected], your mail server performs a DNS lookup for the MX records of example.com to find out where to deliver the message.

Record Structure:

domain TTL IN MX priority mail.server.hostname

The MX record has a unique field: priority. This is a number that indicates preference; mail servers will always try to deliver to the server with the lowest priority number first. If that server is unavailable, they will try the next lowest, and so on. This allows for setting up primary and backup mail servers.

Practical Example:

Let's check the mail servers for Google's gmail.com domain.

> nslookup -type=MX gmail.com
Server:  one.one.one.one
Address:  1.1.1.1

Non-authoritative answer:
gmail.com     mail exchanger = 5 gmail-smtp-in.l.google.com.
gmail.com     mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
gmail.com     mail exchanger = 20 alt2.gmail-smtp-in.l.google.com.
gmail.com     mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com     mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.

This shows that the primary mail server is gmail-smtp-in.l.google.com with a priority of 55. If it fails, servers will try alt1 (priority 10), then alt2 (priority 20), and so on.

NS Record: The Name Server

An NS record (Name Server record) is what makes the DNS hierarchy work through delegation. It specifies the authoritative DNS servers for a given domain. When you register a domain name, you must provide at least two NS records to your domain registrar. These records are placed in the parent TLD's zone file (e.g., in the .com servers' database), telling the entire internet which servers hold the definitive records for your domain.

Record Structure:

domain TTL IN NS nameserver.hostname

Practical Example:

> nslookup -type=NS google.com
Server:  one.one.one.one
Address:  1.1.1.1

Non-authoritative answer:
google.com      nameserver = ns1.google.com.
google.com      nameserver = ns2.google.com.
google.com      nameserver = ns3.google.com.
google.com      nameserver = ns4.google.com.

This shows the four authoritative name servers responsible for the google.com domain.

Other Important Record Types

Beyond the essentials, several other record types provide critical functionality for security, service discovery, and reverse lookups.

TXT Record: The Multi-Purpose Text Record

A TXT record allows a domain administrator to associate arbitrary text with a domain. While this may sound simple, its flexibility has made it a Swiss Army knife for various network protocols and verification mechanisms. Some key uses include:

  • Sender Policy Framework (SPF): SPF records (which are defined using the TXT record type) help prevent email spoofing by publishing a list of servers that are authorized to send email on behalf of a domain.
  • DomainKeys Identified Mail (DKIM): DKIM records (also TXT records) contain a public key used to verify that an email was actually sent by the owner of the domain and that its content was not tampered with.
  • Domain Ownership Verification: Services like Google Search Console or Office 365 often require you to add a specific TXT record to your domain to prove you control it before you can use their services with it.

SRV Record: Service Discovery

An SRV record (Service record) provides a more general way to find services. Instead of just mapping a hostname to an IP address, it specifies a hostname and a port for a specific service. It also includes priority and weight values, allowing for failover and load balancing. SRV records are commonly used by modern protocols like VoIP (using SIP) and instant messaging (using XMPP).

Record Structure:

_service._proto.name. TTL IN SRV priority weight port target.

PTR Record: The Reverse Lookup

A PTR record (Pointer record) is used for reverse DNS lookups. While an A record maps a name to an IP, a PTR record does the opposite: it maps an IP address back to a name. These records are stored in a special reverse DNS zone. Reverse DNS is widely used by mail servers as a security check; many mail servers will reject email from an IP address that does not have a valid PTR record that matches the sending hostname.

Record Structure:

reversed-IP.in-addr.arpa. TTL IN PTR hostname.
    DNS Record Types | Teleinf Edu