Hello everyone, I am Brother Ming. During job interviews, interviewers like to test basic knowledge. In addition to data structures and algorithms, network knowledge is also a very important subject of examination. However, network knowledge is usually very abstract and difficult to understand, and many students fail here. It just so happens that I haven’t shared any content related to the Internet in this official account before, so I plan to reorganize some knowledge about the Internet, which may be useful during your interviews. Today I will start sharing the first article in this network literacy series: DNS. 1. What is DNS? DNS is the abbreviation of Domain Name System, which is the domain name resolution system. Its function is very simple, which is to find the corresponding IP address based on the domain name. You can think of it as a giant phone book. For example, when you want to access the domain name www.163.com, you must first find out its IP address through DNS: 112.48.162.8. 2. Domain name hierarchy Since I will talk about the DNS resolution process later, you need to have some understanding of the domain name hierarchy.
3. DNS resolution process Let's take the domain name www.163.com as an example and see what happens when you visit www.163.com:
To sum up, there are three sentences
4. DNS cache time In the above steps, you can see that there are two places where DNS query records will be cached. With caching, query efficiency will be improved to a certain extent, but at the same time there will be a loss in accuracy. Therefore, when we configure DNS resolution, there will be a TTL parameter (Time To Live), which means how long the cache can survive. After this time, the local DNS will delete the record. After deleting the cache, if you visit again, you must go through the above process again to obtain the latest address. 5. DNS record types After we buy a domain name in Alibaba Cloud, we can configure our host domain name resolution rules, that is, records. Alibaba Cloud Domain Name Cloud Resolution Common DNS record types are as follows
6. DNS message structure Later I will use wireshark to capture DNS packets, but before starting, I need to understand the DNS message structure.
7. Wireshark packet capture practice After opening Wireshark, use ping 163.com to initiate a DNS resolution request and use the DNS keyword to filter in Wireshark. From the overall captured message, we can roughly obtain several pieces of information
I have included screenshots of the request and response messages below, and I will analyze them one by one. ask answer Transaction ID The transaction ID for the request and response should be the same: 0xd0d7 Flags There is a lot of content in the flag field. The meaning of each field is as follows
Answer RRs The number of answer resource records is 2 in the response packet, indicating that two query results are returned, which you can see in the Answer field. Authority RRs Authoritative Name Server Count Additional RRs Number of additional resource records Answers The main content of the response. Two results are returned here. The fields in each result are
8. DNS hijacking and HTTP hijacking Through the above explanation, we all know that DNS completes a domain name to IP mapping query. When you visit www.baidu.com, it can correctly return to you the IP address of Baidu's homepage. But if there are some problems with DNS resolution at this time, when you want to visit www.baidu.com, it returns the IP address of www.google.com to you. This is what we often call DNS hijacking. Easily confused with this is HTTP hijacking. So what is HTTP hijacking? You must have seen that when you visit a website, a glaring ad pop-up window suddenly pops up in the lower right corner. This is HTTP hijacking. Using the examples in other people's articles, the difference between the two is like
Here are some DNS hijacking methods: 1. Local DNS hijacking The attacker infects the user's computer with a Trojan virus or malware through some means, and then maliciously modifies the local DNS configuration, such as modifying the local hosts file, cache, etc. 2. Router DNS hijacking Many users set the default password of the router by default. Attackers can break into the router administrator account and modify the default configuration of the router. 3. Attacking DNS servers Directly attack the DNS server, such as DDOS attack on the DNS server, which can cause the DNS server to crash, abnormal requests, or use certain means to infect the cache of the DNS server so that the malicious IP address is returned to the user 9. Use of tools dig Command dig is a tool that queries DNS including NS records, A records, MX records and other related information in Unix-like command line mode. Through the dig (parameter: +trace) command, we can see the detailed process of DNS resolution described above From the returned results, we can see several points of information
If you only want to see the results, you can use the +short parameter to directly return which IP addresses www.163.com corresponds to. You can also add an @ parameter to specify a DNS server to query from. If you only want to view specific record types host command The host command can be seen as a simplified version of the dig command, returning various records of the currently requested domain name. whois Command The whois command is used to view the registration status of a domain name. nslookup command nslookup is also a commonly used tool to query DNS resolution results.
You can also specify a public domain name server for query, such as the common 114.114.114.114 10. Manually clear the local cache MacOS
Windows
Linux
This article is reprinted from the WeChat public account "Python Programming Time", which can be followed through the following QR code. To reprint this article, please contact the Python Programming Time public account. |
<<: Researchers develop first 5G switch capable of accessing next-generation wireless speeds
>>: If these five gaps cannot be overcome, 5G 2B will be a pipe dream for operators
The integration of 5G technology is expected to s...
Given the rapid pace of change in the technology ...
According to the latest statistics from Omdia, th...
[51CTO.com original article] In order to pay trib...
With the support of artificial intelligence techn...
[[413903]] This guide shows you how to use Linker...
On May 12, more than 75,000 computer virus attack...
Viavi Solutions Inc. released a new study on June...
1. DDN DDN is the abbreviation of Digital Data Ne...
Recently, Jiangmen Municipal People's Governm...
DogYun is a Chinese hosting company established i...
[The Hague, Netherlands, May 29, 2019] The Mobile...
Biden is hoping to finalize an infrastructure bil...
According to a report by the British "Guardi...
[51CTO.com Shanghai report] The 2017 National Cyb...