documentation: Fix missing hosts DNS server

This commit is contained in:
世界 2025-02-24 18:17:11 +08:00
parent e7ad8d294d
commit 331edbacff
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 74 additions and 1 deletions

View file

@ -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{

View file

@ -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"
]
}
}
```

View file

@ -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