sing-box搭建vless-xtls-vision-reality

1、开启BBR加速

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p

2、更新软件源及安装依赖

apt update && apt -y install wget git libc6-dev build-essential zlib1g-dev libssl-dev libevent-dev mingw-w64

3、安装go

wget -c https://go.dev/dl/go1.20.3.linux-amd64.tar.gz -O - | tar -xz -C /usr/local
echo 'export PATH=$PATH:/usr/local/go/bin' > /etc/profile
source /etc/profile

4、编译安装sing-box

go install -v -tags \
with_quic,\
with_grpc,\
with_dhcp,\
with_wireguard,\
with_shadowsocksr,\
with_ech,\
with_utls,\
with_reality_server,\
with_acme,\
with_clash_api,\
with_v2ray_api,\
with_gvisor,\
with_lwip \
github.com/sagernet/sing-box/cmd/sing-box@latest

5、复制编译好的sing-box到/usr/local/bin/目录

cp ~/go/bin/sing-box /usr/local/bin/
可能不成功。用下面命令:
wget https://github.com/SagerNet/sing-box/releases/download/v1.2.4/sing-box_1.2.4_linux_arm64.deb
dpkg -i sing-box_1.2.4_linux_amd64.deb
cp /usr/bin/sing-box /usr/local/bin/

6、为sing-box配置开机自启服务

cat > /etc/systemd/system/sing-box.service <<EOF


[Unit]
Description=sing-box service
Documentation=https://sing-box.sagernet.org
After=network.target nss-lookup.target
[Service]
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
ExecStart=/usr/local/bin/sing-box run -c /usr/local/etc/sing-box/config.json
Restart=on-failure
RestartSec=1800s
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
EOF

7、创建sing-box文件夹创建sing-box配置文件

mkdir /usr/local/etc/sing-box && cd $_

touch config.json
{
  "log": {
    "level": "info",
    "timestamp": true
  },
  "dns": {
    "servers": [
      { 
        "tag": "local",
        "address": "https://1.1.1.1/dns-query",
        "detour": "direct"
      },
      {
        "tag": "block",
        "address": "rcode://success"
      }
    ],
    "rules": [
      { 
        "geosite": "cn",
        "server": "local"
      },
      {
        "geosite": "category-ads-all",
        "server": "block",
        "disable_cache": true
      }
    ]
  },
  "inbounds": [
    {
      "type": "vless",
      "tag": "vless-in",
      "listen": "::",
      "listen_port": 10010, //监听端口
      "users": [
        {
          "uuid": "bf000d23-0752-40b4-affe-68f7707a9661", //执行 sing-box generate uuid 生成
          "flow": "xtls-rprx-vision"
        }
      ],
      "tls": {
        "enabled": true,
        "server_name": "www.microsoft.com", //客户端可用的 serverName 列表,暂不支持 * 通配符
        "reality": {
          "enabled": true,
          "handshake": {
            "server": "www.microsoft.com", //目标网站,标准:国外网站,支持 TLSv1.3 与 H2
            "server_port": 443
          },
          "private_key": "UuMBgl7MXTPx9inmQp2UC7Jcnwc6XYbwDNebonM-FCc", // 执行 sing-box generate reality-keypair 生成
          "short_id": [ //客户端可用的 shortId 列表,可用于区分不同的客户端
            "0123456789abcdef" //执行 openssl rand -hex 8 生成或留空
          ]
        }
      }
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    },
    {
      "type": "block",
      "tag": "block"
    }
  ],
  "route": {
    "rules": [
      {
        "geosite": "cn",
        "geoip": "cn",
        "outbound": "direct"
      },
      {
        "geosite": "category-ads-all",
        "outbound": "block"
      }
    ]
  }
}

8、测试配置文件是否有效

/usr/local/bin/sing-box run -c /usr/local/etc/sing-box/config.json

9、启动并设置sing-box为开机自启

systemctl enable --now sing-box

10、查看sing-box启动状态

systemctl status sing-box

#Clash配置示例

- name: vless
  type: vless
  server: x.x.x.x  #ip地址
  port: 10018  #端口
  uuid: 0cd4ef7d-2d2b-4cc0-abba-57b6322e7575  #UUID
  network: tcp
  udp: true
  tls: true
  flow: xtls-rprx-vision
  servername: www.microsoft.com  #服务端server_nam
  client-fingerprint: chrome
  reality-opts:
    public-key: ajBkMYVvF14hVLPw1cKwyMzHdAj7Rg6L6MyMg6btYV8  #服务端私钥对应的公钥
    short-id: 0123456789abcdef  #服务端short_id

目标网站是否符合标准检查网站
https://www.ssllabs.com/ssltest/

VLESS-XTLS-Vision-uTLS-REALITY,完美解决TLS指纹问题,安全稳定。

本配置TLS 由 REALITY 取代,可消除服务端 TLS 指纹特征,仍有前向保密性等,且证书链攻击无效,安全性超越常规 TLS。可指向别人的网站,无需自己买域名、配置 TLS 服务端,更方便,实现向中间人呈现指定 SNI 的全程真实 TLS,可解决 SNI 名单阻断问题。

#安装并将 Xray-core 升级到预发布版本

bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install --version 1.8.0

#修改Xray配置信息(/usr/local/etc/xray/config.json)

{
  "log": {
    "loglevel": "warning"
  },
  "inbounds": [ 
    {
      "listen": "0.0.0.0",
      "port": 443, //监听端口
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "uuid", //执行xray uuid生成
            "flow": "xtls-rprx-vision" //启用XTLS Vision
          }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "tcp",
        "security": "reality",
        "realitySettings": {
          "show": false, // 选填,若为 true,输出调试信息
          "dest": "www.microsoft.com:443", //转发给自己设定的目标网站
          "xver": 0, //选填,默认关闭PROXY protocol发送
          "serverNames": [ // 必填,客户端可用的 serverName 列表,暂不支持 * 通配符
            "www.microsoft.com" //修改为目标网站的域名
          ],
          "privateKey": "ILdQxyQYfeI2ZE0NXTDtbUjsdYAYk6EmPVoDSJMsz2A", //修改为执行xray x25519后生成的私钥。
          "minClientVer": "1.8.0", //客户端 Xray 最低版本
          "shortIds": [ 
            "a3f9df45ae15d6c2" //若有此项,客户端shortId可为空。若不为空,可0到f(0123456789abcdef),长度为2的倍数,长度上限为16。执行:openssl rand -hex 8
          ]
        }
      },
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      }
    }
  ],
  "routing": {
    "rules": [
      {
        "type": "field",
        "protocol": [
          "bittorrent"
        ],
        "outboundTag": "blocked",
        "ip": [
          "geoip:cn",
          "geoip:private"
        ] 
      }
    ]
  },
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    },
    {
    "tag": "blocked",
      "protocol": "blackhole",
      "settings": {}
    }
  ]
}

#目标网站最低标准:国外网站,支持 TLSv1.3 与 H2,域名非跳转。目标网站是否符合标准检查网站:https://www.ssllabs.com/ssltest/

#win版本客户端下载地址:https://github.com/2dust/v2rayN/releases

#安卓客户端下载地址:https://github.com/2dust/v2rayNG/releases

#Xray-core下载地址:https://github.com/XTLS/Xray-core/releases