Преглед изворни кода

documentation: Fix missing hosts DNS server

世界 пре 7 месеци
родитељ
комит
c51e9cbe06
3 измењених фајлова са 74 додато и 1 уклоњено
  1. 3 1
      dns/transport/hosts/hosts.go
  2. 70 0
      docs/configuration/dns/server/hosts.md
  3. 1 0
      mkdocs.yml

+ 3 - 1
dns/transport/hosts/hosts.go

@@ -2,12 +2,14 @@ package hosts
 
 import (
 	"context"
+	"os"
 
 	"github.com/sagernet/sing-box/adapter"
 	C "github.com/sagernet/sing-box/constant"
 	"github.com/sagernet/sing-box/dns"
 	"github.com/sagernet/sing-box/log"
 	"github.com/sagernet/sing-box/option"
+	"github.com/sagernet/sing/service/filemanager"
 
 	mDNS "github.com/miekg/dns"
 )
@@ -29,7 +31,7 @@ func NewTransport(ctx context.Context, logger log.ContextLogger, tag string, opt
 		files = append(files, NewFile(DefaultPath))
 	} else {
 		for _, path := range options.Path {
-			files = append(files, NewFile(path))
+			files = append(files, NewFile(filemanager.BasePath(ctx, os.ExpandEnv(path))))
 		}
 	}
 	return &Transport{

+ 70 - 0
docs/configuration/dns/server/hosts.md

@@ -0,0 +1,70 @@
+---
+icon: material/new-box
+---
+
+!!! question "Since sing-box 1.12.0"
+
+# Hosts
+
+### Structure
+
+```json
+{
+  "dns": {
+    "servers": [
+      {
+        "type": "hosts",
+        "tag": "",
+
+        "path": [],
+        "predefined": {}
+      }
+    ]
+  }
+}
+```
+
+!!! note ""
+
+    You can ignore the JSON Array [] tag when the content is only one item
+
+### Fields
+
+#### path
+
+List of paths to hosts files.
+
+`/etc/hosts` is used by default.
+
+`C:\Windows\System32\Drivers\etc\hosts` is used by default on Windows.
+
+Example:
+
+```json
+{
+  // "path": "/etc/hosts"
+  
+  "path": [
+    "/etc/hosts",
+    "$HOME/.hosts"
+  ]
+}
+```
+
+#### predefined
+
+Predefined hosts.
+
+Example:
+
+```json
+{
+  "predefined": {
+    "www.google.com": "127.0.0.1",
+    "localhost": [
+      "127.0.0.1",
+      "::1"
+    ]
+  }
+}
+```

+ 1 - 0
mkdocs.yml

@@ -84,6 +84,7 @@ nav:
               - configuration/dns/server/index.md
               - Legacy: configuration/dns/server/legacy.md
               - Local: configuration/dns/server/local.md
+              - Hosts: configuration/dns/server/hosts.md
               - TCP: configuration/dns/server/tcp.md
               - UDP: configuration/dns/server/udp.md
               - TLS: configuration/dns/server/tls.md