Understand what DNS, A records, CNAME are and how to use them in one article

Domain name resolution DNS

Introduction

Domain Name System (DNS) is the system used in the Internet to convert human-readable domain names ( such as www.example.com ) into computer-understandable IP addresses (such as 192.168.1.1). It acts as a "phone book" on the Internet, helping to map user-supplied domain names to actual network addresses, allowing computers to find and connect to the appropriate network server.

Vernacular: IP is equivalent to your home address, such as 101, community xxx, Wuhan City, Hubei Province, and domain name is equivalent to your name. It is called DNS when it binds you to your home. The meaning is that when someone goes to your home, no. You need to remember that xxx community 101 in Wuhan City, Hubei Province is so troublesome, just remember that it is your home.

How domain name resolution works:

  1. Query initiation: When the user enters a domain name in the browser, such as "​ ​www.example.com ​", the browser will try to initiate a query request to the DNS resolver of the local computer.
  2. Local resolution: The local resolver is a part of the user's computer that first checks the local cache to see if the domain name has already been resolved. If not, it forwards the query request to the ISP (Internet Service Provider)'s DNS server.
  3. Recursive resolution: The ISP's DNS server will attempt to perform recursive resolution. It will first query the DNS servers for the top-level domain (such as .com), then query the DNS servers for the secondary domain (such as .example.com), and so on, layer by layer, until it finds the specific server responsible for the domain name.
  4. Response return: When the recursive resolution finds the server responsible for the domain name, it will obtain the IP address corresponding to the domain name from the server, and then return the IP address to the local resolver.
  5. Local cache update: The local resolver stores the obtained IP address in the local cache for future queries. This helps improve performance as future queries can be fetched directly from the local cache.
  6. User connection: The local resolver returns the IP address to the user's computer so that the user's browser or other applications can use this IP address to establish a connection with the server to obtain web content or perform other network operations.

A record

Introduction

A record (Address Record) is a DNS record type used to map a domain name to an IPv4 address. By setting up an A record, you can point a specific domain name directly to a specific IP address, allowing users to access the corresponding server or network resources through this domain name. ,

Procedure for setting up an A record

This is usually done in the control panel of your domain registrar or DNS hosting provider:

  1. Log in to the control panel: Using the account information provided by your domain registrar or DNS hosting provider, log in to their control panel.
  2. Find DNS Settings: Look for options similar to "DNS Settings", "DNS Management" or "Domain Name Management" to enter the DNS record management page.
  3. Select a domain name: Select the domain name for which you want to set an A record from the list.
  4. Add an A record: On the DNS record management page, look for a button or link, usually labeled "Add record," "New record," etc. Select "A Record" in the record type.
  5. Fill in the record information: Fill in the following information:

Hostname: Enter the subdomain name you want to set an A record for, such as "www".

IPv4 Address: Enter the IPv4 address of the target server.

CNAME

Introduction

CNAME is a record type in DNS (Domain Name System), and its full name is Canonical Name. CNAME records are used to map one domain name to another domain name, aliasing or redirecting the domain name.

Function : CNAME records are used to create aliases that map one domain name to another domain name.

Purpose : Mainly used to redirect access from one domain name to another domain name to facilitate management and maintenance. When the IP address of the target domain name changes, only the DNS record of the target domain name needs to be updated, rather than all records that reference the domain name need to be changed.

The operation method is the same as A record

Here is an interesting example: when you visit "​ ​​www.China , you will be redirected to a magical place, where CNAME is used

important point:

  1. Cannot coexist with other records: In the DNS records of a domain name, CNAME records usually cannot coexist with other records (such as A records, MX records, etc.) under the same host name.
  2. The target domain name cannot have other records: If the target domain name has other records (such as A records, TXT records, etc.), CNAME records usually cannot be created. However, in some cases, special configurations can be used to allow additional records for the target domain name.
  3. Added DNS query: Using CNAME records will introduce additional DNS query steps, because the IP address of the domain name pointed to by the CNAME record needs to be queried again when resolving the domain name.

The difference between A records and CNAME

1. An A record directly maps a domain name to an IPv4 address, while a CNAME record maps a domain name to another domain name.

2. The A record is faster because it maps directly to the IP address and does not introduce additional query steps. CNAME records may slow down resolution slightly because they require additional query steps to find the IP address of the target domain name.

3. A records are suitable for situations where direct mapping to IP addresses is required, while CNAME records are suitable for situations where aliases are created or target locations need to be managed more flexibly.

Guess you like

Origin blog.csdn.net/weixin_43820024/article/details/132116370