Are you an LLM? You can read better optimized documentation at /zh-TW\tutorial\dns.md for this page in Markdown format
Clash DNS
由於 Clash 的某些部分運行在第 3 層 (網絡層) , 因此其數據包的域名是無法獲取的, 也就無法進行基於規則的路由.
Enter fake-ip: 它支持基於規則的路由, 最大程度地減少了 DNS 汙染攻擊的影響, 並且提高了網絡性能, 有時甚至是顯著的.
fake-ip
"fake IP" 的概念源自 RFC 3089:
一個 "fake IP" 地址被用於查詢相應的 "FQDN" 信息的關鍵字.fake-ip 池的默認 CIDR 是
198.18.0.1/16(一個保留的 IPv4 地址空間, 可以在dns.fake-ip-range中進行更改).當 DNS 請求被髮送到 Clash DNS 時, Clash 內核會通過管理內部的域名和其 fake-ip 地址的映射, 從池中分配一個 空閒 的 fake-ip 地址.
以使用瀏覽器訪問
http://google.com為例.瀏覽器向 Clash DNS 請求
google.com的 IP 地址Clash 檢查內部映射並返回
198.18.1.5瀏覽器向
198.18.1.5的80/tcp端口發送 HTTP 請求當收到
198.18.1.5的入站數據包時, Clash 查詢內部映射, 發現客戶端實際上是在向google.com發送數據包根據規則的不同:
- Clash 可能僅將域名發送到 SOCKS5 或 shadowsocks 等出站代理, 並與代理服務器建立連接
- 或者 Clash 可能會基於
SCRIPT、GEOIP、IP-CIDR規則或者使用 DIRECT 直連出口查詢google.com的真實 IP 地址
由於這是一個令人困惑的概念, 我將以使用 cURL 程序訪問
http://google.com為例:
bash
$ curl -v http://google.com
<---- cURL 向您的系統 DNS (Clash) 詢問 google.com 的 IP 地址
----> Clash 決定使用 198.18.1.70 作為 google.com 的 IP 地址, 並記住它
* Trying 198.18.1.70:80...
<---- cURL 連接到 198.18.1.70 tcp/80
----> Clash 將立即接受連接, 並且..
* Connected to google.com (198.18.1.70) port 80 (#0)
----> Clash 在其內存中查找到 198.18.1.70 對應於 google.com
----> Clash 查詢對應的規則, 並通過匹配的出口發送數據包
> GET / HTTP/1.1
> Host: google.com
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Location: http://www.google.com/
< Content-Type: text/html; charset=UTF-8
< Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-ahELFt78xOoxhySY2lQ34A' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
< Date: Thu, 11 May 2023 06:52:19 GMT
< Expires: Sat, 10 Jun 2023 06:52:19 GMT
< Cache-Control: public, max-age=2592000
< Server: gws
< Content-Length: 219
< X-XSS-Protection: 0
< X-Frame-Options: SAMEORIGIN
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>
* Connection #0 to host google.com left intact