|
1 |
| -# DNS - Domain Name System |
| 1 | +# DNS - Domain Name System |
| 2 | + |
| 3 | +DNS is a system that translates domain names to IP addresses. This is used to route traffic via an human readable name to an ip address. |
| 4 | + |
| 5 | +- DNS names are only used for human readability |
| 6 | +- Servers use IP addresses to communicate with each other |
| 7 | + |
| 8 | +```mermaid |
| 9 | +sequenceDiagram |
| 10 | + participant Client |
| 11 | + participant DNS_Server as DNS Server |
| 12 | + participant Web_Server as Web Server |
| 13 | +
|
| 14 | + Client->>DNS_Server: DNS Request: www.example.com |
| 15 | + DNS_Server-->>Client: DNS Response: 200.0.0.0 |
| 16 | + Client->>Web_Server: HTTP GET /index.html |
| 17 | + Web_Server-->>Client: HTTP Response 200 OK |
| 18 | +
|
| 19 | +``` |
| 20 | + |
| 21 | +### Zones |
| 22 | + |
| 23 | +A DNS zone is a segment of the domain namespace managed by a specific organization or administrator. It consists of a collection of DNS records maintained by a DNS server. Zones enable different parts of a domain to be managed by separate DNS servers, providing flexibility and delegation in domain administration. |
| 24 | + |
| 25 | +## DNS Records |
| 26 | + |
| 27 | +DNS records are used to store information about a domain in a DNS zone file. General format of a DNS record: |
| 28 | + |
| 29 | +```text |
| 30 | +<name> <ttl> <class> <type> <rdata> |
| 31 | +``` |
| 32 | + |
| 33 | +- `<name>`: the domain or subdomain |
| 34 | +- `<ttl>`: time to live (how long the record is cached) |
| 35 | +- `<class>`: the class of the record (IN for internet) |
| 36 | +- `<type>`: the type of record (A for address) |
| 37 | +- `<rdlength>`: length of the rdata field (internaly used) |
| 38 | +- `<rdata>`: the IP address or data associated with the record |
| 39 | + |
| 40 | +> [!INFO] |
| 41 | +> |
| 42 | +> - `<ttl>`, `<class>` and `<type>` are optional fields. If not specified, they will be set to default values. |
| 43 | +> - `<rdlength>` is an internal field |
| 44 | +
|
| 45 | +### A and AAAA Records |
| 46 | + |
| 47 | +A record is used to point a domain or subdomain to an IP address. A records are used for IPv4 addresses and AAAA records are used for IPv6 addresses. |
| 48 | + |
| 49 | +```text |
| 50 | +example.com 3600 IN A 200.0.0.0 |
| 51 | +example.com 3600 IN AAAA 2001:0db8:85a3:0000:0000:8a2e:0370:7334 |
| 52 | +``` |
| 53 | + |
| 54 | +### CNAME Record |
| 55 | + |
| 56 | +CNAME record is used to point a domain or subdomain to another domain. The authoritative DNS server will resolve the CNAME record to the IP address of the target domain. |
| 57 | + |
| 58 | +```text |
| 59 | +www.example.com 3600 IN CNAME example.com |
| 60 | +``` |
| 61 | + |
| 62 | +> [!WARNING] |
| 63 | +> |
| 64 | +> CNAME records cannot be used for root domains (apex) per [RFC 2181](https://www.rfc-editor.org/rfc/rfc2181#section-10). |
| 65 | +
|
| 66 | +### NS Record |
| 67 | + |
| 68 | +NS record is used to indicate the authoritative DNS server for a domain. With NS records, multiple subdomains can be managed with different DNS zones. |
| 69 | + |
| 70 | +```text |
| 71 | +example.com 3600 IN NS ns1.google.com |
| 72 | +example.com 3600 IN NS ns2.google.com |
| 73 | +example.com 3600 IN NS ns3.google.com |
| 74 | +example.com 3600 IN NS ns4.google.com |
| 75 | +``` |
| 76 | + |
| 77 | +Often there are multiple NS records for a domain to provide redundancy and load balancing. |
| 78 | + |
| 79 | +### MX Record |
| 80 | + |
| 81 | +MX record is used to specify the mail servers that are responsible for receiving emails for a domain. |
| 82 | + |
| 83 | +```text |
| 84 | +example.com 3600 IN MX 10 mail1.example.com |
| 85 | +example.com 3600 IN MX 20 mail2.example.com |
| 86 | +``` |
| 87 | + |
| 88 | +The number (`10`, `20`) in the MX record is the priority of the mail server. Lower numbers have higher priority. |
| 89 | + |
| 90 | +### Other Records |
| 91 | + |
| 92 | +- **SOA Record**: Start of Authority record is used to specify the authoritative DNS server for a domain. |
| 93 | +- **TXT Record**: Text record is used to store arbitrary text data. |
| 94 | +- **PTR Record**: Pointer record is used for reverse DNS lookups. |
| 95 | +- **CAA Record**: Certificate Authority Authorization record is used to specify which certificate authorities are allowed to issue certificates for a domain. |
| 96 | + ```text |
| 97 | + example.com CAA 0 issue "letsencrypt.org" |
| 98 | + ``` |
0 commit comments