🔗 Networking


Материалы

Примеры кода


The general process for converting a name like www.example.com that humans use into an IP address that computers use is called domain name resolution, and it provided by a distributed group of servers that comprise the Domain Name System, or DNS.

Domain Name Servers

Usually called name servers for short, these servers contain IP records for the domain in which they are an authority. That is, a name server doesn’t have records for the entire world; it just has them for a particular domain or subdomain.

subdomain is a domain administered by the owner of a domain. For example, the owner of example.com might make subdomains sub1.example.com and sub2.example.com. These aren’t hosts in this case–but they can have their own hosts, e.g. host1.sub1.examople.comhost2.sub1.example.comsomecompy.sub2.example.com.

Domain owners can make as many subdomains as they want. They just have to make sure they have a name server set up to handle them.

DNS Server Hierarchy

Root Nameservers

We have a number of root name servers that can help us on our way. When we don’t know an IP, we can start with them and ask them to tell us IP, or tell us which other server to ask. More on that process in a minute.

Computers are preconfigured with the IP addresses of the 13 root name servers. These IPs rarely ever change, and only one of them is needed to work. Computers that perform DNS frequently retrieve the list to keep it up to date.

Example Run

Let’s start by doing a query on a computer called www.example.com. We need to know its IP address. We don’t know which name server is responsible for the example.com domain. All we know is our list of root name servers.

  1. Let’s choose a random root server, say c.root-servers.net. We’ll contact it and say, “Hey, we’re looking for www.example.com. Can you help us?”

    But the root name server doesn’t know that. It says, “I don’t know about that, but I can tell you if you’re looking for any .com domain, you can contact any one of these name servers.” It attaches a list of name servers who know about the .com domains:

    a.gtld-servers.net
    b.gtld-servers.net
    c.gtld-servers.net
    d.gtld-servers.net
    e.gtld-servers.net
    f.gtld-servers.net
    g.gtld-servers.net
    h.gtld-servers.net
    i.gtld-servers.net
    j.gtld-servers.net
    k.gtld-servers.net
    l.gtld-servers.net
    m.gtld-servers.net
    
  2. So we choose one of the .com name servers.

    “Hey h.gtld-servers.net, we’re looking for www.example.com. Can you help us?”

    And it answers, “I don’t know that name, but I do know the name servers for example.com. You can talk to one of them. It attaches the list of name servers who know about the example.com domain:

    a.iana-servers.net
    b.iana-servers.net
    
  3. So we choose one of those servers.

    “Hey a.iana-servers.net, we’re looking for www.example.com. Can you help us?”

    And that name server answers, “Yes, I can! I know that name! Its IP address is 93.184.216.34!”

So for any lookup, we start with root name server and it directs us on where to go to find more info. (Unless the information has been cached somewhere, but more on that later.)

Caching Servers

This way we can avoid overloading the root servers with repeated requests.

  1. Ask our resolver library for the IP address. If it has it cached, it will return it.

  2. If it doesn’t have it, ask our local name server for the IP address. If it has it cached, it will return it.

  3. If it’s not cached and if this name server has another upstream name server, it asks that name server for the answer.

  4. If it’s not cached and if this name server does not have another upstream name server, it goes to the root servers and the process continues as before.

With all these possible opportunities to get a cached result, it really helps take the load off the root name servers.

Lots of WiFi routers you get also run caching name servers. So when DHCP configures your computer, your computer uses your router as a DNS server for the computers on your LAN. This gives you a snappy response for DNS lookups since you have a really short ping time to your router.

Time To Live

Since the IP address for a domain or host might change, we have to have a way to expire cache entries.

This is done through a field in the DNS record called time to live (TTL). This is the number of seconds a server should cache the results. It’s commonly set to 86400 seconds (1 day), but could be more or less depending on how often a zone administrator thinks an IP address will change.

When a cache entry expires, the name server will have to once again ask for the data from upstream or the root servers if someone requests it.


dig tool


Record Types

The common record types are:

  • A: An address record for IPv4. This is the type of record we’ve been talking about this whole time. Answers the question, “What is the IPv4 address for this host or domain?”
  • AAAA: An address record for IPv6. Answers the question, “What is the IPv6 address for this host or domain?”
  • NS: A name server record for a particular domain. Answers the question, “What are the name servers answering for this host or domain?”
  • MX: A mail exchange record. Answers the question, “What computers are responsible for handling mail on this domain?”
  • TXT: A text record. Holds free-form text information. Is sometimes used for anti-spam purposes and proof-of-ownership of a domain.
  • CNAME: A canonical name record. Think of this as an alias. Makes the statement, “Domain xyz.example.com is an alias for abc.example.com.”
  • SOA: A start of authority record. This contains information about a domain, including its main name server and contact information.

There are a lot of DNS record types.

A & AAAA records

CNAME records

MX records

TXT records

Dynamic DNS

Typical users of the Internet don’t have a static IP address (that is, dedicated or unchanging) at their house. If they reboot their modem, their ISP might hand them a different IP address.

This causes a ruckus with DNS because any DNS records pointing to their public IPs would be out of date.

Dynamic DNS (DDNS) aims to solve this problem.

In a nutshell, there are two mechanisms at play:

  1. A way for a client to tell the DDNS server what their IP address is.
  2. A very short TTL on the DDNS server for that record.

While DNS defines a way to send update records, a common other way is for a computer on your LAN to periodically (e.g. every 10 minutes) contact the DDNS provider with an authenticated HTTP request. The DDNS server will see the IP address it came from and use that to update its record.


📂 Networking | Последнее изменение: 03.03.2024 22:41