553 字
3 分钟
自建代理
2026-04-29
做这个之前先进行安全防护
此教程以sing-box代理服务端和vless-reality为例
vless-reality是当前代理协议中综合实力最强的,无需域名、证书
开启bbr
sudo cat<<EOF >> /etc/sysctl.confnet.core.default_qdisc = fqnet.ipv4.tcp_congestion_control = bbrnet.ipv4.tcp_mtu_probing = 1net.ipv4.tcp_slow_start_after_idle = 0net.ipv4.tcp_syncookies = 1EOF
# 载入规则sudo sysctl -p安装代理服务端
sudo mkdir -p /etc/apt/keyrings && sudo curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.asc && sudo chmod a+r /etc/apt/keyrings/sagernet.asc && echo 'Types: debURIs: https://deb.sagernet.org/Suites: *Components: *Enabled: yesSigned-By: /etc/apt/keyrings/sagernet.asc' | sudo tee /etc/apt/sources.list.d/sagernet.sources && sudo apt-get update && sudo apt-get install sing-box生成密钥、UUID、short-id
这三个要保存好,配置文件要用
# 生成sing-box的PrivateKey和PublicKeysudo sing-box generate reality-keypair# 生成UUIDcat /proc/sys/kernel/random/uuid# 生成8位short-idopenssl rand -hex 8开放端口
ssh端口总数为65536,范围0~65535
使用随机高端口,最好是20000以上;实在不知道用哪个使用以下命令来生成
Terminal window shuf -i 1024-65535 -n 1
sudo ufw allow 26375/tcpsudo ufw reload配置信息
sudo vim /etc/sing-box/config.json使用以下内容替换掉原有内容
{ "log": { "level": "warn", "timestamp": true }, "inbounds": [ { "type": "vless", "tag": "in-vless-reality", "listen": "0.0.0.0", "listen_port": [随机端口],
"reuse_addr": true, "tcp_fast_open": true,
"users": [ { "name": "client", "uuid": "你的uuid", "flow": "xtls-rprx-vision" } ], "tls": { "enabled": true, "server_name": "www.cloudflare.com", "alpn": ["h2", "http/1.1"], "reality": { "enabled": true, "handshake": { "server": "www.cloudflare.com", "server_port": 443 }, "private_key": "[你的私钥]", "short_id": ["[你的short-id]"] } } } ], "dns": { "servers": [ { "type": "local", "tag": "local" }, { "type": "https", "tag": "cf", "server": "1.1.1.1" } ], "strategy": "prefer_ipv6", "final": "local", "cache_capacity": 4096 }, "outbounds": [ { "type": "direct", "tag": "direct" } ], "route": { "default_domain_resolver": { "server": "local", "strategy": "prefer_ipv6" }, "rules": [ { "ip_is_private": true, "action": "reject" }, { "protocol": "bittorrent", "action": "reject" } ], "final": "direct" }}使用上面的随机高端口、私钥、uuid、short-id替换掉配置中的相关信息
像这样"listen_port": [随机端口], —> "listen_port": 26375,
使用以下命令检验配置文件是否有语法错误
sudo sing-box check -c /etc/sing-box/config.json启动服务
# 设置开机自启sudo systemctl enable sing-box# 启动服务sudo systemctl start sing-box# 查看服务状态sudo systemctl status sing-box代理链接
vless://[UUID]@[服务器IP]:[端口]?type=tcp&encryption=none&security=reality&flow=xtls-rprx-vision&sni=www.cloudflare.com&fp=chrome&pbk=[公钥]&sid=[short-id]#节点名字使用生成的公钥、uuid、服务器ip、sing-box端口、公钥、short-id替换[相关内容]
测试
在[V2rayN](2dust/v2rayN: A GUI client for Windows, Linux and macOS, support Xray and sing-box and others)软件里导入测试是否连通