官方站点:https://sing-box.sagernet.org/zh/
使用版本:1.7.8
安装Ubuntu:bash <(curl -fsSL https://sing-box.app/deb-install.sh)
安装Centos:bash <(curl -fsSL https://sing-box.app/rpm-install.sh)
服务管理
对于带有 systemd 的 Linux 系统,通常安装已经包含 sing-box 服务, 您可以使用以下命令管理服务:
行动 | 命令 |
---|---|
启用 | sudo systemctl enable sing-box |
禁用 | sudo systemctl disable sing-box |
启动 | sudo systemctl start sing-box |
停止 | sudo systemctl stop sing-box |
强行停止 | sudo systemctl kill sing-box |
重新启动 | sudo systemctl restart sing-box |
查看日志 | sudo journalctl -u sing-box --output cat -e |
实时日志 | sudo journalctl -u sing-box --output cat -f |
geo.db目录 | /var/lib/sing-box/ |
配置路径 | /etc/sing-box/ |
Client端配置(IPv4分流、Tun模式、支持atv旁路、支持atv组播)
{
"log": {
"level": "warn",
"timestamp": true
},
"dns": {
"servers": [
{
"tag": "localDns",
"address": "tls://223.6.6.6",
"detour": "direct"
},
{
"tag": "proxyDns",
"address": "tls://8.8.4.4",
"detour": "h2-out"
},
{
"tag": "block",
"address": "rcode://success"
}
],
"rules": [
{
"domain_suffix": [
"??.???",
"???.??"
],
"server": "localDns"
},
{
"clash_mode": "Direct",
"server": "localDns"
},
{
"clash_mode": "Global",
"server": "proxyDns"
},
{
"geosite": "category-ads-all",
"server": "block"
},
{
"geosite": "private",
"server": "block"
},
{
"type": "logical",
"mode": "and",
"rules": [
{
"geosite": "geolocation-!cn",
"invert": true
},
{
"geosite": [
"cn",
"category-companies@cn"
]
}
],
"server": "localDns"
},
{
"geosite": [
"apple",
"geolocation-cn",
"category-games@cn"
],
"server": "localDns"
},
{
"geosite": [
"category-porn",
"geolocation-!cn"
],
"server": "proxyDns"
}
],
"final": "localDns",
"strategy": "ipv4_only"
},
"inbounds": [
{
"type": "tun",
"inet4_address": "172.19.0.1/30",
"auto_route": true,
"inet4_route_exclude_address": "224.0.0.0/4",
"sniff": true,
"sniff_override_destination": true
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "trojan",
"tag": "h2-out",
"server": "???.??",
"server_port": 6443,
"password": "uiVUMG4WJ7NKpFYwqz7lsA==",
"tls": {
"enabled": true,
"server_name": "???.??",
"utls": {
"enabled": true,
"fingerprint": "safari"
}
},
"multiplex": {
"enabled": true
}
},
{
"type": "block",
"tag": "block"
},
{
"type": "dns",
"tag": "dns-out"
}
],
"route": {
"geoip": {
"download_url": "https://github.com/lyc8503/sing-box-rules/releases/latest/download/geoip.db",
"download_detour": "h2-out"
},
"geosite": {
"download_url": "https://github.com/Raudeck/v2fly-domains/releases/latest/download/geosite.db",
"download_detour": "h2-out"
},
"rules": [
{
"type": "logical",
"mode": "or",
"rules": [
{
"protocol": "dns"
},
{
"port": 53
}
],
"outbound": "dns-out"
},
{
"geoip": "private",
"outbound": "direct"
},
{
"clash_mode": "Direct",
"outbound": "direct"
},
{
"clash_mode": "Global",
"outbound": "h2-out"
},
{
"type": "logical",
"mode": "or",
"rules": [
{
"port": 853
},
{
"network": "udp",
"port": 443
},
{
"protocol": "stun"
}
],
"outbound": "block"
},
{
"geosite": "category-ads-all",
"outbound": "block"
},
{
"type": "logical",
"mode": "and",
"rules": [
{
"geosite": "geolocation-!cn",
"invert": true
},
{
"geosite": [
"cn",
"category-companies@cn"
],
"geoip": "cn"
}
],
"outbound": "direct"
},
{
"geosite": [
"geolocation-cn",
"apple"
],
"outbound": "direct"
},
{
"domain_suffix": "??.???",
"geosite": [
"category-porn",
"geolocation-!cn"
],
"geoip": [
"telegram",
"fastly",
"twitter",
"google",
"netflix",
"facebook"
],
"outbound": "h2-out"
}
],
"final": "direct",
"auto_detect_interface": true
}
}
server端配置(示例hysteria2与trojan两种协议)
{
"log": {
"level": "warn",
"timestamp": true
},
"inbounds": [
{
"type": "hysteria2",
"listen": "::",
"listen_port": 8443,
"up_mbps": 30,
"down_mbps": 100,
"users": [
{
"name": "admin",
"password": "uiVUMG4WJ7NKpFYwqz7lsA=="
}
],
"tls": {
"enabled": true,
"server_name": "???.??",
"certificate_path": "/etc/sing-box/???_bundle.crt",
"key_path": "/etc/sing-box/???.key"
}
},
{
"type": "trojan",
"listen": "::",
"listen_port": 6443,
"users": [
{
"name": "trojan",
"password": "uiVUMG4WJ7NKpFYwqz7lsA=="
}
],
"tls": {
"enabled": true,
"server_name": "???.??",
"certificate_path": "/etc/sing-box/???_bundle.crt",
"key_path": "/etc/sing-box/???.key"
},
"multiplex": {
"enabled": true
}
}
]
}
http与socks5代理配置
{
"log": {
"level": "warn",
"timestamp": true
},
"dns": {
"servers": [
{
"tag": "google",
"address": "tls://dns.google",
"address_resolver": "114",
"detour": "proxy"
},
{
"tag": "localDns",
"address": "h3://dns.alidns.com/dns-query",
"address_resolver": "114",
"detour": "direct"
},
{
"tag": "114",
"address": "114.114.114.114",
"detour": "direct"
},
{
"tag": "remote",
"address": "fakeip",
"detour": "proxy"
},
{
"tag": "block",
"address": "rcode://success"
}
],
"rules": [
{
"geosite": "category-ads-all",
"server": "block"
},
{
"domain_suffix": "???.??",
"server": "localDns"
},
{
"geosite": [
"cn",
"apple",
"private",
"geolocation-cn",
"category-games@cn"
],
"server": "localDns"
},
{
"query_type": [
"A",
"AAAA"
],
"server": "remote"
}
],
"fakeip": {
"enabled": true,
"inet4_range": "198.18.0.0/15",
"inet6_range": "fc00::/18"
}
},
"inbounds": [
{
"type": "mixed",
"tag": "mixed-in",
"listen": "::",
"listen_port": 1080,
"sniff": true,
"sniff_override_destination": true
}
],
"outbounds": [
{
"type": "trojan",
"tag": "proxy",
"server": "???.??",
"server_port": 6443,
"password": "uiVUMG4WJ7NKpFYwqz7lsA==",
"tls": {
"enabled": true,
"server_name": "???.??",
"utls": {
"enabled": true,
"fingerprint": "edge"
}
},
"multiplex": {
"enabled": true
}
},
{
"type": "direct",
"tag": "direct"
},
{
"type": "block",
"tag": "block"
},
{
"type": "dns",
"tag": "dns-out"
}
],
"route": {
"geoip": {
"download_url": "https://github.com/lyc8503/sing-box-rules/releases/latest/download/geoip.db",
"download_detour": "proxy"
},
"geosite": {
"download_url": "https://github.com/Raudeck/v2fly-domains/releases/latest/download/geosite.db",
"download_detour": "proxy"
},
"rules": [
{
"type": "logical",
"mode": "or",
"rules": [
{
"protocol": "dns"
},
{
"port": 53
}
],
"outbound": "dns-out"
},
{
"type": "logical",
"mode": "or",
"rules": [
{
"port": 853
},
{
"network": "udp",
"port": 443
},
{
"protocol": "stun"
}
],
"outbound": "block"
},
{
"geosite": "category-ads-all",
"outbound": "block"
},
{
"inbound": "mixed-in",
"domain_suffix": "?.?",
"geosite": [
"cn",
"apple",
"private",
"geolocation-cn",
"category-games@cn"
],
"geoip": [
"private",
"cn"
],
"ip_cidr": "?.?.?.?/24",
"outbound": "direct"
},
{
"geosite": [
"geolocation-!cn",
"category-porn"
],
"outbound": "proxy"
}
]
}
}