跳转至

Sing-box

安装正式版

curl -fsSL https://sing-box.app/install.sh | sh
# or latest beta:
curl -fsSL https://sing-box.app/install.sh | sh -s -- --beta

mkdir -p /var/log/sing-box/

基础信息

程序:
/usr/local/bin/sing-box
/usr/bin/sing-box

配置文件:/etc/sing-box/sing-box_config.json
启用:systemctl enable sing-box
启动:systemctl start sing-box
重启:systemctl restart sing-box
状态:systemctl status sing-box
查看日志:journalctl -u sing-box -o cat -e
实时日志:journalctl -u sing-box -o cat -f

常用命令

# 检查配置文件
sing-box check -c sing-box_config.json
# 生成uuid
sing-box generate uuid

# 生成服务端用的PrivateKey和客户端用的PublicKey
sing-box generate reality-keypair
# 执行完你会看到类似
# PrivateKey 用于服务端,PublicKey用于客户端
PrivateKey: qHtqJLoCGQxeXrJGrP7ZL7KrGBdirFRtACWf3PUuVWo
PublicKey: cuUE-6MT-Rv9_xcTxuXUrwPKeTiZKQhbUx_RsS-0fjw

# 生成short_id: 6ffe6481e83ae953
sing-box generate rand 8 --hex

配置sing-box服务

创建 Systemd 服务文件: 使用您喜欢的文本编辑器创建一个名为 sing-box.service 的文件。您可以使用 nano /etc/systemd/system/sing-box.service 命令来创建这个文件。

[Unit]
After=network.target nss-lookup.target

[Service]
User=root
WorkingDirectory=/root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
ExecStart=/usr/bin/sing-box run -c /etc/sing-box/sing-box_config.json
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=10
LimitNPROC=512
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target

服务端配置

以下配置适用于:sing-box 1.12.0

{
  "log": {
    "disabled": false,
    "level": "info",
    "output": "/var/log/sing-box/sing-box.log",
    "timestamp": true
  },
 "dns": {
    "servers": [
      {
        "tag": "local",
        "type": "local",
        "detour": "direct"
      },
      {
        "tag": "google-doh",
        "type": "https",
        "server": "8.8.8.8"
      }
    ],
    "rules": [
      {
        "domain_suffix": "local",
        "server": "local"
      }
    ],
    "final": "google-doh",
    "strategy": "prefer_ipv4"
  },
  "inbounds": [
    {
      "type": "hysteria2",
      "tag": "hy2-in",
      "listen": "::",
      "listen_port": 1234,
      "users": [
        {
          "name": "user1",
          "password": "f9af8d1c-29b4-4e91-b32d-6a2c9290cac2"
        }
      ],
      "ignore_client_bandwidth": false,
      "tls": {
        "enabled": true,
        "server_name": "wiki.lyricn.com",
        "alpn": ["h3", "h2", "http/1.1"],
        "certificate_path": "/etc/sing-box/server.crt",
        "key_path": "/etc/sing-box/server.key"
      },
      "masquerade": {
        "type": "proxy",
        "url": "https://wiki.lyricn.com",
        "rewrite_host": true
      },
      "brutal_debug": false
    },
    {
      "type": "vless",
      "tag": "vless-in",
      "listen": "::",
      "listen_port": 13443,
      "users": [
          {
              "name": "wiki.lyricn.com",
              "uuid": "f9af8d1c-29b4-4e91-b32d-6a2c9290cac2",
              "flow": "xtls-rprx-vision"
          }
      ],
      "tls": {
          "enabled": true,
          "server_name": "wiki.lyricn.com",
          "reality": {
              "enabled": true,
              "handshake": {
                  "server": "wiki.lyricn.com",
                  "server_port": 443
              },
              "private_key": "qHtqJLoCGQxeXrJGrP7ZL7KrGBdirFRtACWf3PUuVWo",
              "short_id": [
                  "6ffe6481e83ae953"
              ]
          }
      },
      "multiplex": {
          "enabled": false,
          "padding": true,
          "brutal": {
              "enabled": false,
              "up_mbps": 1000,
              "down_mbps": 1000
          }
      }
    },
    {
      "type": "vmess",
      "tag": "vmess-ws-in",
      "listen": "::",
      "listen_port": 51443,
      "users": [
        {
          "name": "user1",
          "uuid": "4f9af8d1c-29b4-4e91-b32d-6a2c9290cac2",
          "alterId": 0
        }
      ],
      "tls": {
        "enabled": true,
        "server_name": "wiki.lyricn.com",   
        "alpn": ["http/1.1"],
        "min_version": "1.2",
        "max_version": "1.3",
        "certificate_path":  "/etc/sing-box/server.crt",
        "key_path": "/etc/sing-box/server.key"
      },
      "transport": {
        "type": "ws",
        "path": "/wiki",
        "max_early_data": 0,
        "early_data_header_name": "Sec-WebSocket-Protocol"
      },
      "multiplex": {
        "enabled": true,
      }
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    }
  ],
  "route": {
    "rules": [
        {
            "protocol": "dns",
            "outbound": "dns"
        },
        {
            "protocol": [
                "bittorrent"
            ],
            "outbound": "block"
        }
    ]
  },
  "experimental": {
      "cache_file": {
          "enabled": true,
          "path": "/etc/sing-box/cache.db"
      }
  }
}

以下配置适用于:sing-box 1.11.0

{
  "log": {
    "disabled": false,
    "level": "info",
    "output": "/var/log/sing-box/sing-box.log",
    "timestamp": true
  },
 "dns": {
    "servers": [
      {
        "tag": "local",
        "address": "local",
        "detour": "direct"
      },
      {
        "tag": "google-doh",
        "address": "https://dns.google/dns-query",
        "detour": "direct",
        "address_resolver": "local"
      },
      {
        "tag": "cloudflare-doh",
        "address": "https://cloudflare-dns.com/dns-query",
        "detour": "direct",
        "address_resolver": "local"
      }
    ],
    "rules": [
      {
        "domain_suffix": "local",
        "server": "local"
      }
    ],
    "final": "google-doh",
    "strategy": "prefer_ipv4"
  },
  "inbounds": [
    {
      "type": "hysteria2",
      "tag": "hy2-in",
      "listen": "::",
      "listen_port": 1234,
      "users": [
        {
          "name": "user1",
          "password": "f9af8d1c-29b4-4e91-b32d-6a2c9290cac2"
        }
      ],
      "ignore_client_bandwidth": false,
      "tls": {
        "enabled": true,
        "server_name": "wiki.lyricn.com",
        "alpn": ["h3", "h2", "http/1.1"],
        "certificate_path": "/etc/sing-box/server.crt",
        "key_path": "/etc/sing-box/server.key"
      },
      "masquerade": {
        "type": "proxy",
        "url": "https://wiki.lyricn.com",
        "rewrite_host": true
      },
      "brutal_debug": false
    },
    {
      "type": "vless",
      "tag": "vless-in",
      "listen": "::",
      "listen_port": 13443,
      "users": [
          {
              "name": "wiki.lyricn.com",
              "uuid": "f9af8d1c-29b4-4e91-b32d-6a2c9290cac2",
              "flow": "xtls-rprx-vision"
          }
      ],
      "tls": {
          "enabled": true,
          "server_name": "wiki.lyricn.com",
          "reality": {
              "enabled": true,
              "handshake": {
                  "server": "wiki.lyricn.com",
                  "server_port": 443
              },
              "private_key": "qHtqJLoCGQxeXrJGrP7ZL7KrGBdirFRtACWf3PUuVWo",
              "short_id": [
                  "6ffe6481e83ae953"
              ]
          }
      },
      "multiplex": {
          "enabled": false,
          "padding": true,
          "brutal": {
              "enabled": false,
              "up_mbps": 1000,
              "down_mbps": 1000
          }
      }
    },
    {
      "type": "vmess",
      "tag": "vmess-ws-in",
      "listen": "::",
      "listen_port": 51443,
      "users": [
        {
          "name": "user1",
          "uuid": "4f9af8d1c-29b4-4e91-b32d-6a2c9290cac2",
          "alterId": 0
        }
      ],
      "tls": {
        "enabled": true,
        "server_name": "wiki.lyricn.com",   
        "alpn": ["http/1.1"],
        "min_version": "1.2",
        "max_version": "1.3",
        "certificate_path":  "/etc/sing-box/server.crt",
        "key_path": "/etc/sing-box/server.key"
      },
      "transport": {
        "type": "ws",
        "path": "/wiki",
        "max_early_data": 0,
        "early_data_header_name": "Sec-WebSocket-Protocol"
      },
      "multiplex": {
        "enabled": true,
      }
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    }, 
    {
        "type": "dns",
        "tag": "dns"
    }
  ],
  "route": {
    "rules": [
        {
            "protocol": "dns",
            "outbound": "dns"
        },
        {
            "protocol": [
                "bittorrent"
            ],
            "outbound": "block"
        }
    ]
  },
  "experimental": {
      "cache_file": {
          "enabled": true,
          "path": "/etc/sing-box/cache.db"
      }
  }
}

注意

如果客户端所有配置都正确,但就是没有速度可能和reality使用的域名有关 `wiki.lyricn.com,请更换域名后重新尝试!

代理地址

www.amazon.com
addons.mozilla.org
www.tesla.com
www.lovelive-anime.jp`
time.is
csgo.com
icook.tw