mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 16:41:30 +00:00
Add documentation and example for linux tun
This commit is contained in:
parent
7f84191748
commit
b417bd5be4
78
docs/configuration/inbound/tun.md
Normal file
78
docs/configuration/inbound/tun.md
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
!!! error ""
|
||||||
|
|
||||||
|
Linux only
|
||||||
|
|
||||||
|
### Structure
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"inbounds": [
|
||||||
|
{
|
||||||
|
"type": "tun",
|
||||||
|
"tag": "tun-in",
|
||||||
|
|
||||||
|
"inet4_address": "172.19.0.1/30",
|
||||||
|
"inet6_address": "fdfe:dcba:9876::1/128",
|
||||||
|
"mtu": 1500,
|
||||||
|
"auto_route": true,
|
||||||
|
"hijack_dns": true,
|
||||||
|
|
||||||
|
"sniff": true,
|
||||||
|
"sniff_override_destination": false,
|
||||||
|
"domain_strategy": "prefer_ipv4"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Tun Fields
|
||||||
|
|
||||||
|
#### inet4_address
|
||||||
|
|
||||||
|
==Required==
|
||||||
|
|
||||||
|
IPv4 prefix for the tun interface.
|
||||||
|
|
||||||
|
#### inet6_address
|
||||||
|
|
||||||
|
IPv6 prefix for the tun interface.
|
||||||
|
|
||||||
|
#### mtu
|
||||||
|
|
||||||
|
The maximum transmission unit.
|
||||||
|
|
||||||
|
#### auto_route
|
||||||
|
|
||||||
|
Set the default route to the Tun.
|
||||||
|
|
||||||
|
!!! error ""
|
||||||
|
|
||||||
|
To avoid traffic loopback, set `route.auto_delect_interface` or `outbound.bind_interface`
|
||||||
|
|
||||||
|
#### hijack_dns
|
||||||
|
|
||||||
|
Hijack TCP/UDP DNS requests to the built-in DNS adapter.
|
||||||
|
|
||||||
|
### Listen Fields
|
||||||
|
|
||||||
|
#### sniff
|
||||||
|
|
||||||
|
Enable sniffing.
|
||||||
|
|
||||||
|
Reads domain names for routing, supports HTTP TLS for TCP, QUIC for UDP.
|
||||||
|
|
||||||
|
This does not break zero copy, like splice.
|
||||||
|
|
||||||
|
#### sniff_override_destination
|
||||||
|
|
||||||
|
Override the connection destination address with the sniffed domain.
|
||||||
|
|
||||||
|
If the domain name is invalid (like tor), this will not work.
|
||||||
|
|
||||||
|
#### domain_strategy
|
||||||
|
|
||||||
|
One of `prefer_ipv4` `prefer_ipv6` `ipv4_only` `ipv6_only`.
|
||||||
|
|
||||||
|
If set, the requested domain name will be resolved to IP before routing.
|
||||||
|
|
||||||
|
If `sniff_override_destination` is in effect, its value will be taken as a fallback.
|
|
@ -6,7 +6,8 @@
|
||||||
"geoip": {},
|
"geoip": {},
|
||||||
"geosite": {},
|
"geosite": {},
|
||||||
"rules": [],
|
"rules": [],
|
||||||
"final": ""
|
"final": "",
|
||||||
|
"auto_detect_interface": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -22,3 +23,13 @@
|
||||||
#### final
|
#### final
|
||||||
|
|
||||||
Default outbound tag. the first outbound will be used if empty.
|
Default outbound tag. the first outbound will be used if empty.
|
||||||
|
|
||||||
|
#### auto_detect_interface
|
||||||
|
|
||||||
|
!!! error ""
|
||||||
|
|
||||||
|
Linux only
|
||||||
|
|
||||||
|
Bind outbound connections to the default NIC by default to prevent routing loops under Tun.
|
||||||
|
|
||||||
|
Takes no effect if `outbound.bind_interface` is set.
|
|
@ -4,3 +4,4 @@ Configuration examples for sing-box.
|
||||||
|
|
||||||
* [Shadowsocks Server](./ss-server)
|
* [Shadowsocks Server](./ss-server)
|
||||||
* [Shadowsocks Client](./ss-client)
|
* [Shadowsocks Client](./ss-client)
|
||||||
|
* [Shadowsocks Tun](./ss-tun)
|
66
docs/examples/ss-tun.md
Normal file
66
docs/examples/ss-tun.md
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"dns": {
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"tag": "google",
|
||||||
|
"address": "tls://8.8.8.8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "local",
|
||||||
|
"address": "223.5.5.5",
|
||||||
|
"detour": "direct"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"domain": "mydomain.com",
|
||||||
|
"geosite": "cn",
|
||||||
|
"server": "local"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"strategy": "ipv4_only"
|
||||||
|
},
|
||||||
|
"inbounds": [
|
||||||
|
{
|
||||||
|
"type": "tun",
|
||||||
|
"inet4_address": "172.19.0.1/30",
|
||||||
|
"auto_route": true,
|
||||||
|
"hijack_dns": true,
|
||||||
|
"sniff": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outbounds": [
|
||||||
|
{
|
||||||
|
"type": "shadowsocks",
|
||||||
|
"tag": "proxy",
|
||||||
|
"server": "mydomain.com",
|
||||||
|
"server_port": 8080,
|
||||||
|
"method": "2022-blake3-aes-128-gcm",
|
||||||
|
"password": "8JCsPssfgS8tiRwiMlhARg=="
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "direct",
|
||||||
|
"tag": "direct"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "block",
|
||||||
|
"tag": "block"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"route": {
|
||||||
|
"rules": [
|
||||||
|
{
|
||||||
|
"geosite": "category-ads-all",
|
||||||
|
"outbound": "block"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"geosite": "cn",
|
||||||
|
"geoip": "cn",
|
||||||
|
"outbound": "direct"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"auto_detect_interface": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
|
@ -40,6 +40,7 @@ nav:
|
||||||
- DNS Rule: configuration/dns/rule.md
|
- DNS Rule: configuration/dns/rule.md
|
||||||
- Inbound:
|
- Inbound:
|
||||||
- configuration/inbound/index.md
|
- configuration/inbound/index.md
|
||||||
|
- Tun: configuration/inbound/tun.md
|
||||||
- Direct: configuration/inbound/direct.md
|
- Direct: configuration/inbound/direct.md
|
||||||
- Mixed: configuration/inbound/mixed.md
|
- Mixed: configuration/inbound/mixed.md
|
||||||
- Socks: configuration/inbound/socks.md
|
- Socks: configuration/inbound/socks.md
|
||||||
|
@ -61,6 +62,7 @@ nav:
|
||||||
- examples/index.md
|
- examples/index.md
|
||||||
- Shadowsocks Server: examples/ss-server.md
|
- Shadowsocks Server: examples/ss-server.md
|
||||||
- Shadowsocks Client: examples/ss-client.md
|
- Shadowsocks Client: examples/ss-client.md
|
||||||
|
- Shadowsocks Tun: examples/ss-tun.md
|
||||||
- Benchmark: benchmark.md
|
- Benchmark: benchmark.md
|
||||||
markdown_extensions:
|
markdown_extensions:
|
||||||
- pymdownx.inlinehilite
|
- pymdownx.inlinehilite
|
||||||
|
|
|
@ -69,7 +69,7 @@ func (r *Rule) UnmarshalJSON(bytes []byte) error {
|
||||||
}
|
}
|
||||||
var v any
|
var v any
|
||||||
switch r.Type {
|
switch r.Type {
|
||||||
case "":
|
case "", C.RuleTypeDefault:
|
||||||
r.Type = C.RuleTypeDefault
|
r.Type = C.RuleTypeDefault
|
||||||
v = &r.DefaultOptions
|
v = &r.DefaultOptions
|
||||||
case C.RuleTypeLogical:
|
case C.RuleTypeLogical:
|
||||||
|
|
Loading…
Reference in a new issue