正在加载...
553 字
3 分钟
自建代理
2026-04-29

做这个之前先进行安全防护

此教程以sing-box代理服务端和vless-reality为例

vless-reality是当前代理协议中综合实力最强的,无需域名、证书

开启bbr#

Terminal window
sudo cat<<EOF >> /etc/sysctl.conf
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_mtu_probing = 1
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_syncookies = 1
EOF
# 载入规则
sudo sysctl -p

安装代理服务端#

Terminal window
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: deb
URIs: https://deb.sagernet.org/
Suites: *
Components: *
Enabled: yes
Signed-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#

这三个要保存好,配置文件要用

Terminal window
# 生成sing-box的PrivateKey和PublicKey
sudo sing-box generate reality-keypair
# 生成UUID
cat /proc/sys/kernel/random/uuid
# 生成8位short-id
openssl rand -hex 8

开放端口#

ssh端口总数为65536,范围0~65535

使用随机高端口,最好是20000以上;实在不知道用哪个使用以下命令来生成

Terminal window
shuf -i 1024-65535 -n 1
Terminal window
sudo ufw allow 26375/tcp
sudo ufw reload

配置信息#

Terminal window
sudo vim /etc/sing-box/config.json

使用以下内容替换掉原有内容

Terminal window
{
"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,

使用以下命令检验配置文件是否有语法错误

Terminal window
sudo sing-box check -c /etc/sing-box/config.json

启动服务#

Terminal window
# 设置开机自启
sudo systemctl enable sing-box
# 启动服务
sudo systemctl start sing-box
# 查看服务状态
sudo systemctl status sing-box

代理链接#

Terminal window
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)软件里导入测试是否连通

自建代理
https://blog.vian.im/自建代理/
作者
woioeow
发布于
2026-04-29
许可协议
CC BY-NC-SA 4.0