2023年6月11日星期日

sing-box搭建naive节点,支持自定义端口、多用户、安全、稳定、超快速4k秒开

 

特别鸣谢

Mr.Xiao


前期准备:

1. VPS

2. 域名

3. Cloudflare


操作步骤:


0. 解析域名











1. 更新软件源及安装依赖

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


2. 安装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 && go version







3. 编译安装sing-box

go install -v -tags \

with_quic,\

with_dhcp,\

with_ech,\

with_utls,\

with_acme \

github.com/sagernet/sing-box/cmd/sing-box@latest











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

cp ~/go/bin/sing-box /usr/local/bin/


5. 为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









6. 创建sing-box文件夹

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


7. 创建sing-box配置文件

touch config.json


8. 配置信息

{

  "log": {

    "level": "warn",

    "timestamp": true

  },

  "inbounds": [

    {

      "type": "naive",

      "tag": "naive-in",

      "network": "tcp",  

      "listen": "::",

      "listen_port": 2345,   //监听端口

      "tcp_fast_open": true,

      "sniff": true,

      "sniff_override_destination": true,

      "users": [

        {

          "username": "test1",   //用户名

          "password": "test2"     //密码

        }

      ],

      "tls": {

        "enabled": true,

        "server_name": "mydomain.com",   //解析的域名

        "acme": {

          "domain": [

            "mydomain.com"   //解析的域名

          ],

          "data_directory": "/usr/local/etc/sing-box",

          "email": "email@gmail.com",

          "provider": "letsencrypt"

        } 

      }

    }

  ],

  "outbounds": [

    {

      "type": "direct",

      "tag": "direct"

    },    

    {

      "type": "block",

      "tag": "block"

    }

  ]

}

#多用户配置

  "users": [ 

      { 

        "username": "xiao001",   //用户名

         "password": "xiao123"  //密码

       }, 

      { 

        "username": "xiao002",   //用户名

         "password": "xiao456"  //密码

       }

     ],


9. 测试配置文件是否有效

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








10. 启动并设置sing-box为开机自启

systemctl enable --now sing-box


11. 查看sing-box启动状态

systemctl status sing-box


12. 在本地电脑上,新建一个.json后缀的文件,在文件中添加以下配置,并且保存

#v2rayN配置示例

{

"listen": "socks://127.0.0.1:1080",

"proxy": "https://xiao001(用户名):xiao123(密码)@mydomain.com(解析的域名):2345(设置的端口号)"

}


13. 打开V2rayN

1)打开"服务器"









2) 添加自定义配置服务器












3)添加刚才的json文件

4)core类型选择naiveproxy

5)Socks端口写1080,点击确定!!


没有评论:

发表评论