阿里云VPS打造家庭网络中枢:内网穿透+远程桌面+代理一站式搭建
- Published on
- ...
- Authors

- Name
- Huashan
- @herohuashan
前言
作为一名有NAS和家庭服务器的用户,经常需要在外部访问家里的各种服务。本文将介绍如何利用一台阿里云轻量级VPS(2核1.6G内存),搭建一套完整的家庭网络中枢,包括:
- FRP 内网穿透 - 让家里的服务可以从公网访问
- RustDesk 自托管 - 开源远程桌面方案
- ShellCrash 透明代理 - 解决VPS访问境外资源问题
- Tailscale DERP 中继 - 加速Tailscale组网
- Nginx 反向代理 + SSL - 为内网穿透服务添加域名和HTTPS
💡 为什么选择阿里云上海节点? 地理位置接近家庭网络,延迟低(通常小于30ms),非常适合作为内网穿透的中转服务器。
服务器基础配置
系统环境
系统:Ubuntu 22.04.5 LTS
CPU:2核 Intel Xeon Platinum
内存:1.6GB
硬盘:40GB SSD
初始化设置
# 更新系统
apt update && apt upgrade -y
# 安装基础工具
apt install -y curl wget git vim htop net-tools
# 安装 Docker
curl -fsSL https://get.docker.com | sh
systemctl enable docker
systemctl start docker
一、FRP 内网穿透
FRP (Fast Reverse Proxy) 是一款高性能的反向代理应用,可以帮助你将内网服务暴露到公网。
1.1 安装 FRP 服务端
# 下载最新版 FRP
wget https://github.com/fatedier/frp/releases/download/v0.62.1/frp_0.62.1_linux_amd64.tar.gz
tar -xzf frp_0.62.1_linux_amd64.tar.gz
mv frp_0.62.1_linux_amd64 /opt/frp
1.2 配置 frps.toml
mkdir -p /etc/frp
cat > /etc/frp/frps.toml << 'EOF'
bindPort = 7000
vhostHTTPPort = 8081
auth.method = "token"
auth.token = "你的安全密钥"
webServer.addr = "0.0.0.0"
webServer.port = 81
webServer.user = "admin"
webServer.password = "你的管理密码"
EOF
1.3 创建系统服务
cat > /etc/systemd/system/frps.service << 'EOF'
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/frp/frps -c /etc/frp/frps.toml
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl enable frps
systemctl start frps
1.4 客户端配置示例
在你的家庭 NAS 或服务器上配置 frpc:
# frpc.toml
serverAddr = "VPS公网IP"
serverPort = 7000
auth.token = "你的安全密钥"
# 映射 SubStore 服务
[[proxies]]
name = "substore"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3000
remotePort = 3003
# 映射 SSH
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 2222
1.5 开放防火墙端口
在阿里云安全组中开放以下端口:
| 端口 | 协议 | 用途 |
|---|---|---|
| 7000 | TCP | FRP 主端口 |
| 8081 | TCP | HTTP vhost |
| 81 | TCP | FRP Dashboard |
| 3003 | TCP | SubStore (示例) |
| 2222 | TCP | SSH (示例) |
二、RustDesk 自托管远程桌面
RustDesk 是一款开源的远程桌面软件,可以完全自托管,不依赖任何第三方服务。
2.1 使用 Docker 部署
# 创建目录
mkdir -p /opt/rustdesk
# 运行 hbbs (ID/信号服务器)
docker run --name hbbs \
-d --restart always \
-p 21115:21115 \
-p 21116:21116 \
-p 21116:21116/udp \
-p 21118:21118 \
-v /opt/rustdesk:/root \
rustdesk/rustdesk-server:latest \
hbbs -r VPS公网IP
# 运行 hbbr (中继服务器)
docker run --name hbbr \
-d --restart always \
-p 21117:21117 \
-p 21119:21119 \
-v /opt/rustdesk:/root \
rustdesk/rustdesk-server:latest \
hbbr
2.2 客户端配置
- 下载 RustDesk 客户端
- 进入设置 → 网络 → ID/中继服务器
- 填入:
- ID服务器:
VPS公网IP - 中继服务器:
VPS公网IP - Key:查看
/opt/rustdesk/id_ed25519.pub
- ID服务器:
2.3 开放端口
| 端口 | 协议 | 用途 |
|---|---|---|
| 21115 | TCP | NAT 类型测试 |
| 21116 | TCP/UDP | ID 注册和心跳 |
| 21117 | TCP | 中继 |
| 21118/21119 | TCP | WebSocket |
三、Tailscale DERP 中继服务器
如果你使用 Tailscale 组网,自建 DERP 服务器可以大幅降低国内节点间的延迟。
3.1 Docker 部署
docker run --restart always \
--name derper \
-d \
-p 59443:443 \
-p 3478:3478/udp \
ghcr.io/yangchuansheng/ip_derper:latest
3.2 Tailscale ACL 配置
在 Tailscale 管理控制台的 ACL 中添加:
"derpMap": {
"OmitDefaultRegions": false,
"Regions": {
"901": {
"RegionID": 901,
"RegionCode": "sh",
"RegionName": "Shanghai Aliyun",
"Nodes": [{
"Name": "901",
"RegionID": 901,
"HostName": "VPS公网IP",
"DERPPort": 59443,
"IPv4": "VPS公网IP",
"InsecureForTests": true,
"STUNPort": 3478
}]
}
}
}
四、ShellCrash 透明代理
VPS 需要访问 Docker Hub、GitHub 等境外资源时,透明代理非常有用。
4.1 安装 ShellCrash
# 安装
export url='https://fastly.jsdelivr.net/gh/juewuy/ShellCrash@master' && sh -c "$(curl -kfsSl $url/install.sh)" && source /etc/profile &> /dev/null
4.2 配置订阅
运行 crash 命令,进入交互式配置:
- 选择
6 导入配置文件 - 选择
3 本地生成配置文件或2 在线获取配置文件 - 输入你的 Clash 订阅链接(确保是 Clash YAML 格式)
- 选择
1 启动/重启服务
⚠️ 注意:确保订阅链接使用
clash=smart参数获取正确的 YAML 格式配置。
4.3 验证代理
# 测试是否能访问 Google
curl -sI https://www.google.com
五、Nginx 反向代理 + SSL
为内网穿透的服务添加域名和 HTTPS。
5.1 安装 Nginx 和 Certbot
apt install -y nginx certbot python3-certbot-nginx
5.2 配置反向代理
以 SubStore 为例,创建配置文件:
cat > /etc/nginx/sites-available/sub.example.com << 'EOF'
server {
listen 80;
server_name sub.example.com;
location / {
proxy_pass http://127.0.0.1:3003;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
EOF
ln -sf /etc/nginx/sites-available/sub.example.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
5.3 获取 SSL 证书
# 在 DNS 添加 A 记录指向 VPS IP 后执行
certbot --nginx -d sub.example.com --non-interactive --agree-tos --email [email protected]
5.4 开放端口
| 端口 | 协议 | 用途 |
|---|---|---|
| 80 | TCP | HTTP (重定向) |
| 443 | TCP | HTTPS |
最终架构图
┌─────────────────────────────────────┐
│ 阿里云 VPS (上海节点) │
│ │
外网访问 ───────►│ ┌─────────┐ ┌─────────────────┐ │
│ │ Nginx │ │ ShellCrash │ │
│ │ :80/:443│ │ 透明代理 │ │
│ └────┬────┘ └─────────────────┘ │
│ │ │
│ ┌────▼────┐ ┌─────────────────┐ │
│ │ FRP │ │ RustDesk │ │
│ │ :7000 │ │ :21115-21119 │ │
│ └────┬────┘ └─────────────────┘ │
│ │ │
│ ┌────▼────┐ ┌─────────────────┐ │
│ │内网穿透 │ │ DERP (Tailscale)│ │
│ │:3003等 │ │ :59443/:3478 │ │
│ └────┬────┘ └─────────────────┘ │
└───────│─────────────────────────────┘
│
┌───────▼─────────┐
│ 家庭 NAS/Mac │
│ (FRP 客户端) │
│ SubStore 等 │
└─────────────────┘
资源占用情况
在 1.6GB 内存的 VPS 上运行以上所有服务:
| 服务 | 内存占用 |
|---|---|
| ShellCrash | ~30MB |
| FRP Server | ~10MB |
| Nginx | ~15MB |
| RustDesk (2容器) | ~25MB |
| DERP | ~20MB |
| 合计 | ~100MB |
剩余约 1GB 可用内存,完全足够日常使用。
安全建议
- 修改默认端口:SSH 改用非标准端口(如 2222)
- 使用强密码:FRP token、RustDesk key 等使用随机生成的强密码
- 定期更新:保持系统和各服务版本最新
- 最小化开放端口:只开放必要的端口
- 启用 fail2ban:防止暴力破解
apt install -y fail2ban
systemctl enable fail2ban
常见问题
Q: Docker 拉取镜像失败?
A: 确保 ShellCrash 代理正常运行,或配置 Docker 使用国内镜像源。
Q: Nginx SSL 证书获取失败?
A: 检查:
- DNS A 记录是否已生效
- 80 端口是否在安全组中开放
- 防火墙是否放行
Q: FRP 连接不上?
A: 检查:
- 服务端和客户端的 token 是否一致
- 7000 端口是否开放
- 使用
frpc -c frpc.toml查看详细日志
总结
通过一台轻量级阿里云 VPS,我们成功搭建了:
- ✅ FRP 内网穿透 - 访问家里的各种服务
- ✅ RustDesk 远程桌面 - 随时远程操控家里电脑
- ✅ ShellCrash 代理 - VPS 可以正常拉取 Docker 镜像
- ✅ Tailscale DERP - 加速 Tailscale 组网
- ✅ Nginx + SSL - 为服务添加 HTTPS 支持
这套方案成本低(轻量级 VPS 月费约 30-50 元)、维护简单、延迟低,非常适合有家庭服务器需求的用户。