Sobes.tech
Middle

What is DNS and how does it work?

sobes.tech AI

Answer from AI

DNS (Domain Name System) is a distributed system that translates domain names (e.g., example.com) into IP addresses understandable by computers on the network.

When you enter a website address in your browser, your computer sends a request to a DNS server to obtain the corresponding IP. DNS servers are organized hierarchically: the request first goes to root servers, then to top-level domain servers (.com, .org, etc.), and finally to authoritative domain servers. After receiving the IP, the browser establishes a connection to the required server.

Example in Go for resolving a domain name:

package main

import (
    "fmt"
    "net"
)

func main() {
    ips, err := net.LookupIP("example.com")
    if err != nil {
        fmt.Println("Error resolving domain:", err)
        return
    }
    for _, ip := range ips {
        fmt.Println("IP address:", ip.String())
    }
}
What is DNS and how does it work? — Golang - sobes.tech